attribution 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/attribution.gemspec +1 -1
- data/lib/attribution/version.rb +1 -1
- data/lib/attribution.rb +4 -2
- data/test/attribution_test.rb +10 -0
- metadata +1 -1
data/attribution.gemspec
CHANGED
data/lib/attribution/version.rb
CHANGED
data/lib/attribution.rb
CHANGED
@@ -21,6 +21,10 @@ module Attribution
|
|
21
21
|
end
|
22
22
|
alias_method :to_h, :attributes
|
23
23
|
|
24
|
+
def to_json
|
25
|
+
to_h.to_json
|
26
|
+
end
|
27
|
+
|
24
28
|
def attributes=(attributes)
|
25
29
|
if attributes
|
26
30
|
attributes = JSON.parse(attributes) if attributes.is_a?(String)
|
@@ -28,8 +32,6 @@ module Attribution
|
|
28
32
|
setter = "#{k}="
|
29
33
|
if respond_to?(setter)
|
30
34
|
send(setter, v)
|
31
|
-
else
|
32
|
-
instance_variable_set("@#{k}", v)
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
data/test/attribution_test.rb
CHANGED
@@ -209,4 +209,14 @@ class AttributionTest < Test::Unit::TestCase
|
|
209
209
|
def test_has_many_setter_with_hash
|
210
210
|
assert_equal(["test"], Book.new("chapters" => { "0" => { "title" => "test" }}).chapters.map(&:title))
|
211
211
|
end
|
212
|
+
|
213
|
+
def test_non_attribute_values_should_be_ignored_by_the_initializer
|
214
|
+
book = Book.new(foo: 'bar')
|
215
|
+
assert_equal nil, book.instance_variable_get('@foo')
|
216
|
+
end
|
217
|
+
|
218
|
+
def test_to_json_should_only_include_attibutes
|
219
|
+
book = Book.new(id: 1, foo: 'bar')
|
220
|
+
assert_equal nil, JSON.parse(book.to_json)['foo']
|
221
|
+
end
|
212
222
|
end
|