Skip to content

Commit

Permalink
don't assert primary key in response if no read adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
tpett committed May 16, 2011
1 parent 6e05021 commit f45dd12
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/perry/middlewares/model_bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def build_models_from_records(records, options)
def update_model_after_save(response, model)
model.saved = response.success
if model.saved
if model.new_record?
if model.new_record? && !model.read_adapter.nil?
key = response.model_attributes[model.primary_key]
raise Perry::PerryError.new('primary key not included in response') if key.nil?
model.send("#{model.primary_key}=", key)
Expand Down
11 changes: 10 additions & 1 deletion test/unit/middlewares/model_bridge_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def call(options)
end

teardown do
@model.read_adapter.reset
@model.read_adapter.reset if @model.read_adapter
@model.write_adapter.reset
end

Expand Down Expand Up @@ -105,6 +105,15 @@ def call(options)
@bridge.new(adapter).call(@options)
end
end

should "not raise if model does not have a read_adapter configured" do
@klass.send(:read_with, :none)
assert_nothing_raised do
adapter = SuccessAdapter.new
adapter.response.parsed = nil
@bridge.new(adapter).call(@options)
end
end
end

should "set the model's :saved attribute to true on success" do
Expand Down

0 comments on commit f45dd12

Please sign in to comment.