spec/dynamoid/persistence_spec.rb in dynamoid-0.3.0 vs spec/dynamoid/persistence_spec.rb in dynamoid-0.3.1
- old
+ new
@@ -1,14 +1,16 @@
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
-
+
context 'without AWS keys' do
unless ENV['ACCESS_KEY'] && ENV['SECRET_KEY']
before do
Dynamoid::Adapter.delete_table(Address.table_name) if Dynamoid::Adapter.list_tables.include?(Address.table_name)
end
@@ -99,9 +101,33 @@
@time = DateTime.now
@hash = {:name => 'Josh', :created_at => @time.to_f}
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 }
+
+ document_class.any_instance.expects(:doing_before_create)
+
+ document_class.create
+ end
+
+ it 'runs after save callbacks when doing #create' do
+ document_class.after_create { doing_after_create }
+
+ document_class.any_instance.expects(:doing_after_create)
+
+ document_class.create
+ end
+
+ it 'runs after save callbacks when doing #save' do
+ document_class.after_create { doing_after_create }
+
+ document_class.any_instance.expects(:doing_after_create)
+
+ document_class.new.save
end
it 'tracks previous changes on save or update' do
@address.city = 'Chicago'
@address.save