Skip to content

Instantly share code, notes, and snippets.

@Fire-Dragon-DoL
Last active December 13, 2015 18:48
Show Gist options
  • Save Fire-Dragon-DoL/4957885 to your computer and use it in GitHub Desktop.
Save Fire-Dragon-DoL/4957885 to your computer and use it in GitHub Desktop.
FactoryGirl.define do
factory :tech_spec_name do
sequence(:name) { |n| "#{ Faker::Lorem.word } #{ n }"}
end
factory :boat do
name { Faker::Name.first_name }
end
factory :tech_spec do
boat { FactoryGirl.create(:boat) }
tech_spec_name { FactoryGirl.create(:tech_spec_name) }
value { Faker::Lorem.word }
end
factory :user do
email { Faker::Internet.email }
role 'user'
password 'thisisapassword'
password_confirmation { |u| u.password }
end
end
class TechSpec < ActiveRecord::Base
validates :boat_id, presence: true
validates :tech_spec_name_id, presence: true, uniqueness: { scope: :boat_id }
belongs_to :boat
has_one :tech_spec_name
end
class TechSpecName < ActiveRecord::Base
validates :name, presence: true, uniqueness: { case_sensitive: false }
end
class Boat < ActiveRecord::Base
validates :name, presence: true, uniqueness: { case_sensitive: false }
has_many :tech_spec
end
DEPRECATION WARNING: You're trying to create an attribute `tech_spec_id'. Writing arbitrary attributes on a model is deprecated. Please just use `attr_writer` etc. (called from block (2 levels) in <top (required)> at /mnt/hgfs/d_wamp_www/austin/austinparker_it/spec/models/tech_spec_spec.rb:7)
F
Failures:
1) TechSpec should have a valid factory
Screenshot: /mnt/hgfs/d_wamp_www/austin/austinparker_it/tmp/capybara/screenshot_2013-02-15-02-06-17.993.png
Failure/Error: tech_spec = FactoryGirl.create(:tech_spec,
ActiveRecord::RecordInvalid:
Validation failed: Tech spec name can't be blank
# ./spec/models/tech_spec_spec.rb:7:in `block (2 levels) in <top (required)>'
Finished in 1.14 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/models/tech_spec_spec.rb:4 # TechSpec should have a valid factory
Screenshot: /mnt/hgfs/d_wamp_www/austin/austinparker_it/tmp/capybara/screenshot_2013-02-15-02-06-17.993.png
Randomized with seed 62188
Done.
require 'spec_helper'
describe TechSpec do
it "should have a valid factory" do
tech_spec_name = FactoryGirl.create(:tech_spec_name)
boat = FactoryGirl.create(:boat)
tech_spec = FactoryGirl.create(:tech_spec,
boat: boat,
tech_spec_name: tech_spec_name)
tech_spec.should be_valid
# tech_spec = FactoryGirl.create(:tech_spec, tech_spec_name: tech_spec_name)
# tech_spec.should be_valid
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment