Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4604186
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:15:33+00:00 2026-05-22T00:15:33+00:00

I am coming from a Spring/hibernate background. I have noticed that Rails has no

  • 0

I am coming from a Spring/hibernate background. I have noticed that Rails has no dao and service layers. This really speeds up development, but I don’t know where to put my tests sometimes.

Right now, I’ve been putting my model methods and validation tests in the main model spec. This file is already fairly large.

Where is the ‘standard’ place to test queries? I can imagine myself making a lot of fixtures/dummy data to make sure my queries are working as expected (probably an even better idea since I am new to rails). These are not really needed for the basic model logic and validation tests.

If you could offer some advice as to where put these tests, the best approach to testing queries using rails (especially ones with multiple joins!), and maybe some basic guidelines of how it might different from doing it with DBunit/spring/hibernate, that would be great.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T00:15:34+00:00Added an answer on May 22, 2026 at 12:15 am

    I used to work with hibernate too. The ActiveRecord way is very different from hibernate. You need to set your mind free, for better or for worse. In java and Hibernate you often have the aggregate root and the object graph. Generally, both the object graphs and code base are smaller in ruby somehow too. I don’t know your particular case, so I’ll tread carefully, but I warn you to try fit ruby, and rails, to your java habits.

    You may use custom directories with rspec to organize in a way that makes sense for you and your team.

    #spec/queries/my_custom_search_spec.rb
    
    require 'spec_helper'
    describe MyModel do
      it "should do this query and return X" do
         subject.some_defined_scope_search.should == "something"
      end
    end
    

    and you may have subdirectories, automatically getting picked up by rspec, like spec/models/account/..

    The spec will automatically be picked up by rake spec or rspec spec. I just wrote a simple example above, as I don’t know your case. Do you define scopes with queries, or define specialized methods?

    I strongly recommend abandoning the fixtures (same as the inserts – anti pattern, to me) for something more refactorable, like factories. I like factory_girl. It let’s your app evolve in a more agile manner, IMO.

    EDIT:
    adding my spec_helper.rb with settings for enable/disable automatic cleanup

    RSpec.configure do |config|
      require 'database_cleaner'
      config.add_setting :skip_database_clean
      config.skip_database_clean = false
      config.before(:suite) do
        DatabaseCleaner.strategy = :truncation
      end
    
      config.before(:each) do
      end
    
      config.after(:each) do
        MongoMapper.database.collections.each(&:remove)
        DatabaseCleaner.clean unless config.skip_database_clean
      end
    

    I add the variable skip_database_clean so that I can enable/disable the autocleanup after each spec (each “it”).

      before :all do
        @an_object = some_expensive_test_buildup
        RSpec.configuration.skip_database_clean = true
      end
      after :all do
        RSpec.configuration.skip_database_clean = false
        DatabaseCleaner.clean
      end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm coming from a Spring MVC background on a new Grails app. I have
Coming from a PHP background, I'm used to writing small functions that return a
I'm new to Tomcat, servlets and Spring Web. I'm coming from a PHP background
Caveat: I'm coming from a PHP background, with a few Java/Tomcat skills that are
Coming from a C++ background I have to master the complexity of the Java
I have a web application in Spring that has a functional requirement for generating
I'm having trouble with this query. I have 2 date coming from textboxes (don't
Coming from a .NET background I'm use to reusing string variables for storage, so
I have a string value coming from a label in the .aspx page as
(LocalVariable)ABC.string(Name) = (IDataReader)dataReader.GetString(0); This name value is coming from database. What happening here is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.