In Rails 3.2.13, subdomain is provided by default. As such, I want to test my application such that when a merchant signs up, he goes by default to root_url with subdomain 'merchant' i.e. https://merchant.lvh.me:3000. However, I am having trouble testing the same in RSpec. My test looks like this:
describe "Sign in" do
before { visit signup_path }
let(:submit) { "Sign up" }
describe "with invalid information" do
it "should not create a user" do
expect { click_button submit }.not_to change(User, :count)
end
end
describe "with valid information" do
before do
fill_in "Email", with: "user#gmail.com"
fill_in "Password", with: "securepassword"
end
describe "as a merchant" do
before { choose("Merchant") }
it "should create a merchant user" do
expect { click_button submit }.to change(User, :count).by(1)
end
describe "after creating the merchant user" do
before do
click_button submit
request = ActionController::TestRequest.new(:host => "lvh.me:3000")
end
let(:merchant) { User.find_by_email('user#gmail.com') }
expect (request.subdomain).to eq('merchant')
it { should have_selector 'div.alert.alert-success', text: "Welcome to App!" }
it { should have_link "Sign out", href: signout_path }
it { should_not have_link "Sign in", href: signin_path }
it { should have_content merchant.email }
it { should have_selector "title", text: full_title(merchant.email) }
end
end
describe "as a user" do
before do
choose("User")
request = ActionController::TestRequest.new(:host => "lvh.me:3000")
end
it "should create a normal user" do
expect { click_button submit }.to change(User, :count).by(1)
end
describe "after creating the normal user" do
before { click_button submit }
let(:user) { User.find_by_email('user#gmail.com') }
expect (request.subdomain).to eq('user')
it { should have_selector 'div.alert.alert-success', text: "Welcome to App!" }
it { should have_link "Sign out", href: signout_path }
it { should_not have_link "Sign in", href: signin_path }
it { should have_content user.email }
it { should have_selector "title", text: full_title(user.email) }
end
end
end
end
Error is:
19:58:54 - INFO - Guard::RSpec is running, with RSpec 2!
19:58:54 - INFO - Running all specs
Running tests with args ["--drb", "-f", "progress", "-r", "/usr/local/lib/ruby/gems/1.9.1/gems/guard-rspec-1.2.1/lib/guard/rspec/formatters/notification_rspec.rb", "-f", "Guard::RSpec::Formatter::NotificationRSpec", "--out", "/dev/null", "--failure-exit-code", "2", "spec"]...
Exception encountered: #<NameError: undefined local variable or method `request' for #<Class:0x007fe0d8058848>>
backtrace:
/home/app/spec/requests/user_pages_spec.rb:46:in `block (5 levels) in <top (required)>'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `module_eval'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `subclass'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:224:in `describe'
/home/app/spec/requests/user_pages_spec.rb:39:in `block (4 levels) in <top (required)>'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `module_eval'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `subclass'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:224:in `describe'
/home/app/spec/requests/user_pages_spec.rb:32:in `block (3 levels) in <top (required)>'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `module_eval'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `subclass'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:224:in `describe'
/home/app/spec/requests/user_pages_spec.rb:26:in `block (2 levels) in <top (required)>'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `module_eval'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `subclass'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:224:in `describe'
/home/app/spec/requests/user_pages_spec.rb:16:in `block in <top (required)>'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `module_eval'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `subclass'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:224:in `describe'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/dsl.rb:18:in `describe'
/home/app/spec/requests/user_pages_spec.rb:3:in `<top (required)>'
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:245:in `load'
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:245:in `block in load'
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency'
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:245:in `load'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `block in load_spec_files'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `map'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load_spec_files'
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:22:in `run'
/usr/local/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/test_framework/rspec.rb:11:in `run_tests'
/usr/local/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/run_strategy/forking.rb:13:in `block in run'
/usr/local/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/forker.rb:21:in `block in initialize'
/usr/local/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/forker.rb:18:in `fork'
/usr/local/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/forker.rb:18:in `initialize'
/usr/local/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/run_strategy/forking.rb:9:in `new'
/usr/local/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/run_strategy/forking.rb:9:in `run'
/usr/local/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/server.rb:48:in `run'
/usr/local/lib/ruby/1.9.1/drb/drb.rb:1548:in `perform_without_block'
/usr/local/lib/ruby/1.9.1/drb/drb.rb:1508:in `perform'
/usr/local/lib/ruby/1.9.1/drb/drb.rb:1586:in `block (2 levels) in main_loop'
/usr/local/lib/ruby/1.9.1/drb/drb.rb:1582:in `loop'
/usr/local/lib/ruby/1.9.1/drb/drb.rb:1582:in `block in main_loop'
Done.
I tried to print request object to see if anything is there, but its blank. How to access request object in RSpec integration test or is integration test the right place to test for this kind of behavior? Please suggest.
Edit: More Information My data model consists of only single user table where all by default are normal users. However, some are merchants also. Now, when someone signs-in as a user (distinguished using radio button in sign-in form), he should be redirected to user.lvh.me and if he signs-in as a merchant, he should be redirected to merchant.lvh.me. This is what I am trying to test in my integration tests.
You can mock a request using
ActionController::TestRequest.new()
for example
request = ActionController::TestRequest.new(:host => test_domain)
I'm not really clear what behaviour you are trying to test here.
It seems that you have a sign up form where merchants can sign up. Once they have signed up they should get their own subdomain ( merchant1.lvh.me, merchant2.lvh.me). Is that right?
If that is right, then it looks like you are trying to test that the sub-domain for the sign up request should be set. I don't think thats how it works - the client is in control of the domain that the request is made to not the server. I suspect what you want to do is perform a redirect after successful signup to the appropriate subdomian. Thus you want to test that the response is redirecting to the subdomain.
Related
I'm having an issue while testing user authentication with rspec and devise.
here is my code:
require 'rails_helper'
describe UsersController, :type => :controller do
let(:user) { User.create!(email: '1#test.com', password: '123456') }
describe 'GET #show' do
context 'User is logged in' do
before
sign_in user
get :show
end
it "loads correct user details" do
expect(assigns(:user)).to eq user
end
end
context 'No user is logged in' do
it 'redirects to login' do
get :show, id: user.id
expect(response).to redirect_to(root_path)
end
end
end
end
When i run rspec on the terminal i get this error:
/Users/joao1/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load': /Users/joao1/Desktop/nameofapp/spec/controllers/users_controller_spec.rb:29: syntax error, unexpected keyword_end, expecting end-of-input (SyntaxError)
from /Users/joao1/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `block in load'
from /Users/joao1/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
from /Users/joao1/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
from /Users/joao1/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1435:in `block in load_spec_files'
from /Users/joao1/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1433:in `each'
from /Users/joao1/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1433:in `load_spec_files'
from /Users/joao1/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:100:in `setup'
from /Users/joao1/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:86:in `run'
from /Users/joao1/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:71:in `run'
from /Users/joao1/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:45:in `invoke'
from /Users/joao1/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/exe/rspec:4:in `<top (required)>'
from /Users/joao1/.rvm/gems/ruby-2.3.0/bin/rspec:23:in `load'
from /Users/joao1/.rvm/gems/ruby-2.3.0/bin/rspec:23:in `<main>'
from /Users/joao1/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
from /Users/joao1/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'
How can i solve this and effectively test my user authentication?
The error message is a result of a typo in your program and it not matching up do end blocks. Looking more carefully I see you are missing a do statement from the before block. Change it to:
before do
sign_in user
get :show
end
This is my code snippet to test the polymorphic relationship.
I wrote test as below.
require 'rails_helper'
RSpec.describe Proration, type: :model do
let(:invoice_item) { FactoryGirl.create(:proration_invoice_item) }
subject { :invoice_item }
it { should be_valid }
it { should respond_to(:total_amount) }
it { should respond_to(:invoice) }
it { should respond_to(:itemable) }
end
But this errors out
Failures:
1) Proration should be valid
Failure/Error: it { should be_valid }
NoMethodError:
undefined method `valid?' for :invoice_item:Symbol
# ./spec/models/proration_spec.rb:7:in `block (2 levels) in <top (required)>'
2) Proration Proration should respond to #total_amount
Failure/Error: end
expected :invoice_item to respond to :total_amount
# ./spec/models/proration_spec.rb:16:in `block (3 levels) in <top (required)>'
3) Proration Proration should respond to #invoice
Failure/Error: end
expected :invoice_item to respond to :invoice
# ./spec/models/proration_spec.rb:17:in `block (3 levels) in <top (required)>'
4) Proration Proration should respond to #itemable
Failure/Error: Unable to find matching line in /Users/toshikiinami/Desktop/billing/spec/models/proration_spec.rb
expected :invoice_item to respond to :itemable
# ./spec/models/proration_spec.rb:18:in `block (3 levels) in <top (required)>'
Any ideas to fix this?
(respond_to for model doesn't work.)
You defined an invoice_item using let, but as a subject you're using symbol. What you want instead is that object invoice_item, so
subject{ :invoice_item }
should be changed to
subject{ invoice_item }
I was working on the part 9.3.3 about pagination from the ruby on rails tutorial of Michael Hartl, an Im stuck: running the rspec tests i got an error message that there is something wrong with the gem FactoryGirl. Do you suppose what could be a problem?
/Users/smi/.rvm/gems/ruby-2.0.0-p594/gems/factory_girl-4.5.0/lib/factory_girl/definition_proxy.rb:43:in `add_attribute': Both value and block given (FactoryGirl::AttributeDefinitionError)
from /Users/smi/.rvm/gems/ruby-2.0.0-p594/gems/factory_girl-4.5.0/lib/factory_girl/definition_proxy.rb:102:in `method_missing'
from /Users/smi/projects/sample_app/spec/factories.rb:3:in `block (2 levels) in <top (required)>'
from /Users/smi/.rvm/gems/ruby-2.0.0-p594/gems/factory_girl-4.5.0/lib/factory_girl/syntax/default.rb:18:in `instance_eval'
from /Users/smi/.rvm/gems/ruby-2.0.0-p594/gems/factory_girl-4.5.0/lib/factory_girl/syntax/default.rb:18:in `factory'
from /Users/smi/projects/sample_app/spec/factories.rb:2:in `block in <top (required)>'
from /Users/smi/.rvm/gems/ruby-2.0.0-p594/gems/factory_girl-4.5.0/lib/factory_girl/syntax/default.rb:49:in `instance_eval'
from /Users/smi/.rvm/gems/ruby-2.0.0-p594/gems/factory_girl-4.5.0/lib/factory_girl/syntax/default.rb:49:in `run'
from /Users/smi/.rvm/gems/ruby-2.0.0-p594/gems/factory_girl-4.5.0/lib/factory_girl/syntax/default.rb:7:in `define'
from /Users/smi/projects/sample_app/spec/factories.rb:1:in `<top (required)>'
from /Users/smi/.rvm/ge......................
users_pages_spec.rb:
describe "pagination" do
before(:all) { 30.times { FactoryGirl.create(:user) } }
after(:all) { User.delete_all }
it { should have_selector('div.pagination') }
it "should list each user" do
User.paginate(page: 1).each do |user|
expect(page).to have_selector('li', text: user.name)
end
end
end
factories.rb:
FactoryGirl.define do
factory :user do
sequense(:name) { |n| "Person #{n}" }
sequense(:email) { |n| "person_#{n}#example.com" }
password "foobar"
password_confirmation "foobar"
end
end
I have found an answer! the method "sequence" in factories.rb was written with a mistake. Now all tests are green.
I'm using rails 3.2 with devise and rspec with factory girl. I'm trying to log a user in but it seems there is a problem creating the user in the first place.
user factory:
factory :user do
first_name "Test"
last_name "User"
sequence(:email) { |n| "foo#{n}#test.com" }
password "secretpassword"
confirmed_at Time.now
end
my spec
feature "BackOffice" do
subject { page }
context "as user" do
let(:user) { create(:user) }
describe "should not have access to backoffice" do
before do
visit "http://domain_name/fr/users/sign_in"
within ".login-wrapper" do
fill_in "user_email", with: user.email
fill_in "user_password", with: user.password
click_button "S'identifier"
end
end
it { should have_content "Bienvenue"}
end
end
Error
Failure/Error: let(:user) { create(:user) }
ActionView::Template::Error:
No route matches {:action=>"edit", :controller=>"users/registrations"}
# ./app/views/user_mailer/welcome.html.erb:3:in `_app_views_user_mailer_welcome_html_erb__212088972377821759_70301344598820'
# ./app/mailers/user_mailer.rb:31:in `welcome'
# ./app/models/user.rb:125:in `send_welcome_email'
# ./spec/requests/backoffice_spec.rb:15:in `block (3 levels) in <top (required)>'
# ./spec/requests/backoffice_spec.rb:20:in `block (5 levels) in <top (required)>'
# ./spec/requests/backoffice_spec.rb:19:in `block (4 levels) in <top (required)>'
# ./spec/support/database_cleaner.rb:17:in `block (2 levels) in <top (required)>'
why would it be trying to go to the edit action when it should be creating the resource?
There was a problem with a link in a welcome email I added the following to fix it:
config.action_mailer.default_url_options = { protocol: "http", host: "localhost", port: 3000, locale: I18n.locale }
I was changing some parts of code, and my tests started to give errors and warnings.
Then I removed those tests, because I couldn't fix them.
But then tests in my other file totally went awry.
The following is my factories.rb file:
FactoryGirl.define do
factory :user do
sequence(:name) { |n| "Person #{n}" }
sequence(:surname) { |n| "Persona #{n}" }
sequence(:email) { |n| "person_persona_#{n}#example.com.eu" }
password "foobar"
password_confirmation "foobar"
# factory :admin do
# admin true
# end
factory :admin do
role "admin"
end
factory :editor do
role "editor"
end
factory :author do
role "author"
end
end
factory :course do
sequence(:title) { |n| "Title #{n}" }
sequence(:objectives) { |n| "Objectives #{n}" }
user_id 1
subject_id 1
student_level_id 1
end
factory :subject do
title "French for Adults"
end
factory :student_level do
title "Advanced"
end
end
And this is my actual test file, models/course_spec.rb:
require 'spec_helper'
describe Course do
let (:user) { FactoryGirl.create(:user) }
let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
let (:student_level) { FactoryGirl.create(:student_level) }
before do
# #course = Course.new(user_id: user.id, subject_id: subject_.id, student_level_id: student_level.id,
# title: "French for Us", objectives: "Lorem ipsum")
#course = user.courses.build(title: "French", objectives: "lorem")
#course.subject = subject_
#course.student_level = student_level
end
subject { #course }
it { should respond_to(:user_id) }
it { should respond_to(:subject_id) }
it { should respond_to(:student_level_id) }
it { should respond_to(:title) }
it { should respond_to(:objectives) }
it { should respond_to(:user) }
its(:user) { should == user }
it { should be_valid }
describe "when user_id is not present" do
before { #course.user_id = nil }
it { should_not be_valid }
end
describe "when subject_id is not present" do
before { #course.subject_id = nil }
it { should_not be_valid }
end
describe "when student_level_id is not present" do
before { #course.student_level_id = nil }
it { should_not be_valid }
end
describe "when title is not present" do
before { #course.title = "" }
it { should_not be_valid }
end
describe "when title is too long" do
before { #course.title = "a" * 251 }
it { should_not be_valid }
end
describe "when title is already taken" do
before do
course_with_same_title = #course.dup
course_with_same_title.title = #course.title.upcase
course_with_same_title.save
end
it { should_not be_valid }
end
describe "when objectives are not present" do
before { #course.objectives = "" }
it { should_not be_valid }
end
describe "accessible attributes" do
it "should not allow access user_id" do
expect do
Course.new(user_id: user.id)
end.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
end
# it "should not allow access subject_id" do
# expect do
# Course.new(subject_id: subject_.id)
# end.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
# end
# it "should not allow access student_level_id" do
# expect do
# Course.new(student_level_id: student_level.id)
# end.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
# end
end
end
And these are test outputs:
:~/ror/oy$ bundle exec rspec
...............................................................FFFFFFFFFFFFFFFF.................................................
Failures:
1) Course
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
2) Course
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
3) Course
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
4) Course
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
5) Course
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
6) Course
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
7) Course
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
8) Course when user_id is not present
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
9) Course user
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
10) Course when title is already taken
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
11) Course when objectives are not present
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
12) Course accessible attributes should not allow access user_id
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
13) Course when title is too long
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
14) Course when subject_id is not present
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
15) Course when student_level_id is not present
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
16) Course when title is not present
Failure/Error: let (:subject_) { FactoryGirl.create(:subject) } # "_" so that to differenciate from subject test directive
ActiveRecord::RecordInvalid:
translation missing: uzlt.activerecord.errors.messages.record_invalid
# ./spec/models/course_spec.rb:19:in `block (2 levels) in <top (required)>'
# ./spec/models/course_spec.rb:27:in `block (2 levels) in <top (required)>'
Finished in 7.82 seconds
128 examples, 16 failures
Failed examples:
rspec ./spec/models/course_spec.rb:36 # Course
rspec ./spec/models/course_spec.rb:37 # Course
rspec ./spec/models/course_spec.rb:34 # Course
rspec ./spec/models/course_spec.rb:35 # Course
rspec ./spec/models/course_spec.rb:33 # Course
rspec ./spec/models/course_spec.rb:41 # Course
rspec ./spec/models/course_spec.rb:38 # Course
rspec ./spec/models/course_spec.rb:45 # Course when user_id is not present
rspec ./spec/models/course_spec.rb:39 # Course user
rspec ./spec/models/course_spec.rb:76 # Course when title is already taken
rspec ./spec/models/course_spec.rb:82 # Course when objectives are not present
rspec ./spec/models/course_spec.rb:86 # Course accessible attributes should not allow access user_id
rspec ./spec/models/course_spec.rb:65 # Course when title is too long
rspec ./spec/models/course_spec.rb:50 # Course when subject_id is not present
rspec ./spec/models/course_spec.rb:55 # Course when student_level_id is not present
rspec ./spec/models/course_spec.rb:60 # Course when title is not present
Randomized with seed 44955
I suppose there is problem with factories.rb file. But I checked it with the same file on other branch, nothing changed actually.
What could be wrong here?
I ran
$ rake db:test:prepare
per this thread: Suddenly ALL RSpec tests failing?
And everything worked fine.
I suggest you check the following things
schema, migration: make sure your object has the correct attributes
model validation: this is highly the reason that cause your test fail. Last time I had this invalid_record error is because of a validation fault