lhs 3.0.2 → 3.0.3

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: de4e937aec263ff69d6e9a3ba6325c644c4cd9fe
4
- data.tar.gz: f9b26639ef17eed08e07d9015892aa5cb86810dd
3
+ metadata.gz: 5457dca94fecc849496d18aaff5a9caa087608f8
4
+ data.tar.gz: c1854bf19ecd17ab7383cda4ee2cc482e068fecc
5
5
  SHA512:
6
- metadata.gz: 08b0a1aef783001857844d13927dccf03a6e5dabbb5d7804cb74a35776903d750760b6c7c89a60b488742c2d63cce9bbef3fe9fe9e1494d12ddf92be9b4595b6
7
- data.tar.gz: 8a08538eab98ca16604e3c14d8fc44f144f42be8ece4a0c0537189459437d23565b15068ffddb8b89ec959bac86a5838c9258f7fd44b6b1a25851686031090cb
6
+ metadata.gz: ceabba06f22f3337a24ef9410b7f2cd17b072c4c86ba3d4e8e8f01991d98f51eaa10448d77021baf5bb3055fe5226127ab8d6ccebe1da993b43c68a5e0691cfd
7
+ data.tar.gz: 861a4ff34ea47ed94c33e3b247ad75a25119f74a9a430b307a4b8f3bd05459cfb29fd280d00d4be986c86b3ea7a3062bb378f3a58390f8b5a8712c0cc10d4d05
@@ -9,7 +9,8 @@ class LHS::Item < LHS::Proxy
9
9
  self.errors = nil
10
10
  fail 'No validation endpoint found!' unless validation_endpoint
11
11
  record = LHS::Record.for_url(validation_endpoint.url)
12
- params = validation_endpoint.options.fetch(:params, {}).merge(persist: false)
12
+ validation_params = validation_endpoint.options[:validates] == true ? { persist: false } : { validation_endpoint.options[:validates] => false }
13
+ params = validation_endpoint.options.fetch(:params, {}).merge(validation_params)
13
14
  begin
14
15
  record.request(
15
16
  url: validation_endpoint.url,
@@ -1,3 +1,3 @@
1
1
  module LHS
2
- VERSION = "3.0.2"
2
+ VERSION = "3.0.3"
3
3
  end
@@ -3,83 +3,109 @@ require 'rails_helper'
3
3
  describe LHS::Item do
4
4
  let(:datastore) { 'http://local.ch' }
5
5
 
6
- before(:each) do
7
- LHC.config.placeholder('datastore', datastore)
8
- class User < LHS::Record
9
- endpoint ':datastore/v2/users', validates: true
10
- end
11
- mock_validation
12
- end
6
+ let(:validation_parameter) { 'persist' }
13
7
 
14
8
  let(:mock_validation) do
15
9
  successful_validation
16
10
  end
17
11
 
18
12
  let(:successful_validation) do
19
- stub_request(:post, "#{datastore}/v2/users?persist=false").to_return(body: '{}')
13
+ stub_request(:post, "#{datastore}/v2/users?#{validation_parameter}=false").to_return(body: '{}')
20
14
  end
21
15
 
22
- let(:failing_validation) do
23
- stub_request(:post, "#{datastore}/v2/users?persist=false")
24
- .to_return(status: 400,
25
- body: {
26
- field_errors: [{ code: "UNSUPPORTED_PROPERTY_VALUE", "path" => ["email"] }]
27
- }.to_json
28
- )
16
+ before(:each) do
17
+ mock_validation
29
18
  end
30
19
 
31
- context 'valid data' do
20
+ context 'custom validation parameter' do
21
+ let(:validation_parameter) { 'publish' }
22
+
32
23
  let(:user) do
33
24
  User.build(email: 'steve@local.ch')
34
25
  end
35
26
 
36
- it 'validates' do
37
- expect(user.valid?).to eq true
27
+ before(:each) do
28
+ LHC.config.placeholder('datastore', datastore)
29
+ class User < LHS::Record
30
+ endpoint ':datastore/v2/users', validates: 'publish'
31
+ end
38
32
  end
39
33
 
40
- it 'turns to be invalid if validating on changed, invalid data' do
34
+ it 'validates' do
41
35
  expect(user.valid?).to eq true
42
- user.email = 'not a valid email'
43
- failing_validation
44
- expect(user.valid?).to eq false
45
- expect(user.errors[:email]).to be
46
36
  end
47
37
  end
48
38
 
49
- context 'invalid data' do
50
- let(:user) do
51
- User.build(email: 'im not an email address')
39
+ context 'default parameter' do
40
+ before(:each) do
41
+ LHC.config.placeholder('datastore', datastore)
42
+ class User < LHS::Record
43
+ endpoint ':datastore/v2/users', validates: true
44
+ end
52
45
  end
53
46
 
54
- let(:mock_validation) do
55
- failing_validation
47
+ let(:failing_validation) do
48
+ stub_request(:post, "#{datastore}/v2/users?persist=false")
49
+ .to_return(status: 400,
50
+ body: {
51
+ field_errors: [{ code: "UNSUPPORTED_PROPERTY_VALUE", "path" => ["email"] }]
52
+ }.to_json
53
+ )
56
54
  end
57
55
 
58
- it 'does not validate and provides error messages' do
59
- expect(user.valid?).to eq false
60
- expect(user.errors[:email]).to be
61
- end
56
+ context 'valid data' do
57
+ let(:user) do
58
+ User.build(email: 'steve@local.ch')
59
+ end
62
60
 
63
- it 'resets errors when revalidating' do
64
- expect(user.valid?).to eq false
65
- user.email = 'steve@local.ch'
66
- successful_validation
67
- expect(user.valid?).to eq true
68
- expect(user.errors).to be_nil
61
+ it 'validates' do
62
+ expect(user.valid?).to eq true
63
+ end
64
+
65
+ it 'turns to be invalid if validating on changed, invalid data' do
66
+ expect(user.valid?).to eq true
67
+ user.email = 'not a valid email'
68
+ failing_validation
69
+ expect(user.valid?).to eq false
70
+ expect(user.errors[:email]).to be
71
+ end
69
72
  end
70
- end
71
73
 
72
- context 'endpoint does not support validations' do
73
- before(:each) do
74
- class Favorite < LHS::Record
75
- endpoint ':datastore/v2/favorites'
74
+ context 'invalid data' do
75
+ let(:user) do
76
+ User.build(email: 'im not an email address')
77
+ end
78
+
79
+ let(:mock_validation) do
80
+ failing_validation
81
+ end
82
+
83
+ it 'does not validate and provides error messages' do
84
+ expect(user.valid?).to eq false
85
+ expect(user.errors[:email]).to be
86
+ end
87
+
88
+ it 'resets errors when revalidating' do
89
+ expect(user.valid?).to eq false
90
+ user.email = 'steve@local.ch'
91
+ successful_validation
92
+ expect(user.valid?).to eq true
93
+ expect(user.errors).to be_nil
76
94
  end
77
95
  end
78
96
 
79
- it 'fails when trying to use an endpoint for validations that does not support it' do
80
- expect(lambda {
81
- Favorite.build.valid?
82
- }).to raise_error('Endpoint does not support validations!')
97
+ context 'endpoint does not support validations' do
98
+ before(:each) do
99
+ class Favorite < LHS::Record
100
+ endpoint ':datastore/v2/favorites'
101
+ end
102
+ end
103
+
104
+ it 'fails when trying to use an endpoint for validations that does not support it' do
105
+ expect(lambda do
106
+ Favorite.build.valid?
107
+ end).to raise_error('Endpoint does not support validations!')
108
+ end
83
109
  end
84
110
  end
85
111
  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: 3.0.2
4
+ version: 3.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/local-ch/lhs/graphs/contributors