her 0.7.1 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7626abb2e0aa83555379ffb426c47f766e7e5175
4
- data.tar.gz: 9036b8f208b4e9462740eb22fa1b6d21ef48b9c1
3
+ metadata.gz: e3f3ebeacfc88f8ba6fbb3dc98cb7527975c8531
4
+ data.tar.gz: c96e0c1b82ef1528529ac806a3d1b71e7e1aa434
5
5
  SHA512:
6
- metadata.gz: d6a8734624af88d8261d6f26147c517626530c925f886770b284471dde1f9903c455dd77a1dd6e7d21fc8a720d98d293fed0f3f967ccc3516dc05a1528a58b70
7
- data.tar.gz: 4badd683f1cc2550dc34758573c6a57b46843b52b1a12b213eb917b6b2c60542cb05ff47038c9cc5aa8d497571fbf8569432a7d56024e7109c83fcf200dedc5b
6
+ metadata.gz: 71d3c48cf6fc0aa560e5349d695cc234d981602d721e9c6d59e3ce64ab2b4916af39ff360c691c5e1a3f341381d6d4fc158b19d17cacb6ea0fc7310f18fe9d70
7
+ data.tar.gz: fdda014a8f9c66bf5f9f99b013022be531a798912a8e856d1b098fc846017e181237813849ebad7961d206ad799ab08948f47d64591a0b1955f3a9d3ff3cd476
data/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
  <a href="https://rubygems.org/gems/her"><img src="http://img.shields.io/gem/v/her.svg" /></a>
9
9
  <a href="https://codeclimate.com/github/remiprev/her"><img src="http://img.shields.io/codeclimate/github/remiprev/her.svg" /></a>
10
10
  <a href='https://gemnasium.com/remiprev/her'><img src="http://img.shields.io/gemnasium/remiprev/her.svg" /></a>
11
- <a href="https://travis-ci.org/remiprev/her"><img src="http://img.shields.io/travis/remiprev/her.svg" /></a>
11
+ <a href="https://travis-ci.org/remiprev/her"><img src="http://img.shields.io/travis/remiprev/her/master.svg" /></a>
12
12
  </p>
13
13
 
14
14
  ---
@@ -36,6 +36,16 @@ module Her
36
36
  end
37
37
  end
38
38
 
39
+ # @private
40
+ def association_names
41
+ associations.inject([]) { |memo, (name, details)| memo << details }.flatten.map { |a| a[:name] }
42
+ end
43
+
44
+ # @private
45
+ def association_keys
46
+ associations.inject([]) { |memo, (name, details)| memo << details }.flatten.map { |a| a[:data_key] }
47
+ end
48
+
39
49
  # Parse associations data after initializing a new object
40
50
  #
41
51
  # @private
@@ -49,8 +49,12 @@ module Her
49
49
  #
50
50
  # @private
51
51
  def self.use_setter_methods(model, params)
52
- setter_method_names = model.class.setter_method_names
53
52
  params ||= {}
53
+
54
+ reserved_keys = [:id, model.class.primary_key] + model.class.association_keys
55
+ model.class.attributes *params.keys.reject { |k| reserved_keys.include?(k) || reserved_keys.map(&:to_s).include?(k) }
56
+
57
+ setter_method_names = model.class.setter_method_names
54
58
  params.inject({}) do |memo, (key, value)|
55
59
  setter_method = key.to_s + '='
56
60
  if setter_method_names.include?(setter_method)
@@ -20,10 +20,10 @@ module Her
20
20
  #
21
21
  # user = User.new(name: "Tobias", role_attributes: { title: "moderator" })
22
22
  # user.role # => #<Role title="moderator">
23
- def accepts_nested_attributes_for(*association_names)
24
- allowed_association_names = associations.inject([]) { |memo, (name, details)| memo << details }.flatten.map { |a| a[:name] }
23
+ def accepts_nested_attributes_for(*associations)
24
+ allowed_association_names = association_names
25
25
 
26
- association_names.each do |association_name|
26
+ associations.each do |association_name|
27
27
  unless allowed_association_names.include?(association_name)
28
28
  raise Her::Errors::AssociationUnknownError.new("Unknown association name :#{association_name}")
29
29
  end
data/lib/her/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Her
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.2"
3
3
  end
@@ -10,6 +10,7 @@ describe "Her::Model and ActiveModel::Dirty" do
10
10
  builder.adapter :test do |stub|
11
11
  stub.get("/users/1") { |env| [200, {}, { :id => 1, :fullname => "Lindsay Fünke" }.to_json] }
12
12
  stub.get("/users/2") { |env| [200, {}, { :id => 2, :fullname => "Maeby Fünke" }.to_json] }
13
+ stub.get("/users/3") { |env| [200, {}, { :user_id => 3, :fullname => "Maeby Fünke" }.to_json] }
13
14
  stub.put("/users/1") { |env| [200, {}, { :id => 1, :fullname => "Tobias Fünke" }.to_json] }
14
15
  stub.put("/users/2") { |env| [400, {}, { :errors => ["Email cannot be blank"] }.to_json] }
15
16
  stub.post("/users") { |env| [200, {}, { :id => 1, :fullname => "Tobias Fünke" }.to_json] }
@@ -19,6 +20,9 @@ describe "Her::Model and ActiveModel::Dirty" do
19
20
  spawn_model "Foo::User" do
20
21
  attributes :fullname, :email
21
22
  end
23
+ spawn_model "Dynamic::User" do
24
+ primary_key :user_id
25
+ end
22
26
  end
23
27
 
24
28
  context "for existing resource" do
@@ -36,11 +40,20 @@ describe "Her::Model and ActiveModel::Dirty" do
36
40
  user.save
37
41
  user.should_not be_changed
38
42
  end
43
+
39
44
  it "tracks previous changes" do
40
45
  user.fullname = "Tobias Fünke"
41
46
  user.save
42
47
  user.previous_changes.should eq({"fullname"=>"Lindsay Fünke"})
43
48
  end
49
+
50
+ it 'tracks dirty attribute for mass assign for dynamic created attributes' do
51
+ user = Dynamic::User.find(3)
52
+ user.assign_attributes(:fullname => 'New Fullname')
53
+ user.fullname_changed?.should be_truthy
54
+ user.should be_changed
55
+ user.changes.length.should eq(1)
56
+ end
44
57
  end
45
58
 
46
59
  context "with erroneous save" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: her
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rémi Prévost
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-04 00:00:00.000000000 Z
11
+ date: 2014-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake