Note that there are some explanatory texts on larger screens.

plurals
  1. POMany rpsec tests with test_sign_in fail after upgrading to Rails 3.1, maybe a cookie problem?
    text
    copied!<p>I have upgraded to Rails 3.1 and everything seems to work fine. But the tests (RSpec) fail anyhow, e.g. the following one:</p> <pre><code>describe "for admin user" do before(:each) do @city = Factory(:city) @user = Factory(:user) @business = Factory(:business, :user_id =&gt; @user.id, :city_id =&gt; @city.id) @admin = test_sign_in(Factory(:user, :email =&gt; "admin@example.it", :admin =&gt; true)) end it "should have an edit link for all businesses in show city" do get :show, :id =&gt; @city response.should have_selector('a', :href =&gt; "/businesses/#{@business.id}-Factory-business-city-Factory-business/edit") end end </code></pre> <p>This worked fine with Rails 3.0.8, but now the test fails. Test log says:</p> <p>[1m[35mSQL (0.2ms)[0m INSERT INTO <code>users</code> (<code>admin</code>, <code>created_at</code>, <code>email</code>, <code>encrypted_password</code>, <code>name</code>, <code>salt</code>, <code>updated_at</code>) VALUES (1, '2011-09-21 10:30:30', 'admin@example.it', '68f8a34e0243a642662fe2b6ea8ed7c714d042750a66ce542f2df288caefac32', 'Admin Name', '6df34c304d79437d495e60d2d34e1028489731afa96690efbc25c714224edb1f', '2011-09-21 10:30:30')</p> <p>Processing by CitiesController#show as HTML [1m[35mUser Load (0.2ms)[0m SELECT <code>users</code>.* FROM <code>users</code> WHERE <code>users</code>.<code>id</code> IS NULL LIMIT 1</p> <p>[1m[36mCity Load (0.2ms)[0m [1mSELECT <code>cities</code>.* FROM <code>cities</code> WHERE <code>cities</code>.<code>id</code> = 942 LIMIT 1[0m</p> <p>[1m[35mCity Load (0.2ms)[0m SELECT <code>cities</code>.* FROM <code>cities</code> WHERE <code>cities</code>.<code>id</code> = 942 LIMIT 1</p> <p>[1m[36mCity Load (0.2ms)[0m [1mSELECT <code>cities</code>.* FROM <code>cities</code> WHERE <code>cities</code>.<code>id</code> = 942 LIMIT 1[0m</p> <p>[1m[36mUser Load (0.2ms)[0m [1mSELECT <code>users</code>.* FROM <code>users</code> WHERE <code>users</code>.<code>id</code> IS NULL LIMIT 1[0m</p> <p>So, it seems there is no user id (NULL), but the admin was created correctly before. Might this be a cookie problem?</p> <p>The test group in my Gemfile is:</p> <pre><code>group :test do gem 'rspec', '2.6.0' gem 'rspec-rails', '2.6.1' gem 'webrat', '0.7.3' gem 'factory_girl_rails', '1.0' gem 'spork', '~&gt; 0.9.0.rc' end </code></pre> <p>My test.rb is</p> <pre><code>Project::Application.configure do # Settings specified here will take precedence over those in config/application.rb # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between test runs. Don't rely on the data there! config.cache_classes = true # Configure static asset server for tests with Cache-Control for performance config.serve_static_assets = true config.static_cache_control = "public, max-age=3600" # Log error messages when you accidentally call methods on nil config.whiny_nils = true # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false # Raise exceptions instead of rendering exception templates config.action_dispatch.show_exceptions = false # Disable request forgery protection in test environment config.action_controller.allow_forgery_protection = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test # Use SQL instead of Active Record's schema dumper when creating the test database. # This is necessary if your schema can't be completely dumped by the schema dumper, # like if you have constraints or database-specific column types # config.active_record.schema_format = :sql # Print deprecation notices to the stderr config.active_support.deprecation = :stderr # Allow pass debug_assets=true as a query parameter to load pages with unpackaged assets config.assets.allow_debugging = true end </code></pre> <p>And this is my spec_helper:</p> <pre><code># This file is copied to spec/ when you run 'rails generate rspec:install' require 'rubygems' require 'spork' 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. ENV["RAILS_ENV"] ||= 'test' unless defined?(Rails) require File.dirname(__FILE__) + "/../config/environment" end require 'rspec/rails' # Requires supporting files with custom matchers and macros, etc, # in ./support/ and its subdirectories. Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} 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" # 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 ### Part of a Spork hack. See http://bit.ly/arY19y # Emulate initializer set_clear_dependencies_hook in # railties/lib/rails/application/bootstrap.rb ActiveSupport::Dependencies.clear def test_sign_in(user) controller.sign_in(user) end end end Spork.each_run do end </code></pre> <p>Thank you for your suggestions/answers!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload