Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/active_resource/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,7 @@ class Base
extend ActiveResource::Associations

include Callbacks, CustomMethods, Validations, Serialization
include ActiveModel::Conversion
include ActiveModel::AttributeAssignment, ActiveModel::Conversion
include ActiveModel::ForbiddenAttributesProtection
include ActiveModel::Serializers::JSON
include ActiveModel::Serializers::Xml
Expand Down
22 changes: 22 additions & 0 deletions test/cases/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,28 @@ def test_predicate_for_an_unknown_attribute_returns_nil
assert_not_predicate post, :unknown_attribute?
end

def test_assign_attributes_to_known_attributes
previous_schema = Person.schema
Person.schema = { name: "string" }

matz = Person.new

matz.assign_attributes "id" => 1, :name => "Matz"

assert_equal 1, matz.id
assert_equal "Matz", matz.name
ensure
Person.schema = previous_schema
end

def test_assign_attributes_assigns_to_loaded_attributes
matz = Person.new(name: "matz")

assert_changes -> { matz.name }, from: "matz", to: "Matz" do
matz.assign_attributes(name: "Matz")
end
end

def test_custom_header
Person.headers["key"] = "value"
assert_raise(ActiveResource::ResourceNotFound) { Person.find(4) }
Expand Down