spec/dynamoid/persistence_spec.rb in dynamoid-0.3.2 vs spec/dynamoid/persistence_spec.rb in dynamoid-0.4.0

- old
+ new

@@ -1,11 +1,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe "Dynamoid::Persistence" do - let(:document_class) { Class.new.send :include, Dynamoid::Document } - before do Random.stubs(:rand).with(Dynamoid::Config.partition_size).returns(0) @address = Address.new end @@ -14,17 +12,17 @@ before do Dynamoid::Adapter.delete_table(Address.table_name) if Dynamoid::Adapter.list_tables.include?(Address.table_name) end it 'creates a table' do - Address.create_table(Address.table_name) + Address.create_table(:table_name => Address.table_name) Dynamoid::Adapter.list_tables.should include 'dynamoid_tests_addresses' end it 'checks if a table already exists' do - Address.create_table(Address.table_name) + Address.create_table(:table_name => Address.table_name) Address.table_exists?(Address.table_name).should be_true Address.table_exists?('crazytable').should be_false end end @@ -104,31 +102,25 @@ User.undump(@hash)[:name].should == 'Josh' User.undump(@hash)[:created_at].to_f == @time.to_f end it 'runs the before_create callback only once' do - document_class.before_create { doing_before_create } + CamelCase.any_instance.expects(:doing_before_create).once.returns(true) - document_class.any_instance.expects(:doing_before_create) - - document_class.create + CamelCase.create end it 'runs after save callbacks when doing #create' do - document_class.after_create { doing_after_create } + CamelCase.any_instance.expects(:doing_after_create).once.returns(true) - document_class.any_instance.expects(:doing_after_create) - - document_class.create + CamelCase.create end it 'runs after save callbacks when doing #save' do - document_class.after_create { doing_after_create } + CamelCase.any_instance.expects(:doing_after_create).once.returns(true) - document_class.any_instance.expects(:doing_after_create) - - document_class.new.save + CamelCase.new.save end it 'tracks previous changes on save or update' do @address.city = 'Chicago' @address.save @@ -138,10 +130,10 @@ @address.city_was.should == 'Chicago' end it 'works with a HashWithIndifferentAccess' do - hash = ActiveSupport::HashWithIndifferentAccess.new("test" => "hi", "hello" => "there") + hash = ActiveSupport::HashWithIndifferentAccess.new("city" => "Atlanta") lambda {Address.create(hash)}.should_not raise_error end end