response_state 0.2.0 → 0.2.1

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: 07191e8d424f92fed0fef312a55e39af9bfb7167
4
- data.tar.gz: 704aa92961c5bed9a8b6f3214ec81c8d16c75dd8
3
+ metadata.gz: 4e0cea61825ed6f590a0b2510a4a6a0f368e4b93
4
+ data.tar.gz: d7e616a314b7073920d2be12b22724a4166f75cf
5
5
  SHA512:
6
- metadata.gz: 5f98c261f52b66717c562f1b3c76bbf761971ad7b9154468c7618a5ca6aaa876a8151f2de684e0a7a3ce3bb11ca1aa7ae79e401597f0f3a2eb82f375c7d406c6
7
- data.tar.gz: 35943cdbbc29d7145b80718b6b812cbd3a52c00450f584ed762efdd36733984c9ff1eee10abaa229bdba2e27c66094f5e3dd009d64455680b691ca1cc5c0f8f4
6
+ metadata.gz: d530ace92af0e4e98345fbacaf69cb02047dfe6c6f11a2352794796d14b25a55b2badd9cb36cf345c9328c7d58866eb51c8b1b1d37427a44f1e587c14d690944
7
+ data.tar.gz: 3cfc434592e2ab21ba32d25f5374cb1cbcaa604f9a8c73cae9597560fe9d7468f7633b3553d860c3ee56ab524050ca55112d871ffcab955128b943e1eef622e6
data/README.md CHANGED
@@ -30,13 +30,14 @@ class MyService < ResponseState::Service
30
30
 
31
31
  def call(&block)
32
32
  # do some work
33
- yield ResponseState::Response.new(:success)
33
+ yield send_state(:success)
34
34
  end
35
35
  end
36
36
  ```
37
37
 
38
38
  You must implement a `call` method.
39
39
  Your call method should yield with a `ResponseState::Response`.
40
+ The response can be generated with a helper method `send_state` in your service class.
40
41
 
41
42
  ### Response
42
43
 
@@ -34,4 +34,4 @@ module ResponseState
34
34
  raise "Invalid state: #{call_state}"
35
35
  end
36
36
  end
37
- end
37
+ end
@@ -6,7 +6,11 @@ module ResponseState
6
6
  end
7
7
 
8
8
  def call(&block)
9
- yield Response.new(:unimplemented, "A ResponseState::Service should implement the call method.\nThe call method should perform the relevant work of the service and yield a ResponseState::Response object.\n")
9
+ yield send_state(:unimplemented, "A ResponseState::Service should implement the call method.\nThe call method should perform the relevant work of the service and yield a ResponseState::Response object.\n")
10
+ end
11
+
12
+ def send_state(state, message=nil, context=nil, valid_states=nil)
13
+ ResponseState::Response.new(state, message, context, valid_states)
10
14
  end
11
15
  end
12
- end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module ResponseState
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -25,5 +25,87 @@ module ResponseState
25
25
  expect(response.message).to eq "A ResponseState::Service should implement the call method.\nThe call method should perform the relevant work of the service and yield a ResponseState::Response object.\n"
26
26
  end
27
27
  end
28
+
29
+ describe '#send_state' do
30
+ context 'given :success, "a message", {}, [:success, :failure]' do
31
+ let(:response) { service.send_state(:success, 'a message', {}, [:success, :failure]) }
32
+
33
+ it 'has a success state' do
34
+ expect(response.state).to eq :success
35
+ end
36
+
37
+ it 'has the message "a message"' do
38
+ expect(response.message).to eq 'a message'
39
+ end
40
+
41
+ it 'has the context {}' do
42
+ expect(response.context).to eq Hash.new
43
+ end
44
+
45
+ it 'has valid_states [:success, :failure]' do
46
+ expect(response.valid_states).to eq [:success, :failure]
47
+ end
48
+ end
49
+
50
+ context 'given :success, "a message", {}' do
51
+ let(:response) { service.send_state(:success, 'a message', {}) }
52
+
53
+ it 'has a success state' do
54
+ expect(response.state).to eq :success
55
+ end
56
+
57
+ it 'has the message "a message"' do
58
+ expect(response.message).to eq 'a message'
59
+ end
60
+
61
+ it 'has the context {}' do
62
+ expect(response.context).to eq Hash.new
63
+ end
64
+
65
+ it 'has valid_states nil' do
66
+ expect(response.valid_states).to eq []
67
+ end
68
+ end
69
+
70
+ context 'given :success, "a message"' do
71
+ let(:response) { service.send_state(:success, 'a message') }
72
+
73
+ it 'has a success state' do
74
+ expect(response.state).to eq :success
75
+ end
76
+
77
+ it 'has the message "a message"' do
78
+ expect(response.message).to eq 'a message'
79
+ end
80
+
81
+ it 'has the context nil' do
82
+ expect(response.context).to be_nil
83
+ end
84
+
85
+ it 'has valid_states nil' do
86
+ expect(response.valid_states).to eq []
87
+ end
88
+ end
89
+
90
+ context 'given :success' do
91
+ let(:response) { service.send_state(:success) }
92
+
93
+ it 'has a success state' do
94
+ expect(response.state).to eq :success
95
+ end
96
+
97
+ it 'has the message nil' do
98
+ expect(response.message).to be_nil
99
+ end
100
+
101
+ it 'has the context nil' do
102
+ expect(response.context).to be_nil
103
+ end
104
+
105
+ it 'has valid_states nil' do
106
+ expect(response.valid_states).to eq []
107
+ end
108
+ end
109
+ end
28
110
  end
29
111
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: response_state
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - alexpeachey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-16 00:00:00.000000000 Z
11
+ date: 2014-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler