lhs 6.3.0 → 6.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e5f67d6a0394eaf9742357631505c14ecf0d308
4
- data.tar.gz: 725d43ea3e43f8374e210b5d29a0e54fde5d4a11
3
+ metadata.gz: e9f38d7e7d79b9099b282d29cdd8c126d9ec2a97
4
+ data.tar.gz: b01e749df675ef68f1a13923a7d73b2317a58614
5
5
  SHA512:
6
- metadata.gz: 5344e79fe480861ae6fe214f9c5fd7f19fb6bfaa754a99dc9afecb2de9efb636b1f80f3b76c7a6e0a23c1efa20e7264a884d8253a7c5c020c23e2b838cb637e8
7
- data.tar.gz: b060a234369822f4dd32b945d576cf089e9e56352bd3ced2ee26aeb62c604f48e9febb72fb226c34ed723039ad012efe469ddabe71319264824b95a074726913
6
+ metadata.gz: ac30a7cd582675b6ba8d7b02748563b64ee6c572858102dcccd9be8db7e70213575dc5a35ded169449d738c78d6a79636df1eb35b0ffe48f068814038c59be93
7
+ data.tar.gz: 8eb224deb70fa275b5ea13722854ee1d4a971f9ffa509c468aafd74dbf7684edc2a0d37551ff876733d87137b82386cd50c41b18cb9797f07217495b43ca5b68
@@ -25,7 +25,7 @@ class LHS::Record
25
25
  data = LHS::Data.new({}, nil, self.class) unless data
26
26
  data = LHS::Data.new(data, nil, self.class) unless data.is_a?(LHS::Data)
27
27
  define_singleton_method(:_data) { data }
28
- consider_custom_setters
28
+ apply_custom_setters!
29
29
  end
30
30
 
31
31
  def as_json(options = nil)
@@ -48,20 +48,13 @@ class LHS::Record
48
48
 
49
49
  private
50
50
 
51
- def consider_custom_setters
52
- return if !instance_data.is_a?(Hash)
53
- instance_data.each do |k, v|
54
- if public_methods.include?("#{k}=".to_sym)
55
- send("#{k}=", v)
56
- end
57
- end
58
- end
59
-
60
- def instance_data
61
- if _data._proxy.is_a?(LHS::Collection) && _data._raw.is_a?(Hash)
62
- _data._raw.fetch(:items, [])
63
- else
64
- _data._raw
51
+ def apply_custom_setters!
52
+ return if !_data.item? || !_data._raw.respond_to?(:keys)
53
+ raw = _data._raw
54
+ custom_setters = raw.keys.find_all { |key| public_methods.include?("#{key}=".to_sym) }
55
+ custom_setters.each do |setter|
56
+ value = raw.delete(setter)
57
+ send("#{setter}=", value)
65
58
  end
66
59
  end
67
60
  end
@@ -1,3 +1,3 @@
1
1
  module LHS
2
- VERSION = "6.3.0"
2
+ VERSION = "6.3.1"
3
3
  end
@@ -73,7 +73,7 @@ describe LHS::Record do
73
73
  .to_return(status: 400, body: creation_error.to_json)
74
74
  expect(lambda {
75
75
  Feedback.create!(object.merge(campaign_id: '12345'))
76
- }).to raise_error
76
+ }).to raise_error(LHC::Error)
77
77
  end
78
78
  end
79
79
 
@@ -10,7 +10,8 @@ describe LHS::Record do
10
10
  endpoint ':datastore/v2/reviews'
11
11
  end
12
12
  }
13
- ).to raise_error
13
+ ).to raise_error(/Clashing endpoints/)
14
+
14
15
  expect(
15
16
  lambda {
16
17
  class Record < LHS::Record
@@ -18,7 +19,7 @@ describe LHS::Record do
18
19
  endpoint ':datastore/v2/:campaign_id/reviews'
19
20
  end
20
21
  }
21
- ).to raise_error
22
+ ).to raise_error(/Clashing endpoints/)
22
23
  end
23
24
  end
24
25
  end
@@ -6,21 +6,40 @@ describe LHS::Record do
6
6
  endpoint 'http://datastore/records/:id'
7
7
  end
8
8
  stub_request(:get, "http://datastore/records/1")
9
- .to_return(body: {
10
- name: 'Steve',
11
- kind: {
12
- animal: {
13
- type: 'Monkey'
14
- }
15
- }
16
- }.to_json)
9
+ .to_return(body: attrbitutes.to_json)
17
10
  end
18
11
 
19
12
  let(:record) { Record.find(1) }
13
+ let(:attrbitutes) do
14
+ {
15
+ name: 'Steve',
16
+ kind: {
17
+ animal: {
18
+ type: 'Monkey'
19
+ }
20
+ }
21
+ }
22
+ end
23
+
24
+ let(:output) { "Record##{record.object_id}\n:name => \"Steve\"\n:kind => {:animal=>{:type=>\"Monkey\"}}" }
20
25
 
21
26
  context 'inspect' do
22
27
  it 'prints the record on the terminal: each attrbitute on a new line' do
23
- expect(record.inspect).to eq "Record##{record.object_id}\n:name => \"Steve\"\n:kind => {:animal=>{:type=>\"Monkey\"}}"
28
+ expect(record.inspect).to eq(output)
29
+ end
30
+
31
+ context 'with custom setters that do no touch raw data' do
32
+ before do
33
+ class Record
34
+ attr_accessor :listing
35
+ end
36
+ end
37
+
38
+ let(:record) { Record.new(attrbitutes.merge(listing: double('listing'))) }
39
+
40
+ it 'does not print what is not in raw' do
41
+ expect(record.inspect).to eq(output)
42
+ end
24
43
  end
25
44
  end
26
45
  end
@@ -65,6 +65,26 @@ describe LHS::Record do
65
65
  expect(feedback.ratings.first.name).to eq :z
66
66
  end
67
67
 
68
+ context 'that do not affect raw data' do
69
+ before(:each) do
70
+ class Rating
71
+ attr_accessor :listing
72
+ end
73
+ end
74
+
75
+ let(:listing) { double('listing') }
76
+
77
+ it 'are used by initializer' do
78
+ feedback = Rating.new(listing: listing)
79
+ expect(feedback.listing).to eq(listing)
80
+ end
81
+
82
+ it 'do not set raw data' do
83
+ feedback = Rating.new(listing: listing)
84
+ expect(feedback._raw[:listing]).to be_nil
85
+ end
86
+ end
87
+
68
88
  context 'and custom getters' do
69
89
  before(:each) do
70
90
  class Rating
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhs
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.3.0
4
+ version: 6.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/local-ch/lhs/graphs/contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-04 00:00:00.000000000 Z
11
+ date: 2016-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lhc
@@ -351,7 +351,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
351
351
  requirements:
352
352
  - Ruby >= 2.0.0
353
353
  rubyforge_project:
354
- rubygems_version: 2.2.2
354
+ rubygems_version: 2.6.5
355
355
  signing_key:
356
356
  specification_version: 4
357
357
  summary: Rails gem providing an easy, active-record-like interface for http json services