lhs 4.1.0 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lhs/concerns/item/save.rb +8 -6
- data/lib/lhs/concerns/record/create.rb +6 -10
- data/lib/lhs/version.rb +1 -1
- data/spec/record/create_spec.rb +54 -0
- data/spec/record/new_spec.rb +9 -9
- data/spec/record/persisted_spec.rb +2 -7
- data/spec/record/save_spec.rb +28 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9054af3b33bec8e693c84c84e44ba80845e4525c
|
4
|
+
data.tar.gz: 6ebd3acdaa73985d3f1845c92fe3cf57803c604f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51165a2c4256deb6cf82f445c8a597b7c1830a40edc1004239c32b34bf629bd5e81417590351e0f88159c5a60aebaf68f79199042ccffb8b80a078096879fe1e
|
7
|
+
data.tar.gz: ee0fe6d834cf6194276852903e7a33215fba61eb6b0b1715bea3da2b9a2c8478c465c32c8c13fb9371131c907d09d506bb7e20efcce5e32cb438498d7aba6d80
|
@@ -16,12 +16,14 @@ class LHS::Item < LHS::Proxy
|
|
16
16
|
def save!
|
17
17
|
record = _data.class
|
18
18
|
data = _data._raw.dup
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
if href.present?
|
20
|
+
url = href
|
21
|
+
else
|
22
|
+
endpoint = record.find_endpoint(data)
|
23
|
+
url = endpoint.compile(data)
|
24
|
+
endpoint.remove_interpolated_params!(data)
|
25
|
+
end
|
26
|
+
|
25
27
|
data = record.request(method: :post, url: url, body: data.to_json, headers: { 'Content-Type' => 'application/json' })
|
26
28
|
_data.merge_raw!(data)
|
27
29
|
true
|
@@ -7,19 +7,15 @@ class LHS::Record
|
|
7
7
|
|
8
8
|
module ClassMethods
|
9
9
|
def create(data = {})
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
data = LHS::Data.new(json, nil, self, e.response.request)
|
14
|
-
item = LHS::Item.new(data)
|
15
|
-
item.errors = LHS::Errors.new(e.response)
|
16
|
-
data._record.new(LHS::Data.new(item, data))
|
10
|
+
record = new(data)
|
11
|
+
record.save
|
12
|
+
record
|
17
13
|
end
|
18
14
|
|
19
15
|
def create!(data = {})
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
record = new(data)
|
17
|
+
record.save!
|
18
|
+
record
|
23
19
|
end
|
24
20
|
end
|
25
21
|
end
|
data/lib/lhs/version.rb
CHANGED
data/spec/record/create_spec.rb
CHANGED
@@ -76,5 +76,59 @@ describe LHS::Record do
|
|
76
76
|
}).to raise_error
|
77
77
|
end
|
78
78
|
end
|
79
|
+
|
80
|
+
context 'custom setters' do
|
81
|
+
before(:each) do
|
82
|
+
class Feedback
|
83
|
+
def ratings=(ratings)
|
84
|
+
_raw[:ratings] = ratings.map { |k, v| { name: k.to_s, value: v } }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
stub_request(:post, "#{datastore}/feedbacks")
|
89
|
+
.with(body: { ratings: converted_ratings }.to_json)
|
90
|
+
.to_return(status: 200, body: { ratings: converted_ratings }.to_json)
|
91
|
+
end
|
92
|
+
|
93
|
+
let(:ratings) do
|
94
|
+
{
|
95
|
+
a: 1,
|
96
|
+
b: 2
|
97
|
+
}
|
98
|
+
end
|
99
|
+
|
100
|
+
let(:converted_ratings) do
|
101
|
+
[
|
102
|
+
{ name: 'a', value: 1 },
|
103
|
+
{ name: 'b', value: 2 }
|
104
|
+
]
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'are used by create' do
|
108
|
+
feedback = Feedback.create(ratings: ratings)
|
109
|
+
expect(feedback.ratings.raw).to eq(converted_ratings)
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'can be used directly to change raw data' do
|
113
|
+
feedback = Feedback.create(ratings: ratings)
|
114
|
+
feedback.ratings = { z: 3 }
|
115
|
+
expect(feedback.ratings.first.name).to eq 'z'
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'and custom getters' do
|
119
|
+
before(:each) do
|
120
|
+
class Feedback
|
121
|
+
def ratings
|
122
|
+
Hash[_raw[:ratings].map { |r| [r[:name].to_sym, r[:value]] }]
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'uses custom getters to show data for exploration' do
|
128
|
+
feedback = Feedback.create(ratings: ratings)
|
129
|
+
expect(feedback.ratings).to eq(ratings)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
79
133
|
end
|
80
134
|
end
|
data/spec/record/new_spec.rb
CHANGED
@@ -6,15 +6,15 @@ describe LHS::Record do
|
|
6
6
|
|
7
7
|
before(:each) do
|
8
8
|
LHC.config.placeholder('datastore', datastore)
|
9
|
-
class
|
9
|
+
class Rating < LHS::Record
|
10
10
|
endpoint ':datastore/content-ads/:campaign_id/feedbacks'
|
11
11
|
endpoint ':datastore/feedbacks'
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'builds a new item from scratch (like build)' do
|
16
|
-
feedback =
|
17
|
-
expect(feedback).to be_kind_of
|
16
|
+
feedback = Rating.new recommended: true
|
17
|
+
expect(feedback).to be_kind_of Rating
|
18
18
|
expect(feedback.recommended).to eq true
|
19
19
|
stub_request(:post, "http://local.ch/v2/feedbacks")
|
20
20
|
.with(body: "{\"recommended\":true}")
|
@@ -22,7 +22,7 @@ describe LHS::Record do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'builds new items also with keys containing dashes' do
|
25
|
-
feedback =
|
25
|
+
feedback = Rating.new('some-key' => [])
|
26
26
|
expect(feedback._raw[:'some-key']).to eq([])
|
27
27
|
end
|
28
28
|
|
@@ -47,7 +47,7 @@ describe LHS::Record do
|
|
47
47
|
|
48
48
|
context 'custom setters' do
|
49
49
|
before(:each) do
|
50
|
-
class
|
50
|
+
class Rating
|
51
51
|
def ratings=(ratings)
|
52
52
|
_raw[:ratings] = ratings.map { |k, v| { name: k, value: v } }
|
53
53
|
end
|
@@ -55,19 +55,19 @@ describe LHS::Record do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'are used by initializer' do
|
58
|
-
feedback =
|
58
|
+
feedback = Rating.new(ratings: { a: 1, b: 2 })
|
59
59
|
expect(feedback.ratings.raw).to eq([{ name: :a, value: 1 }, { name: :b, value: 2 }])
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'can be used directly to change raw data' do
|
63
|
-
feedback =
|
63
|
+
feedback = Rating.new(ratings: { a: 1 })
|
64
64
|
feedback.ratings = { z: 3 }
|
65
65
|
expect(feedback.ratings.first.name).to eq :z
|
66
66
|
end
|
67
67
|
|
68
68
|
context 'and custom getters' do
|
69
69
|
before(:each) do
|
70
|
-
class
|
70
|
+
class Rating
|
71
71
|
def ratings
|
72
72
|
Hash[_raw[:ratings].map { |r| [r[:name], r[:value]] }]
|
73
73
|
end
|
@@ -75,7 +75,7 @@ describe LHS::Record do
|
|
75
75
|
end
|
76
76
|
|
77
77
|
it 'uses custom getters to show data for exploration' do
|
78
|
-
feedback =
|
78
|
+
feedback = Rating.new(ratings: { a: 1, b: 2 })
|
79
79
|
expect(feedback.ratings).to eq(a: 1, b: 2)
|
80
80
|
end
|
81
81
|
end
|
@@ -21,13 +21,8 @@ describe LHS::Record do
|
|
21
21
|
|
22
22
|
context 'for saved record' do
|
23
23
|
let(:campaign_id) { 'aaa' }
|
24
|
-
let(:parameters)
|
25
|
-
|
26
|
-
recommended: true,
|
27
|
-
campaign_id: campaign_id
|
28
|
-
}
|
29
|
-
end
|
30
|
-
subject { Feedback.new(parameters) }
|
24
|
+
let(:parameters) { { recommended: true } }
|
25
|
+
subject { Feedback.new(parameters.merge(campaign_id: campaign_id)) }
|
31
26
|
|
32
27
|
before do
|
33
28
|
stub_request(:post, "#{datastore}/content-ads/#{campaign_id}/feedbacks")
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe LHS::Record do
|
4
|
+
context 'save!' do
|
5
|
+
context 'without href' do
|
6
|
+
before do
|
7
|
+
LHC.config.placeholder('datastore', datastore)
|
8
|
+
class Feedback < LHS::Record
|
9
|
+
endpoint ':datastore/content-ads/:campaign_id/feedbacks'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:datastore) { 'http://local.ch/v2' }
|
14
|
+
let(:campaign_id) { 12345 }
|
15
|
+
let(:object) { { recommended: true } }
|
16
|
+
let(:item) { Feedback.new(object.merge(campaign_id: campaign_id)) }
|
17
|
+
|
18
|
+
it 'removes params used to compute url from send data' do
|
19
|
+
datastore_request = stub_request(:post, "#{datastore}/content-ads/#{campaign_id}/feedbacks")
|
20
|
+
.with(body: object.to_json)
|
21
|
+
.to_return(status: 200, body: object.to_json)
|
22
|
+
|
23
|
+
item.save!
|
24
|
+
expect(datastore_request).to have_been_made.once
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lhs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- https://github.com/local-ch/lhs/graphs/contributors
|
@@ -295,6 +295,7 @@ files:
|
|
295
295
|
- spec/record/pagination_spec.rb
|
296
296
|
- spec/record/persisted_spec.rb
|
297
297
|
- spec/record/request_spec.rb
|
298
|
+
- spec/record/save_spec.rb
|
298
299
|
- spec/record/select_spec.rb
|
299
300
|
- spec/record/to_json_spec.rb
|
300
301
|
- spec/record/where_spec.rb
|
@@ -419,6 +420,7 @@ test_files:
|
|
419
420
|
- spec/record/pagination_spec.rb
|
420
421
|
- spec/record/persisted_spec.rb
|
421
422
|
- spec/record/request_spec.rb
|
423
|
+
- spec/record/save_spec.rb
|
422
424
|
- spec/record/select_spec.rb
|
423
425
|
- spec/record/to_json_spec.rb
|
424
426
|
- spec/record/where_spec.rb
|