linker 0.0.4 → 0.0.5

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: ac03dfe23e9fee4462e37ff348f534df0a1b5675
4
- data.tar.gz: a2cd229386f46837212830c1b7ad4e3be5688268
3
+ metadata.gz: 7215c599b0c4568eaee73a1f5dd17ef4494d8c67
4
+ data.tar.gz: 1f7122fc680bcbfa1471871e617966da3ec6c986
5
5
  SHA512:
6
- metadata.gz: d930171e67aeec914442f5430b96eb420d3a2926fb5a0c2ee4874774823a3d569222f9bd40caab56d91db7afcf4120826b20d2c5308465c53fec29b4391ba1bf
7
- data.tar.gz: 68ef88987ef64dc5046e6723e3cf7f51f55ddf0b33e09686957c521264611b8f1767a14ae30ea35b0362afb980dd2e5276e5a6351adc842318f29cad19ec9cf6
6
+ metadata.gz: b6307b9c840caffcaaa6afbae8205bcfd203c74e34459ae8e74fa3a6211c5178efac4703103aadfe569ec7922965029b6bcf399eb133094f78c949ad6093f944
7
+ data.tar.gz: 3893664531b92f965ada075022e2413ccea81558d236c00355a3e0c368e7e6b80acb41e4878d21fe94a4ef4c6a6db384558077d498959a6005f8f384d2b5eb8b
@@ -45,8 +45,8 @@ module Linker
45
45
  end
46
46
  elsif param.match(/_list$/)
47
47
  assoc = param.gsub(/_list$/, '')
48
- if search_has_one(assoc)
49
- final = value.present? ? assoc.camelize.constantize.send(:find, value) : nil
48
+ if r = search_has_one(assoc)
49
+ final = value.present? ? r[:klass].constantize.send(:find, value) : nil
50
50
  _get_main_model.send("#{assoc}=", final)
51
51
  end
52
52
  else
@@ -73,7 +73,8 @@ module Linker
73
73
  end
74
74
 
75
75
  def search_has_one name
76
- map_has_one_associations.select{|c| c[:name] == name}.present?
76
+ s = map_has_one_associations.detect{|c| c[:name] == name}
77
+ s.present? && s
77
78
  end
78
79
  end
79
80
  end
@@ -1,3 +1,3 @@
1
1
  module Linker
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -4,6 +4,7 @@ class User < ActiveRecord::Base
4
4
 
5
5
  has_one :address, dependent: :destroy
6
6
  has_one :profile
7
+ has_one :my_phone, class_name: 'Phone'
7
8
  has_one :little_pet, class_name: 'Pet'
8
9
 
9
10
  has_many :dependent_users, dependent: :destroy
@@ -37,6 +38,9 @@ end
37
38
  class Profile < ActiveRecord::Base
38
39
  end
39
40
 
41
+ class Phone < ActiveRecord::Base
42
+ end
43
+
40
44
  #migrations
41
45
  class CreateAllTables < ActiveRecord::Migration
42
46
  def self.up
@@ -100,6 +104,13 @@ class CreateAllTables < ActiveRecord::Migration
100
104
  t.timestamps
101
105
  end
102
106
 
107
+ create_table :phones do |t|
108
+ t.string :phone_number
109
+ t.references :user, index: true
110
+
111
+ t.timestamps
112
+ end
113
+
103
114
  end
104
115
  end
105
116
  ActiveRecord::Migration.verbose = false
@@ -109,6 +120,10 @@ Profile.create(profile_type: 'A')
109
120
  Profile.create(profile_type: 'B')
110
121
  Profile.create(profile_type: 'C')
111
122
 
123
+ Phone.create(phone_number: 'ZA')
124
+ Phone.create(phone_number: 'ZB')
125
+ Phone.create(phone_number: 'ZC')
126
+
112
127
  # seed
113
128
  bar = User.create(name: 'Bar')
114
129
  bar.my_tasks << Task.create(name: 'Task 1')
@@ -40,6 +40,10 @@ describe UsersForm do
40
40
  subject(:profile_list) { users_form.profile_list }
41
41
  it { expect(profile_list).to eq(nil) }
42
42
 
43
+ it { expect(users_form).to respond_to(:my_phone_list) }
44
+ subject(:my_phone_list) { users_form.my_phone_list }
45
+ it { expect(my_phone_list).to eq(nil) }
46
+
43
47
  it { expect(users_form).to respond_to(:little_pet, :little_pet_attributes=) }
44
48
  subject(:pet) { users_form.little_pet }
45
49
  it { expect(pet).to be_an(Pet) }
@@ -70,6 +74,8 @@ describe UsersForm do
70
74
 
71
75
  it { expect(profile_list).to eq(nil) }
72
76
 
77
+ it { expect(my_phone_list).to eq(nil) }
78
+
73
79
  it { expect(pet.persisted?).to eq(false) }
74
80
 
75
81
  it { expect(company.persisted?).to eq(false) }
@@ -85,6 +91,7 @@ describe UsersForm do
85
91
  'my_family_attributes' => {'id' => '', 'last_name' => 'Milan'},
86
92
  'address_attributes' => {'id' => '', 'street' => '', 'district' => ''},
87
93
  'profile_list' => '1',
94
+ 'my_phone_list' => '2',
88
95
  'little_pet_attributes' => {'id' => '', 'name' => 'Stuart'},
89
96
  'my_tasks_attributes' => {'0' => {'id' => '', 'name' => 'T1'}, '1' => {'id' => '', 'name' => 'T2'}},
90
97
  'dependent_users_attributes' => {'0' => {'id' => '', 'name' => '', 'date_birth' => ''}, '1' => {'id' => '', 'name' => '', 'date_birth' => ''}}
@@ -106,6 +113,7 @@ describe UsersForm do
106
113
  it { expect(dependent_users_sample.name).to eq('') }
107
114
 
108
115
  it { expect(profile_list).to eq(1) }
116
+ it { expect(my_phone_list).to eq(2) }
109
117
 
110
118
  it { expect(pet).to be_a(Pet)}
111
119
  it { expect(pet.persisted?).to be(true)}
@@ -132,6 +140,7 @@ describe UsersForm do
132
140
  'my_family_attributes' => {'id' => '', 'last_name' => 'Milan'},
133
141
  'address_attributes' => {'id' => '', 'street' => '', 'district' => ''},
134
142
  'profile_list' => '',
143
+ 'my_phone_list' => '',
135
144
  'little_pet_attributes' => {'id' => '1', 'name' => 'Stuart 2'},
136
145
  #'tasks_attributes' => {'0' => {'id' => '', 'name' => 'T1'}, '1' => {'id' => '', 'name' => 'T2'}},
137
146
  'dependent_users_attributes' => {'0' => {'id' => '1', 'name' => 'John 2', 'date_birth' => Date.new(1990, 2, 2)}, '1' => {'id' => '', 'name' => '', 'date_birth' => ''}}
@@ -178,6 +187,7 @@ describe UsersForm do
178
187
  it { expect(users_form_existing_user_family.last_name).to eq('Milan') }
179
188
 
180
189
  it { expect(users_form_existing_user.profile_list).to be(nil) }
190
+ it { expect(users_form_existing_user.my_phone_list).to be(nil) }
181
191
 
182
192
  it { expect(users_form_existing_user_pet).to be_a(Pet) }
183
193
  it { expect(users_form_existing_user_pet.persisted?).to be(true) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Glauco Custódio