test/machine_test.rb in aub-machine-1.0.2 vs test/machine_test.rb in aub-machine-1.0.3

- old
+ new

@@ -191,11 +191,11 @@ Machine.expects(:require).with(third).never Machine.find_definitions end end - context "using the helper method" do + context "using the helper methods" do setup do Machine.define :article do |article, machine| article.title = 'aha' end end @@ -213,10 +213,31 @@ end should "not save the object" do assert Machine(:article).new_record? end + + should "apply Machine! correctly" do + assert Machine!(:article).instance_of?(Article) + end + + should "set the attributes" do + assert_equal 'aha', Machine!(:article).title + end + + should "allow replacement attributes" do + assert_equal 'ooh', Machine!(:article, :title => 'ooh').title + end + + should "save the object" do + assert !Machine!(:article).new_record? + end + + should "take a block to set attributes" do + assert_equal 'big fun', Machine(:article) { |obj| obj.title = 'big fun' }.title + assert_equal 'big fun', Machine!(:article) { |obj| obj.title = 'big fun' }.title + end end context "applying a machine to an existing object" do setup do Machine.define :article do |article, machine| @@ -285,8 +306,16 @@ article.title = 'fun' assert article.new_record? end assert_equal 'fun', article.title assert !article.new_record? + end + + should 'use the block in the shorthand version of build' do + article = Machine(:article) do |article| + article.title = 'another one' + end + assert_equal 'another one', article.title + assert article.new_record? end end end