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 666655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:50:32+00:00 2026-05-13T23:50:32+00:00

How can database views be tested in Rspec? Every scenario is wrapped in a

  • 0

How can database views be tested in Rspec? Every scenario is wrapped in a transaction and the data does not look like it is being persisted to the database (MySQL in my case). My view returns with an empty result set because none of the records are being persisted in the transaction. I am validating that the records are not being stored by setting a debug point in my spec and checking my data with a database client while the spec is being debugged.

The only way I can think to have my view work would be if I could commit the transaction before the end of the scenario and then clear the database after the scenario is complete. Does anyone know how to accomplish this or is there a better way?

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-13T23:50:32+00:00Added an answer on May 13, 2026 at 11:50 pm

    I think I got it. In order to not use transactions, you need to specify:

    self.use_transactional_fixtures = false
    

    You also must be sure to clean up what you create after each scenario.

    describe Attendee do
      self.use_transactional_fixtures = false
    
      def clear_all
        ActiveRecord::Base.connection.execute('delete from users')
        ActiveRecord::Base.connection.execute('delete from contact_info')
        ActiveRecord::Base.connection.execute('delete from events')
      end
    
      before(:each) do
        # create some test users
        @event = Factory.create(:event)
        @event.publish!
        @user = Factory.create(:user)
        @user_2 = Factory.create(:user_2)
      end
    
      after(:each) do
        clear_all
      end
    
      it "should list have attendees in the directory" do
        # in my case, Attendee class uses my attendees database view
        Attendee.count.should be 2
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My MySQL database can store the euro symbol just fine (as I have tested
Where I can download sample database which can be used for data warehouse creation?
I'm just wondering how to implement database views in Ruby on Rails. Can you
We have a SQL server database. To manipulate the data non-programmatically, I can use
can microsoft sync framework sync database views ? or in your SelectIncrementalInsertsCommand can you
How can you get a list of the views in a SQL server database
I need to delete all views from my MySQL database. How can I do
i have readonly VIEWs in an existing Database and i'd like to get them
Has anybody tried mapping database views in oracle using ActiveRecord? Please can I get
how I can format my database-query in a list view with 2 signs after

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.