gexp 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/docs/commands_handling.mdoc +72 -0
- data/docs/notes.mdoc +19 -0
- data/gexp.gemspec +1 -0
- data/lib/examples/item_example.rb +32 -52
- data/lib/examples/user_example.rb +7 -3
- data/lib/gexp/command.rb +17 -1
- data/lib/gexp/command/object.rb +20 -5
- data/lib/gexp/command/stack.rb +15 -1
- data/lib/gexp/handler.rb +8 -8
- data/lib/gexp/handler/modify/resources.rb +1 -0
- data/lib/gexp/handler/producer.rb +31 -17
- data/lib/gexp/handler/transition.rb +39 -11
- data/lib/gexp/handler/transition/builder.rb +33 -7
- data/lib/gexp/item.rb +73 -0
- data/lib/gexp/object.rb +8 -0
- data/lib/gexp/receiver/example.rb +2 -2
- data/lib/gexp/receiver/mongoid.rb +3 -3
- data/lib/gexp/state_definition/state_machine.rb +8 -6
- data/lib/gexp/user.rb +9 -0
- data/lib/gexp/version.rb +1 -1
- data/spec/gexp/command/object_spec.rb +73 -26
- data/spec/gexp/handler/transition/builder_spec.rb +42 -48
- data/spec/gexp/item_spec.rb +65 -0
- data/spec/gexp/receiver_spec.rb +7 -2
- data/spec/gexp/state_definition/state_machine_spec.rb +11 -1
- data/spec/mongoid.yml +19 -0
- data/spec/spec_helper.rb +3 -0
- metadata +47 -28
@@ -0,0 +1,65 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
|
3
|
+
|
4
|
+
describe Gexp::Item do
|
5
|
+
|
6
|
+
let(:subject) { ItemExample.new }
|
7
|
+
let(:receiver_class) { Gexp::Receiver::Example }
|
8
|
+
let(:user) { UserExample.new }
|
9
|
+
let(:request) do
|
10
|
+
HashWithIndifferentAccess.new({
|
11
|
+
:params => {
|
12
|
+
:sended_at => 123456789.012,
|
13
|
+
:create_at => 123456789.012,
|
14
|
+
:commands => [{
|
15
|
+
# У себя на карте
|
16
|
+
:event => :pick,
|
17
|
+
:stage => { x: 100, y: 200 },
|
18
|
+
:rewards => { energy: -1, exp: 5 },
|
19
|
+
:timestamp => 123456789.012,
|
20
|
+
:objects => { 'item_example' => '55a55' },
|
21
|
+
:transition => { :builded => :builded },
|
22
|
+
:seed => 532434234,
|
23
|
+
}]
|
24
|
+
}
|
25
|
+
})
|
26
|
+
end
|
27
|
+
|
28
|
+
let(:receiver) { receiver_class.new(user, request) }
|
29
|
+
|
30
|
+
before do
|
31
|
+
stub(ItemExample).find('55a55') { subject }
|
32
|
+
end
|
33
|
+
|
34
|
+
it { subject.should be_created }
|
35
|
+
|
36
|
+
it "если ресурсы в наличии" do
|
37
|
+
user.energy = 5
|
38
|
+
user.wood = 25
|
39
|
+
receiver.receive
|
40
|
+
subject.reload
|
41
|
+
subject.should be_prebuilded
|
42
|
+
user.energy.should be 5 - 1
|
43
|
+
user.wood.should be 25 - 5
|
44
|
+
end
|
45
|
+
|
46
|
+
it "если нехватает энергии" do
|
47
|
+
user.energy = 0
|
48
|
+
user.wood = 25
|
49
|
+
lambda { receiver.receive }.should raise_error Regexp.new("out_of_resource-energy")
|
50
|
+
subject.reload
|
51
|
+
user.energy.should be 0
|
52
|
+
user.wood.should be 25
|
53
|
+
end
|
54
|
+
|
55
|
+
it "если нехватает дерева" do
|
56
|
+
user.energy = 5
|
57
|
+
user.wood = 4
|
58
|
+
subject.should be_created
|
59
|
+
lambda { receiver.receive }.should raise_error Regexp.new("out_of_resource-wood")
|
60
|
+
subject.reload
|
61
|
+
user.energy.should be 5
|
62
|
+
user.wood.should be 4
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
data/spec/gexp/receiver_spec.rb
CHANGED
@@ -36,10 +36,15 @@ describe Gexp::Receiver do
|
|
36
36
|
|
37
37
|
context "Успешная обработка комманды" do
|
38
38
|
|
39
|
+
before {
|
40
|
+
user.energy = 1
|
41
|
+
user.wood = 5
|
42
|
+
}
|
43
|
+
|
39
44
|
it "должна пройти без ошибок" do
|
40
|
-
|
45
|
+
lambda {
|
41
46
|
subject.receive
|
42
|
-
|
47
|
+
}.should_not raise_error
|
43
48
|
end
|
44
49
|
|
45
50
|
end
|
@@ -12,7 +12,17 @@ describe Gexp::StateDefinition::StateMachine do
|
|
12
12
|
it "should be definition states" do
|
13
13
|
SubjectClass.instance_eval do
|
14
14
|
self.define_state_by({
|
15
|
-
states: {
|
15
|
+
states: {
|
16
|
+
first: {
|
17
|
+
second: []
|
18
|
+
},
|
19
|
+
second: {
|
20
|
+
last: []
|
21
|
+
},
|
22
|
+
last: {
|
23
|
+
last: []
|
24
|
+
}
|
25
|
+
},
|
16
26
|
initial: :created,
|
17
27
|
events: {
|
18
28
|
do_first: [{
|
data/spec/mongoid.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
development:
|
2
|
+
sessions:
|
3
|
+
default:
|
4
|
+
database: gexp_test
|
5
|
+
hosts:
|
6
|
+
- localhost:27017
|
7
|
+
test:
|
8
|
+
sessions:
|
9
|
+
default:
|
10
|
+
database: gexp_test
|
11
|
+
hosts:
|
12
|
+
- localhost:27017
|
13
|
+
production:
|
14
|
+
sessions:
|
15
|
+
default:
|
16
|
+
database: gexp_test
|
17
|
+
hosts:
|
18
|
+
- localhost:27017
|
19
|
+
|
data/spec/spec_helper.rb
CHANGED
@@ -5,6 +5,9 @@ require 'gexp'
|
|
5
5
|
|
6
6
|
ENV["MONGO_URL"] ||= ENV["MONGOHQ_URL"] || "mongodb://localhost/gexp_test"
|
7
7
|
|
8
|
+
require 'mongoid'
|
9
|
+
Mongoid.load!(File.join(File.dirname(__FILE__), 'mongoid.yml'), :test)
|
10
|
+
|
8
11
|
RSpec.configure do |conf|
|
9
12
|
#conf.include Rack::Test::Methods
|
10
13
|
conf.include Mongoid::Matchers
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gexp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70314005552640 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70314005552640
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rr
|
27
|
-
requirement: &
|
27
|
+
requirement: &70314005550780 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70314005550780
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &70314005548680 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70314005548680
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: pry
|
49
|
-
requirement: &
|
49
|
+
requirement: &70314005547940 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,21 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70314005547940
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: configuration
|
60
|
+
requirement: &70314005546240 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70314005546240
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: state_machine
|
60
|
-
requirement: &
|
71
|
+
requirement: &70314005544160 !ruby/object:Gem::Requirement
|
61
72
|
none: false
|
62
73
|
requirements:
|
63
74
|
- - ! '>='
|
@@ -65,10 +76,10 @@ dependencies:
|
|
65
76
|
version: '0'
|
66
77
|
type: :development
|
67
78
|
prerelease: false
|
68
|
-
version_requirements: *
|
79
|
+
version_requirements: *70314005544160
|
69
80
|
- !ruby/object:Gem::Dependency
|
70
81
|
name: activesupport
|
71
|
-
requirement: &
|
82
|
+
requirement: &70314005542280 !ruby/object:Gem::Requirement
|
72
83
|
none: false
|
73
84
|
requirements:
|
74
85
|
- - ! '>='
|
@@ -76,10 +87,10 @@ dependencies:
|
|
76
87
|
version: '0'
|
77
88
|
type: :development
|
78
89
|
prerelease: false
|
79
|
-
version_requirements: *
|
90
|
+
version_requirements: *70314005542280
|
80
91
|
- !ruby/object:Gem::Dependency
|
81
92
|
name: bson
|
82
|
-
requirement: &
|
93
|
+
requirement: &70314005538900 !ruby/object:Gem::Requirement
|
83
94
|
none: false
|
84
95
|
requirements:
|
85
96
|
- - =
|
@@ -87,10 +98,10 @@ dependencies:
|
|
87
98
|
version: 1.8.0
|
88
99
|
type: :development
|
89
100
|
prerelease: false
|
90
|
-
version_requirements: *
|
101
|
+
version_requirements: *70314005538900
|
91
102
|
- !ruby/object:Gem::Dependency
|
92
103
|
name: bson_ext
|
93
|
-
requirement: &
|
104
|
+
requirement: &70314005530240 !ruby/object:Gem::Requirement
|
94
105
|
none: false
|
95
106
|
requirements:
|
96
107
|
- - =
|
@@ -98,10 +109,10 @@ dependencies:
|
|
98
109
|
version: 1.8.0
|
99
110
|
type: :development
|
100
111
|
prerelease: false
|
101
|
-
version_requirements: *
|
112
|
+
version_requirements: *70314005530240
|
102
113
|
- !ruby/object:Gem::Dependency
|
103
114
|
name: mongo
|
104
|
-
requirement: &
|
115
|
+
requirement: &70314005527820 !ruby/object:Gem::Requirement
|
105
116
|
none: false
|
106
117
|
requirements:
|
107
118
|
- - ~>
|
@@ -109,10 +120,10 @@ dependencies:
|
|
109
120
|
version: 1.8.0
|
110
121
|
type: :development
|
111
122
|
prerelease: false
|
112
|
-
version_requirements: *
|
123
|
+
version_requirements: *70314005527820
|
113
124
|
- !ruby/object:Gem::Dependency
|
114
125
|
name: mongoid
|
115
|
-
requirement: &
|
126
|
+
requirement: &70314005526220 !ruby/object:Gem::Requirement
|
116
127
|
none: false
|
117
128
|
requirements:
|
118
129
|
- - ~>
|
@@ -120,10 +131,10 @@ dependencies:
|
|
120
131
|
version: 3.0.0
|
121
132
|
type: :development
|
122
133
|
prerelease: false
|
123
|
-
version_requirements: *
|
134
|
+
version_requirements: *70314005526220
|
124
135
|
- !ruby/object:Gem::Dependency
|
125
136
|
name: money-mongoid
|
126
|
-
requirement: &
|
137
|
+
requirement: &70314005523320 !ruby/object:Gem::Requirement
|
127
138
|
none: false
|
128
139
|
requirements:
|
129
140
|
- - =
|
@@ -131,10 +142,10 @@ dependencies:
|
|
131
142
|
version: 0.1.2
|
132
143
|
type: :development
|
133
144
|
prerelease: false
|
134
|
-
version_requirements: *
|
145
|
+
version_requirements: *70314005523320
|
135
146
|
- !ruby/object:Gem::Dependency
|
136
147
|
name: mongoid-rspec
|
137
|
-
requirement: &
|
148
|
+
requirement: &70314005519640 !ruby/object:Gem::Requirement
|
138
149
|
none: false
|
139
150
|
requirements:
|
140
151
|
- - =
|
@@ -142,7 +153,7 @@ dependencies:
|
|
142
153
|
version: 1.4.5
|
143
154
|
type: :development
|
144
155
|
prerelease: false
|
145
|
-
version_requirements: *
|
156
|
+
version_requirements: *70314005519640
|
146
157
|
description: Gexp - comand hadlers
|
147
158
|
email:
|
148
159
|
- kazantsev.nickolay@gmail.com
|
@@ -155,6 +166,8 @@ files:
|
|
155
166
|
- LICENSE.txt
|
156
167
|
- README.md
|
157
168
|
- Rakefile
|
169
|
+
- docs/commands_handling.mdoc
|
170
|
+
- docs/notes.mdoc
|
158
171
|
- gexp.gemspec
|
159
172
|
- lib/examples/item_example.rb
|
160
173
|
- lib/examples/user_example.rb
|
@@ -172,6 +185,7 @@ files:
|
|
172
185
|
- lib/gexp/handler/producer.rb
|
173
186
|
- lib/gexp/handler/transition.rb
|
174
187
|
- lib/gexp/handler/transition/builder.rb
|
188
|
+
- lib/gexp/item.rb
|
175
189
|
- lib/gexp/mongoid.rb
|
176
190
|
- lib/gexp/mongoid/transaction.rb
|
177
191
|
- lib/gexp/object.rb
|
@@ -180,6 +194,7 @@ files:
|
|
180
194
|
- lib/gexp/receiver/mongoid.rb
|
181
195
|
- lib/gexp/state_definition.rb
|
182
196
|
- lib/gexp/state_definition/state_machine.rb
|
197
|
+
- lib/gexp/user.rb
|
183
198
|
- lib/gexp/version.rb
|
184
199
|
- spec/gexp/command/object_spec.rb
|
185
200
|
- spec/gexp/command/stack_spec.rb
|
@@ -192,9 +207,11 @@ files:
|
|
192
207
|
- spec/gexp/handler/producer_spec.rb
|
193
208
|
- spec/gexp/handler/transition/builder_spec.rb
|
194
209
|
- spec/gexp/handler/transition_spec.rb
|
210
|
+
- spec/gexp/item_spec.rb
|
195
211
|
- spec/gexp/mongoid/transaction_spec.rb
|
196
212
|
- spec/gexp/receiver_spec.rb
|
197
213
|
- spec/gexp/state_definition/state_machine_spec.rb
|
214
|
+
- spec/mongoid.yml
|
198
215
|
- spec/spec_helper.rb
|
199
216
|
homepage: http://github.com/realb0t/gexp
|
200
217
|
licenses: []
|
@@ -210,7 +227,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
210
227
|
version: '0'
|
211
228
|
segments:
|
212
229
|
- 0
|
213
|
-
hash: -
|
230
|
+
hash: -4272846069926930058
|
214
231
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
215
232
|
none: false
|
216
233
|
requirements:
|
@@ -219,7 +236,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
219
236
|
version: '0'
|
220
237
|
segments:
|
221
238
|
- 0
|
222
|
-
hash: -
|
239
|
+
hash: -4272846069926930058
|
223
240
|
requirements: []
|
224
241
|
rubyforge_project: gexp
|
225
242
|
rubygems_version: 1.8.5
|
@@ -238,7 +255,9 @@ test_files:
|
|
238
255
|
- spec/gexp/handler/producer_spec.rb
|
239
256
|
- spec/gexp/handler/transition/builder_spec.rb
|
240
257
|
- spec/gexp/handler/transition_spec.rb
|
258
|
+
- spec/gexp/item_spec.rb
|
241
259
|
- spec/gexp/mongoid/transaction_spec.rb
|
242
260
|
- spec/gexp/receiver_spec.rb
|
243
261
|
- spec/gexp/state_definition/state_machine_spec.rb
|
262
|
+
- spec/mongoid.yml
|
244
263
|
- spec/spec_helper.rb
|