spec/lib/pickle_session_spec.rb in pickle-0.2.2 vs spec/lib/pickle_session_spec.rb in pickle-0.2.3

- old
+ new

@@ -205,18 +205,44 @@ it_should_behave_like "after storing a single user" end end end + describe "#create_models_from_table(plural_factory, table)" do + context "when given a table without a matching pickle ref column" do + before do + @table = mock(:hashes => [{'name' => 'Fred'}, {'name' => 'Betty'}]) + end + + it "should call create_model for each of the table hashes with plain factory name" do + should_receive(:create_model).with("user", 'name' => "Fred").once.ordered + should_receive(:create_model).with("user", 'name' => "Betty").once.ordered + create_models_from_table("users", @table) + end + end + + context "when given a table with a matching pickle ref column" do + before do + @table = mock(:hashes => [{'user' => "fred", 'name' => 'Fred'}, {'user' => "betty", 'name' => 'Betty'}]) + end + + it "should call create_model for each of the table hashes with labelled pickle ref" do + should_receive(:create_model).with("user \"fred\"", 'name' => "Fred").once.ordered + should_receive(:create_model).with("user \"betty\"", 'name' => "Betty").once.ordered + create_models_from_table("users", @table) + end + end + end + describe "#find_model!" do it "should call find_model" do should_receive(:find_model).with('name', 'fields').and_return(mock('User')) find_model!('name', 'fields') end it "should call raise error if find_model returns nil" do should_receive(:find_model).with('name', 'fields').and_return(nil) - lambda { find_model!('name', 'fields') }.should raise_error + lambda { find_model!('name', 'fields') }.should raise_error(RuntimeError, "Can't find pickle model: 'name' in this scenario") end end describe "#find_models" do before do \ No newline at end of file