Skip to content

Instantly share code, notes, and snippets.

@karthiks
Created September 21, 2011 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karthiks/1232368 to your computer and use it in GitHub Desktop.
Save karthiks/1232368 to your computer and use it in GitHub Desktop.
Can't find first MyFreakingActiveRecordModel....
### Terminal Output showing spec failure ###
Failures:
1) CurrencyConverter#validations
Failure/Error: it { should validate_uniqueness_of(:from).scoped_to(:to) }
Can't find first CurrencyConverter
# ./spec/models/currency_converter_spec.rb:4:in `block (3 levels) in <top (required)>'
###########################################
### The Solution ###
###########################################
### currency_converter.rb ###
class CurrencyConverter < ActiveRecord::Base
validates_uniqueness_of :from, :scope => :to
end
### currency_converter_spec.rb ###
describe CurrencyConverter do
describe "#validations" do
subject { Factory(:currency_converter) } # Comment this line and you get spec failure shown in the Terminal Output above
it { should validate_uniqueness_of(:from).scoped_to(:to) }
end
end
### factories.rb ###
Factory.define(:currency_converter) do |cc|
cc.rate 100
cc.from "INR"
cc.to "SGD"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment