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/4958131 to your computer and use it in GitHub Desktop.
Save Fire-Dragon-DoL/4958131 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 }
# This was belongs_to, changed to test it
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)
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)
--- !ruby/object:TechSpecName
attributes:
id: 1
name: WTF
created_at: 2013-02-15 02:14:33.329072909 Z
updated_at: 2013-02-15 02:14:33.329072909 Z
tech_spec_id:
--- !ruby/object:Boat
attributes:
id: 1
name: 36 Fly
created_at: 2013-02-15 02:14:33.370546501 Z
updated_at: 2013-02-15 02:14:33.370546501 Z
tech_spec_id:
--- !ruby/object:TechSpec
attributes:
id:
boat_id: 1
tech_spec_name_id:
value: officiis
created_at:
updated_at:
require 'spec_helper'
describe TechSpec do
it "has a valid factory" do
tech_spec_name = FactoryGirl.create(:tech_spec_name, name: "WTF")
boat = FactoryGirl.create(:boat, name: "36 Fly")
tech_spec = FactoryGirl.build(:tech_spec,
boat: boat,
tech_spec_name: tech_spec_name)
puts "\n"
puts tech_spec_name.to_yaml.to_s+"\n"
puts boat.to_yaml.to_s+"\n"
puts tech_spec.to_yaml.to_s+"\n"
# 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