Merge pull request #662 from jastkand/remove-question-sign

Add auto-stripping of question mark for attributes
This commit is contained in:
Steve Klabnik
2014-09-26 10:35:43 -04:00
3 changed files with 32 additions and 4 deletions

View File

@@ -1,11 +1,13 @@
class Model
def initialize(hash={})
def initialize(hash = {})
@attributes = hash
end
def read_attribute_for_serialization(name)
if name == :id || name == 'id'
object_id
elsif respond_to?(name)
send name
else
@attributes[name]
end

View File

@@ -36,6 +36,22 @@ module ActiveModel
assert_equal([:name, :description],
another_inherited_serializer_klass._attributes)
end
def tests_query_attributes_strip_question_mark
model = Class.new(::Model) do
def strip?
true
end
end
serializer = Class.new(ActiveModel::Serializer) do
attributes :strip?
end
actual = serializer.new(model.new).as_json
assert_equal({ strip: true }, actual)
end
end
end
end