Sha256: 84955f057ff83d6d93384bdf31e4543e71c5bbc9060e78d37ed6aaaaa681b8cb
Contents?: true
Size: 1.57 KB
Versions: 2
Compression:
Stored size: 1.57 KB
Contents
require 'pathname' require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper' if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES describe "DataMapper::Resource" do after do repository(:default).adapter.execute('DELETE from green_smoothies'); end before(:all) do class ::GreenSmoothie include DataMapper::Resource property :id, Integer, :serial => true property :name, String auto_migrate!(:default) end end it "should find/create using find_or_create" do repository(:default) do green_smoothie = GreenSmoothie.new(:name => 'Banana') green_smoothie.save GreenSmoothie.find_or_create({:name => 'Banana'}).id.should eql(green_smoothie.id) GreenSmoothie.find_or_create({:name => 'Strawberry'}).id.should eql(2) end end it "should use find_by and use the name attribute to find a record" do repository(:default) do green_smoothie = GreenSmoothie.create({:name => 'Banana'}) green_smoothie.should == GreenSmoothie.find_by_name('Banana') end end it "should use find_all_by to find records using an attribute" do repository(:default) do green_smoothie = GreenSmoothie.create({:name => 'Banana'}) green_smoothie2 = GreenSmoothie.create({:name => 'Banana'}) found_records = GreenSmoothie.find_all_by_name('Banana') found_records.length.should == 2 found_records.each do |found_record| [green_smoothie, green_smoothie2].include?(found_record).should be_true end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
dm-ar-finders-0.9.10 | spec/integration/ar-finders_spec.rb |
dm-ar-finders-0.9.11 | spec/integration/ar-finders_spec.rb |