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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:44:27+00:00 2026-05-31T09:44:27+00:00

UPDATE: This turned out not to be about my database at all, but rather

  • 0

UPDATE: This turned out not to be about my database at all, but rather about preferences stored by Spree in a memory cache that was polluted by my tests. See my answer below.


I am running a Spree application on Rails 3.1.4, with Ruby 1.9.3-p0, rspec-rails 2.8.1, rspec 2.8.0.

Rspec is interacting oddly with Webrick on my development machine, making me think that it is somehow making a running Webrick instance switch to using the test database.

I have one spec for my HomeController:

require 'spec_helper'

describe HomeController do
  render_views

describe "GET 'index'" do
  it "should be successful" do
    get 'index'
    response.should be_success
  end
end

end

When I boot up Webrick on my localhost (development machine), my home page works fine in the browser. The first time I run Rspec on my HomeController, whose index action corresponds to the home page, my test passes.

After Rspec runs, the page breaks in Webrick because a database field, previously populated with text data, is now nil. Subsequent Rspec iterations also break.

So, is Rspec making Webrick stop using my development database and start using my test database, and why? Is it the ENV["RAILS_ENV"] ||= 'test' line in spec_helper.rb?

(Here is my spec_helper.rb and sanitized database.yml:)

spec_helper.rb (I have Spork and Autotest installed, but this error occurs when I am not running them too.)

require 'rubygems'
require 'spork'
#uncomment the following line to use spork with the debugger
#require 'spork/ext/ruby-debug'

Spork.prefork do
  # Loading more in this block will cause your tests to run faster. However,
  # if you change any configuration or code from libraries loaded here, you'll
  # need to restart spork for it take effect.
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
# from the project root directory.
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
# require 'capybara/rspec'

# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}

#require 'factories'

RSpec.configure do |config|
  # == Mock Framework
  #
  # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
  #
  # config.mock_with :mocha
  # config.mock_with :flexmock
  # config.mock_with :rr
  config.mock_with :rspec

  config.fixture_path = "#{::Rails.root}/spec/fixtures"

  #config.include Devise::TestHelpers, :type => :controller
  # If you're not using ActiveRecord, or you'd prefer not to run each of your
  # examples within a transaction, comment the following line or assign false
  # instead of true.
  config.use_transactional_fixtures = true
end

@configuration ||= AppConfiguration.find_or_create_by_name("Default configuration")

PAYMENT_STATES = Payment.state_machine.states.keys unless defined? PAYMENT_STATES
SHIPMENT_STATES = Shipment.state_machine.states.keys unless defined? SHIPMENT_STATES
ORDER_STATES = Order.state_machine.states.keys unless defined? ORDER_STATES

# Usage:
#
# context "factory" do
#   it { should have_valid_factory(:address) }
# end
RSpec::Matchers.define :have_valid_factory do |factory_name|
  match do |model|
    Factory(factory_name).new_record?.should be_false
  end
end
end

Spork.each_run do
  # This code will be run each time you run your specs.
end

database.yml

development:
  adapter: mysql2
  host: localhost
  database: <APP>_development 
  username: <USER>
  password: <PASSWORD>

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: mysql2
  host: localhost
  database: <APP>_test 
  username: <USER>
  password: <PASSWORD>

production:
  adapter: mysql2
  host: localhost
  database: <APP>_prod
  username: <PROD_USER>
  password: <PROD_PASSWORD>
  • 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-31T09:44:28+00:00Added an answer on May 31, 2026 at 9:44 am

    It turns out that this was an issue with preferences stored in a cache, and NOT with the databases.

    Josh Jacobs answers it (and explains it very well) here

    The solution is to configure a different cache store for test and development. In test.rb I added config.cache_store = :memory_store, restarted spork, and everything works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATE: This question is out of date, but left for informational purposes. Original Question
After all the answers to my last question about fine-tuning turned out to be
Update: This turned into a blog post, with updated links and code, over at
Update: This is, as I was told, no principle Python related problem, but seems
Update: This question was an epic failure, but here's the working solution. It's based
Update: This issue was not properly explored. The real issue lies within render :json
I am struggling to update my MySQL database. This is what I have written:
Update I turned Zombies on... and got this error: *** -[CALayer retain]: message sent
Update: this question, including the title, was rephrased, see history for details I know
Update: This does work, I was being stupid :( i have the following extension

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.