rest_my_case 1.9.1 → 1.9.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: 4eaca5ca9d55737b8d3aadc7d215d3bb13f2aabe
4
- data.tar.gz: e4a6d32211c6c2033b341a1c53e4894b642a9985
3
+ metadata.gz: 088ea74126da74d24cd42b6ca1bd23838cf16f74
4
+ data.tar.gz: a5c583155c12293f7e23e23213bab13c74cf3544
5
5
  SHA512:
6
- metadata.gz: f34ecef601ece173ee6960d489ca331c767a23e255977f46c0b2362d745555781f9540a2bbb9032e9e1cd44ad3bd9c96c8c20741d047fefbf5f1644e05cdc790
7
- data.tar.gz: b2a4efbdf1e1975f9b037a7a6e6162e3a6548c02533dca21474a6f6a53798e7399b78266765478eb814382b9482d7bdcba71abd846f94bc245553ad5ca1a9fde
6
+ metadata.gz: d48c0464b9ea66217c168963ebbef24542273a55336486e0c0dcbfb0a7bf5ae8bbdf38cbdfb7d4dbf646f401a7d9ff62196e9885c13493a1e8af19c418c39057
7
+ data.tar.gz: 6c8546d1508b909c58e19287d7e8e8dc826f311a4e52387d7aeaf49b72d693e3d40816fba6da3c90d9253d4d3f5cdfed6fed21dc88c450cc613b6ffb5f73a69e
@@ -10,10 +10,20 @@ module RestMyCase
10
10
  @context = context
11
11
  end
12
12
 
13
- def add(error, message)
14
- self[error] ||= []
13
+ def add(class_name, message)
14
+ self[class_name] ||= []
15
15
 
16
- self[error].push(message)
16
+ self[class_name].push(message.to_s)
17
+ end
18
+
19
+ def messages
20
+ self.values.flatten
21
+ end
22
+
23
+ def full_messages
24
+ self.map do |class_name, messages|
25
+ "#{class_name}: #{messages.join(', ')}"
26
+ end
17
27
  end
18
28
 
19
29
  end
@@ -7,7 +7,9 @@ module RestMyCase
7
7
  def add(error, message)
8
8
  super
9
9
 
10
- @context.status.send("#{message}!")
10
+ status = message.to_s.split(' - ')[0]
11
+
12
+ @context.status.send("#{status}!")
11
13
  end
12
14
 
13
15
  end
@@ -1,5 +1,5 @@
1
1
  module RestMyCase
2
2
 
3
- VERSION = '1.9.1'
3
+ VERSION = '1.9.2'
4
4
 
5
5
  end
@@ -4,9 +4,9 @@ describe RestMyCase::AccusationAttorneys::Base do
4
4
 
5
5
  describe '#validate' do
6
6
  context "given that the child class hasn't implemented the validate method" do
7
- TestCase4 = Class.new(described_class)
7
+ AccusationAttorneysTestCase1 = Class.new(described_class)
8
8
 
9
- before { @instance = TestCase4.new({ attributes: { id: '1' } }) }
9
+ before { @instance = AccusationAttorneysTestCase1.new({ attributes: { id: '1' } }) }
10
10
 
11
11
  it 'should raise an error' do
12
12
  expect { @instance.validate(nil) }.to raise_error
@@ -4,9 +4,9 @@ describe RestMyCase::AccusationAttorneys::Each do
4
4
 
5
5
  describe '#validate_each' do
6
6
  context "given that the child class hasn't implemented the validate_each method" do
7
- TestCase5 = Class.new(described_class)
7
+ AccusationAttorneysTestCase2 = Class.new(described_class)
8
8
 
9
- before { @instance = TestCase5.new({ attributes: { id: '1' } }) }
9
+ before { @instance = AccusationAttorneysTestCase2.new({ attributes: { id: '1' } }) }
10
10
 
11
11
  it 'should raise an error' do
12
12
  expect { @instance.validate_each(nil, nil, nil) }.to raise_error
@@ -108,6 +108,7 @@ describe RestMyCase::Base do
108
108
 
109
109
  it "context should contain only one error" do
110
110
  expect(@context.errors).to match a_hash_including({"Perform::ValidateName"=>[""]})
111
+ expect(@context.errors.full_messages).to eq ["Perform::ValidateName: "]
111
112
  end
112
113
 
113
114
  it "context prove that only the correct method have ran" do
@@ -130,6 +131,7 @@ describe RestMyCase::Base do
130
131
 
131
132
  it "context should contain only one error" do
132
133
  expect(@context.errors).to match a_hash_including({"Perform::ValidateName"=>[""]})
134
+ expect(@context.errors.full_messages).to eq ["Perform::ValidateName: "]
133
135
  end
134
136
 
135
137
  it "context prove that only the correct method have ran" do
@@ -231,6 +233,7 @@ describe RestMyCase::Base do
231
233
 
232
234
  it "context should contain only 2 errors" do
233
235
  expect(@context.errors).to match a_hash_including({"Perform::ValidateName"=>[""], "Perform::ValidateBody"=>[""]})
236
+ expect(@context.errors.full_messages).to eq ["Perform::ValidateName: ", "Perform::ValidateBody: "]
234
237
  end
235
238
 
236
239
  it "context prove that only the correct method have ran" do
@@ -255,6 +258,7 @@ describe RestMyCase::Base do
255
258
 
256
259
  it "context should contain only 2 errors" do
257
260
  expect(@context.errors).to match a_hash_including({"Perform::ValidateName"=>[""], "Perform::ValidateBody"=>[""]})
261
+ expect(@context.errors.full_messages).to eq ["Perform::ValidateName: ", "Perform::ValidateBody: "]
258
262
  end
259
263
 
260
264
  it "context prove that only the correct method have ran" do
@@ -290,6 +294,7 @@ describe RestMyCase::Base do
290
294
 
291
295
  it "context should contain only 4 errors" do
292
296
  expect(@context.errors).to match a_hash_including({"Perform::BuildPost"=>[""], "Perform::ValidateName"=>[""], "Perform::ValidateBody"=>[""], "Perform::SavePost"=>[""]})
297
+ expect(@context.errors.full_messages).to eq ["Perform::BuildPost: ", "Perform::ValidateName: ", "Perform::ValidateBody: ", "Perform::SavePost: "]
293
298
  end
294
299
 
295
300
  it "context prove that only the correct method have ran" do
@@ -18,10 +18,10 @@ describe RestMyCase::Status do
18
18
  end
19
19
  end
20
20
 
21
- context "when failure(:unprocessable_entity) is used" do
21
+ context "when error(:unprocessable_entity) is used" do
22
22
  TestCase2 = Class.new(described_class) do
23
23
  def perform
24
- failure(:unprocessable_entity)
24
+ error(:unprocessable_entity)
25
25
  context.next_line = true
26
26
  end
27
27
  end
@@ -41,14 +41,17 @@ describe RestMyCase::Status do
41
41
  end
42
42
 
43
43
  it "context's errors should have a proper message" do
44
- expect(@context.errors["TestCase2"]).to eq ["unprocessable_entity"]
44
+ message = "unprocessable_entity"
45
+
46
+ expect(@context.errors["TestCase2"]).to eq [message]
47
+ expect(@context.errors.messages).to eq [message]
45
48
  end
46
49
  end
47
50
 
48
- context "when failure!(:internal_server_error) is used" do
51
+ context "when error!(:internal_server_error) is used" do
49
52
  TestCase3 = Class.new(described_class) do
50
53
  def perform
51
- failure!(:internal_server_error)
54
+ error!(:internal_server_error)
52
55
  context.next_line = true
53
56
  end
54
57
  end
@@ -68,7 +71,70 @@ describe RestMyCase::Status do
68
71
  end
69
72
 
70
73
  it "context's errors should have a proper message" do
71
- expect(TestCase3.perform.errors["TestCase3"]).to eq ["internal_server_error"]
74
+ message = "internal_server_error"
75
+
76
+ expect(@context.errors["TestCase3"]).to eq [message]
77
+ expect(@context.errors.messages).to eq [message]
78
+ end
79
+ end
80
+
81
+ context "when failure(:unprocessable_entity) is used" do
82
+ TestCase4 = Class.new(described_class) do
83
+ def perform
84
+ failure(:unprocessable_entity, 'invalid id')
85
+ context.next_line = true
86
+ end
87
+ end
88
+
89
+ before { @context = TestCase4.perform }
90
+
91
+ it "@context.status.unprocessable_entity? should be true" do
92
+ expect(@context.status.unprocessable_entity?).to be true
93
+ end
94
+
95
+ it "@context.next_line should be true" do
96
+ expect(@context.next_line).to be true
97
+ end
98
+
99
+ it "@context.status.ok? should be false" do
100
+ expect(@context.status.ok?).to be false
101
+ end
102
+
103
+ it "context's errors should have a proper message" do
104
+ message = "unprocessable_entity - invalid id"
105
+
106
+ expect(@context.errors["TestCase4"]).to eq [message]
107
+ expect(@context.errors.messages).to eq [message]
108
+ end
109
+ end
110
+
111
+ context "when failure!(:internal_server_error) is used" do
112
+ TestCase5 = Class.new(described_class) do
113
+ def perform
114
+ failure!(:internal_server_error, 'while saving the resource')
115
+ context.next_line = true
116
+ end
117
+ end
118
+
119
+ before { @context = TestCase5.perform }
120
+
121
+ it "@context.status.internal_server_error? should be true" do
122
+ expect(@context.status.internal_server_error?).to be true
123
+ end
124
+
125
+ it "@context.next_line should be true" do
126
+ expect { context.next_line }.to raise_error
127
+ end
128
+
129
+ it "@context.status.ok? should be false" do
130
+ expect(@context.status.ok?).to be false
131
+ end
132
+
133
+ it "context's errors should have a proper message" do
134
+ message = "internal_server_error - while saving the resource"
135
+
136
+ expect(@context.errors["TestCase5"]).to eq [message]
137
+ expect(@context.errors.messages).to eq [message]
72
138
  end
73
139
  end
74
140
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest_my_case
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.1
4
+ version: 1.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - goncalvesjoao