riveter 0.0.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 +7 -0
- data/.gitignore +15 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +17 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +147 -0
- data/LICENSE.txt +23 -0
- data/README.md +77 -0
- data/Rakefile +7 -0
- data/app/helpers/riveter/command_form_helper.rb +15 -0
- data/app/helpers/riveter/enquiry_form_helper.rb +16 -0
- data/app/helpers/riveter/query_filter_form_helper.rb +16 -0
- data/config/locales/forms.en.yml +25 -0
- data/config/locales/validators.en.yml +26 -0
- data/init.rb +25 -0
- data/lib/generators/erb/TODO +1 -0
- data/lib/generators/haml/command_controller/USAGE +0 -0
- data/lib/generators/haml/command_controller/command_controller_generator.rb +56 -0
- data/lib/generators/haml/command_controller/templates/new.html.haml +26 -0
- data/lib/generators/haml/enquiry_controller/USAGE +0 -0
- data/lib/generators/haml/enquiry_controller/enquiry_controller_generator.rb +56 -0
- data/lib/generators/haml/enquiry_controller/templates/index.html.haml +57 -0
- data/lib/generators/riveter/command/USAGE +0 -0
- data/lib/generators/riveter/command/command_generator.rb +55 -0
- data/lib/generators/riveter/command/templates/command.rb +40 -0
- data/lib/generators/riveter/command/templates/commands.en.yml +57 -0
- data/lib/generators/riveter/command/templates/module.rb +4 -0
- data/lib/generators/riveter/command_controller/USAGE +0 -0
- data/lib/generators/riveter/command_controller/command_controller_generator.rb +40 -0
- data/lib/generators/riveter/command_controller/templates/command_controller.rb +18 -0
- data/lib/generators/riveter/command_controller/templates/module.rb +4 -0
- data/lib/generators/riveter/enquiry/USAGE +0 -0
- data/lib/generators/riveter/enquiry/enquiry_generator.rb +29 -0
- data/lib/generators/riveter/enquiry/templates/enquiry.rb +11 -0
- data/lib/generators/riveter/enquiry/templates/module.rb +4 -0
- data/lib/generators/riveter/enquiry_controller/USAGE +0 -0
- data/lib/generators/riveter/enquiry_controller/enquiry_controller_generator.rb +34 -0
- data/lib/generators/riveter/enquiry_controller/templates/enquiry_controller.rb +9 -0
- data/lib/generators/riveter/enquiry_controller/templates/module.rb +4 -0
- data/lib/generators/riveter/enum/USAGE +41 -0
- data/lib/generators/riveter/enum/enum_generator.rb +51 -0
- data/lib/generators/riveter/enum/templates/enum.rb +17 -0
- data/lib/generators/riveter/enum/templates/enums.en.yml +35 -0
- data/lib/generators/riveter/enum/templates/module.rb +4 -0
- data/lib/generators/riveter/install/USAGE +0 -0
- data/lib/generators/riveter/install/install_generator.rb +14 -0
- data/lib/generators/riveter/presenter/USAGE +0 -0
- data/lib/generators/riveter/presenter/presenter_generator.rb +20 -0
- data/lib/generators/riveter/presenter/templates/module.rb +4 -0
- data/lib/generators/riveter/presenter/templates/presenter.rb +7 -0
- data/lib/generators/riveter/query/USAGE +22 -0
- data/lib/generators/riveter/query/query_generator.rb +20 -0
- data/lib/generators/riveter/query/templates/module.rb +4 -0
- data/lib/generators/riveter/query/templates/query.rb +31 -0
- data/lib/generators/riveter/query_filter/USAGE +0 -0
- data/lib/generators/riveter/query_filter/query_filter_generator.rb +52 -0
- data/lib/generators/riveter/query_filter/templates/module.rb +4 -0
- data/lib/generators/riveter/query_filter/templates/query_filter.rb +40 -0
- data/lib/generators/riveter/query_filter/templates/query_filters.en.yml +49 -0
- data/lib/generators/riveter/service/USAGE +0 -0
- data/lib/generators/riveter/service/service_generator.rb +20 -0
- data/lib/generators/riveter/service/templates/module.rb +4 -0
- data/lib/generators/riveter/service/templates/service.rb +12 -0
- data/lib/generators/riveter/worker/USAGE +0 -0
- data/lib/generators/riveter/worker/templates/module.rb +4 -0
- data/lib/generators/riveter/worker/templates/worker.rb +7 -0
- data/lib/generators/riveter/worker/worker_generator.rb +20 -0
- data/lib/generators/rspec/command/USAGE +0 -0
- data/lib/generators/rspec/command/command_generator.rb +11 -0
- data/lib/generators/rspec/command/templates/command_spec.rb +8 -0
- data/lib/generators/rspec/command_controller/USAGE +0 -0
- data/lib/generators/rspec/command_controller/command_controller_generator.rb +21 -0
- data/lib/generators/rspec/command_controller/templates/command_controller_spec.rb +70 -0
- data/lib/generators/rspec/enquiry/USAGE +0 -0
- data/lib/generators/rspec/enquiry/enquiry_generator.rb +11 -0
- data/lib/generators/rspec/enquiry/templates/enquiry_spec.rb +69 -0
- data/lib/generators/rspec/enquiry_controller/USAGE +0 -0
- data/lib/generators/rspec/enquiry_controller/enquiry_controller_generator.rb +16 -0
- data/lib/generators/rspec/enquiry_controller/templates/enquiry_controller_spec.rb +32 -0
- data/lib/generators/rspec/enum/USAGE +0 -0
- data/lib/generators/rspec/enum/enum_generator.rb +11 -0
- data/lib/generators/rspec/enum/templates/enum_spec.rb +8 -0
- data/lib/generators/rspec/presenter/USAGE +0 -0
- data/lib/generators/rspec/presenter/presenter_generator.rb +11 -0
- data/lib/generators/rspec/presenter/templates/presenter_spec.rb +8 -0
- data/lib/generators/rspec/query/USAGE +0 -0
- data/lib/generators/rspec/query/query_generator.rb +11 -0
- data/lib/generators/rspec/query/templates/query_spec.rb +41 -0
- data/lib/generators/rspec/query_filter/USAGE +0 -0
- data/lib/generators/rspec/query_filter/query_filter_generator.rb +11 -0
- data/lib/generators/rspec/query_filter/templates/query_filter_spec.rb +8 -0
- data/lib/generators/rspec/service/USAGE +0 -0
- data/lib/generators/rspec/service/service_generator.rb +11 -0
- data/lib/generators/rspec/service/templates/service_spec.rb +8 -0
- data/lib/generators/rspec/worker/USAGE +0 -0
- data/lib/generators/rspec/worker/templates/worker_spec.rb +8 -0
- data/lib/generators/rspec/worker/worker_generator.rb +11 -0
- data/lib/generators/test_unit/TODO +1 -0
- data/lib/riveter/associated_type_registry.rb +63 -0
- data/lib/riveter/attribute_default_values.rb +67 -0
- data/lib/riveter/attributes.rb +443 -0
- data/lib/riveter/booleaness_validator.rb +20 -0
- data/lib/riveter/command.rb +59 -0
- data/lib/riveter/command_controller.rb +93 -0
- data/lib/riveter/command_routes.rb +73 -0
- data/lib/riveter/core_extensions.rb +246 -0
- data/lib/riveter/email_validator.rb +20 -0
- data/lib/riveter/enquiry.rb +137 -0
- data/lib/riveter/enquiry_controller.rb +80 -0
- data/lib/riveter/enquiry_routes.rb +69 -0
- data/lib/riveter/enumerated.rb +107 -0
- data/lib/riveter/errors.rb +11 -0
- data/lib/riveter/form_builder_extensions.rb +21 -0
- data/lib/riveter/hash_with_dependency.rb +12 -0
- data/lib/riveter/presenter.rb +73 -0
- data/lib/riveter/query.rb +45 -0
- data/lib/riveter/query_filter.rb +22 -0
- data/lib/riveter/rails/engine.rb +6 -0
- data/lib/riveter/rails/railtie.rb +50 -0
- data/lib/riveter/service.rb +45 -0
- data/lib/riveter/spec_helper.rb +55 -0
- data/lib/riveter/tasks/.keep +0 -0
- data/lib/riveter/version.rb +3 -0
- data/lib/riveter/worker.rb +20 -0
- data/lib/riveter.rb +47 -0
- data/riveter.gemspec +40 -0
- data/spec/examples/attribute_examples.rb +57 -0
- data/spec/generators/haml/command_controller/command_controller_generator_spec.rb +34 -0
- data/spec/generators/haml/enquiry_controller/enquiry_controller_generator_spec.rb +34 -0
- data/spec/generators/riveter/command/command_generator_spec.rb +58 -0
- data/spec/generators/riveter/command_controller/command_controller_generator_spec.rb +0 -0
- data/spec/generators/riveter/enquiry/enquiry_generator_spec.rb +0 -0
- data/spec/generators/riveter/query_filter/query_filter_generator_spec.rb +58 -0
- data/spec/riveter/associated_type_registry_spec.rb +158 -0
- data/spec/riveter/attribute_default_value_spec.rb +69 -0
- data/spec/riveter/attributes_spec.rb +228 -0
- data/spec/riveter/command_controller_spec.rb +116 -0
- data/spec/riveter/command_routes_spec.rb +116 -0
- data/spec/riveter/command_spec.rb +66 -0
- data/spec/riveter/core_extensions_spec.rb +209 -0
- data/spec/riveter/enquiry_controller_spec.rb +128 -0
- data/spec/riveter/enquiry_routes_spec.rb +101 -0
- data/spec/riveter/enquiry_spec.rb +299 -0
- data/spec/riveter/enumerated_spec.rb +47 -0
- data/spec/riveter/form_builder_extensions_spec.rb +28 -0
- data/spec/riveter/presenter_spec.rb +131 -0
- data/spec/riveter/query_filter_spec.rb +19 -0
- data/spec/riveter/query_spec.rb +72 -0
- data/spec/riveter/service_spec.rb +49 -0
- data/spec/riveter/spec_helper_spec.rb +21 -0
- data/spec/riveter/worker_spec.rb +11 -0
- data/spec/spec_helper.rb +54 -0
- data/spec/support/test_associated_class.rb +2 -0
- data/spec/support/test_class_with_attributes.rb +17 -0
- data/spec/support/test_command.rb +4 -0
- data/spec/support/test_command_controller.rb +12 -0
- data/spec/support/test_command_routes.rb +3 -0
- data/spec/support/test_enquiry.rb +7 -0
- data/spec/support/test_enquiry_controller.rb +12 -0
- data/spec/support/test_enquiry_routes.rb +3 -0
- data/spec/support/test_enum.rb +8 -0
- data/spec/support/test_form_builder.rb +3 -0
- data/spec/support/test_model.rb +2 -0
- data/spec/support/test_model_with_attribute_default_values.rb +29 -0
- data/spec/support/test_presenter.rb +2 -0
- data/spec/support/test_query.rb +5 -0
- data/spec/support/test_query_filter.rb +4 -0
- data/spec/support/test_service.rb +7 -0
- data/spec/support/validate_booleaness_of_matcher.rb +17 -0
- data/spec/support/validate_timeliness_of_matcher.rb +17 -0
- data/spec/support/validator_detector.rb +48 -0
- metadata +487 -0
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Riveter::Enquiry do
|
|
4
|
+
describe "class" do
|
|
5
|
+
subject { TestEnquiry }
|
|
6
|
+
|
|
7
|
+
describe ".enquiry_name" do
|
|
8
|
+
it { should respond_to(:enquiry_name) }
|
|
9
|
+
it { subject.enquiry_name.should be_a(ActiveModel::Name) }
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe ".i18n_scope" do
|
|
13
|
+
it { should respond_to(:i18n_scope) }
|
|
14
|
+
it { subject.i18n_scope.should eq(:enquiries) }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe ".filter_with" do
|
|
18
|
+
subject {
|
|
19
|
+
Class.new(Riveter::Enquiry::Base).instance_eval do
|
|
20
|
+
def enquiry_name
|
|
21
|
+
ActiveModel::Name.new(self, nil, 'TestEnquiry')
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
self
|
|
25
|
+
end
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
it { should respond_to(:filter_with) }
|
|
29
|
+
|
|
30
|
+
describe "called without a class or block" do
|
|
31
|
+
it "raise an error" do
|
|
32
|
+
expect {
|
|
33
|
+
subject.filter_with
|
|
34
|
+
}.to raise_error(ArgumentError)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe "called with a class" do
|
|
39
|
+
it {
|
|
40
|
+
klass = Class.new(Riveter::QueryFilter::Base)
|
|
41
|
+
subject.filter_with(klass)
|
|
42
|
+
subject.query_with {}
|
|
43
|
+
subject.new().query_filter_class.should eq(klass)
|
|
44
|
+
}
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
describe "called with a block" do
|
|
48
|
+
it "invokes the block" do
|
|
49
|
+
block = Mock::Block.new()
|
|
50
|
+
expect(block).to receive(:call).at_least(:once)
|
|
51
|
+
subject.filter_with do
|
|
52
|
+
block.call
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "creates an anonymous class" do
|
|
57
|
+
block = Mock::Block.new()
|
|
58
|
+
allow(block).to receive(:call)
|
|
59
|
+
|
|
60
|
+
subject.filter_with do
|
|
61
|
+
block.call
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
subject.query_with {}
|
|
65
|
+
|
|
66
|
+
subject.new().query_filter.should be_a_kind_of(Riveter::QueryFilter::Base)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "adds a .model_name method" do
|
|
70
|
+
subject.filter_with {}
|
|
71
|
+
|
|
72
|
+
# for forms support
|
|
73
|
+
subject.query_filter_class.should respond_to(:model_name)
|
|
74
|
+
subject.query_filter_class.model_name.should eq(subject.enquiry_name)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
describe ".query_filter_class" do
|
|
80
|
+
it { should respond_to(:query_filter_class) }
|
|
81
|
+
it { subject.query_filter_class.should eq(TestQueryFilter) }
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
describe ".query_filter_attributes" do
|
|
85
|
+
it { should respond_to(:query_filter_attributes) }
|
|
86
|
+
it { subject.query_filter_attributes.should eq(TestQueryFilter.attributes) }
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
describe ".query_with" do
|
|
90
|
+
subject {
|
|
91
|
+
Class.new(Riveter::Enquiry::Base).instance_eval do
|
|
92
|
+
def enquiry_name
|
|
93
|
+
ActiveModel::Name.new(self, nil, 'TestEnquiry')
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
filter_with {}
|
|
97
|
+
|
|
98
|
+
self
|
|
99
|
+
end
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
it { should respond_to(:query_with) }
|
|
103
|
+
|
|
104
|
+
describe "called without a class or block" do
|
|
105
|
+
it "raise an error" do
|
|
106
|
+
expect {
|
|
107
|
+
subject.query_with
|
|
108
|
+
}.to raise_error(ArgumentError)
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
describe "called with a class" do
|
|
113
|
+
it {
|
|
114
|
+
klass = Class.new(Riveter::Query::Base)
|
|
115
|
+
subject.query_with(klass)
|
|
116
|
+
subject.new().query_class.should eq(klass)
|
|
117
|
+
}
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
describe "called with a block" do
|
|
121
|
+
it "invokes the block" do
|
|
122
|
+
block = Mock::Block.new()
|
|
123
|
+
allow(subject).to receive(:create_query_filter) { OpenStruct.new(:valid? => true) }
|
|
124
|
+
|
|
125
|
+
expect(block).to receive(:call).at_least(:once)
|
|
126
|
+
|
|
127
|
+
subject.query_with do |filter|
|
|
128
|
+
block.call
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
subject.new().submit()
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it "creates an anonymous class" do
|
|
135
|
+
block = Mock::Block.new()
|
|
136
|
+
allow(block).to receive(:call)
|
|
137
|
+
|
|
138
|
+
subject.query_with do |filter|
|
|
139
|
+
block.call
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
subject.new().query_class.new(:query_filter).should be_a_kind_of(Riveter::Query::Base)
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
describe ".query_class" do
|
|
148
|
+
it { should respond_to(:query_class) }
|
|
149
|
+
it { subject.query_class.should eq(TestQuery) }
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
describe "instance" do
|
|
154
|
+
context "with incorrectly configured" do
|
|
155
|
+
it "fails when no filter or query set" do
|
|
156
|
+
expect {
|
|
157
|
+
Class.new(Riveter::Enquiry::Base).new()
|
|
158
|
+
}.to raise_error
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
it "fails when no query set" do
|
|
162
|
+
expect {
|
|
163
|
+
Class.new(Riveter::Enquiry::Base).tap {|klass|
|
|
164
|
+
klass.filter_with TestQueryFilter
|
|
165
|
+
}.new()
|
|
166
|
+
}.to raise_error
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
it "fails when no filter set" do
|
|
170
|
+
expect {
|
|
171
|
+
Class.new(Riveter::Enquiry::Base).tap {|klass|
|
|
172
|
+
klass.query_with TestQuery
|
|
173
|
+
}.new()
|
|
174
|
+
}.to raise_error
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
context "with correctly configured" do
|
|
179
|
+
subject { TestEnquiry.new() }
|
|
180
|
+
|
|
181
|
+
describe "#query_filter_class" do
|
|
182
|
+
it { subject.query_filter_class.should eq(TestQueryFilter) }
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
describe "#query_class" do
|
|
186
|
+
it { subject.query_class.should eq(TestQuery) }
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
describe "#query_filter" do
|
|
190
|
+
it { should respond_to(:filter) }
|
|
191
|
+
it { subject.query_filter.should be_a(TestQueryFilter)}
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
describe "#query_filter_attributes" do
|
|
195
|
+
it { subject.query_filter_attributes.should eq(TestQueryFilter.attributes)}
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
describe "#submit" do
|
|
199
|
+
it "yields the query for a valid filter" do
|
|
200
|
+
query = Object.new()
|
|
201
|
+
expect(subject).to receive(:create_query_filter) { OpenStruct.new(:valid? => true) }
|
|
202
|
+
expect(subject).to receive(:create_query) { query }
|
|
203
|
+
subject.submit().should eq(query)
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
it "yields false for an invalid filter" do
|
|
207
|
+
expect(subject).to receive(:create_query_filter) { OpenStruct.new(:valid? => false) }
|
|
208
|
+
subject.submit().should eq(false)
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
it "assigns query" do
|
|
212
|
+
query = Object.new()
|
|
213
|
+
expect(subject).to receive(:create_query_filter) { OpenStruct.new(:valid? => true) }
|
|
214
|
+
expect(subject).to receive(:create_query) { query }
|
|
215
|
+
subject.submit()
|
|
216
|
+
subject.query.should eq(query)
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
describe "#query" do
|
|
221
|
+
it { should respond_to(:query) }
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
describe "#find_each" do
|
|
225
|
+
it "invokes the given block when data" do
|
|
226
|
+
allow(subject).to receive(:query) { [1] }
|
|
227
|
+
block = Mock::Block.new()
|
|
228
|
+
expect(block).to receive(:call).at_least(:once)
|
|
229
|
+
subject.find_each(&block)
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
it "does not invoke the given block when query nil" do
|
|
233
|
+
allow(subject).to receive(:query) { nil }
|
|
234
|
+
block = Mock::Block.new()
|
|
235
|
+
expect(block).to_not receive(:call)
|
|
236
|
+
subject.find_each(&block)
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
it "does not invoke the given block when no data" do
|
|
240
|
+
allow(subject).to receive(:query) { [] }
|
|
241
|
+
block = Mock::Block.new()
|
|
242
|
+
expect(block).to_not receive(:call)
|
|
243
|
+
subject.find_each(&block)
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
describe "#has_data?" do
|
|
248
|
+
it "yields false when query nil" do
|
|
249
|
+
allow(subject).to receive(:query) { nil }
|
|
250
|
+
subject.has_data?.should be_false
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
it "yields false when query empty" do
|
|
254
|
+
allow(subject).to receive(:query) { OpenStruct.new(:has_data? => false) }
|
|
255
|
+
subject.has_data?.should be_false
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
it "yields true when query data" do
|
|
259
|
+
allow(subject).to receive(:query) { OpenStruct.new(:has_data? => true) }
|
|
260
|
+
subject.has_data?.should be_true
|
|
261
|
+
end
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
describe "#query_results" do
|
|
265
|
+
it { should respond_to(:query_results) }
|
|
266
|
+
|
|
267
|
+
it "yield false when invalid query" do
|
|
268
|
+
subject.query_results.should be_nil
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
it "yield query relation for a valid query" do
|
|
272
|
+
allow(subject).to receive(:query) { OpenStruct.new(:has_data? => true, :relation => []) }
|
|
273
|
+
|
|
274
|
+
subject.query_results.should eq([])
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
describe "#create_query_filter" do
|
|
279
|
+
it "should create an instance" do
|
|
280
|
+
subject.send(:create_query_filter, {}).should be_a(TestQueryFilter)
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
it "should assign params" do
|
|
284
|
+
subject.send(:create_query_filter, {:name => 'test'}).name.should eq('test')
|
|
285
|
+
end
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
describe "#create_query" do
|
|
289
|
+
it "should create an instance" do
|
|
290
|
+
subject.send(:create_query, {}).should be_a(TestQuery)
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
it "should assign filter" do
|
|
294
|
+
subject.send(:create_query, 'test').query_filter.should eq('test')
|
|
295
|
+
end
|
|
296
|
+
end
|
|
297
|
+
end
|
|
298
|
+
end
|
|
299
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Riveter::Enumerated do
|
|
4
|
+
subject { TestEnum }
|
|
5
|
+
|
|
6
|
+
describe "#human" do
|
|
7
|
+
it {
|
|
8
|
+
subject.human.should be_present
|
|
9
|
+
}
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe "#names" do
|
|
13
|
+
it { subject.names.should eq(%i{Member1 Member2}) }
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe "#all" do
|
|
17
|
+
it { subject.all.should eq([1, 2]) }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe "#name_for" do
|
|
21
|
+
it { subject.name_for(1).should be_present }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe "#human_name_for" do
|
|
25
|
+
it { subject.name_for(1).should be_present }
|
|
26
|
+
it { subject.name_for(1).should eq(:Member1) }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe "#value_for" do
|
|
30
|
+
it { subject.value_for('Member1').should eq(1) }
|
|
31
|
+
it { subject.value_for(:Member1).should eq(1) }
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe "#collection" do
|
|
35
|
+
it { subject.collection.should be_present }
|
|
36
|
+
it { subject.collection.length.should eq(2) }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe "::All" do
|
|
40
|
+
it { subject::All.should be_present }
|
|
41
|
+
it { subject::All.length.should eq(2) }
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# TODO: scenario for a member value of nil
|
|
45
|
+
# TODO: scenario for a member value of a Class
|
|
46
|
+
|
|
47
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'riveter/form_builder_extensions'
|
|
3
|
+
|
|
4
|
+
describe Riveter::FormBuilderExtensions do
|
|
5
|
+
describe "instance" do
|
|
6
|
+
subject { TestFormBuilder.new }
|
|
7
|
+
|
|
8
|
+
describe "#search" do
|
|
9
|
+
it { should respond_to(:search) }
|
|
10
|
+
|
|
11
|
+
it "should render a submit HTML element" do
|
|
12
|
+
expect(subject).to receive(:submit)
|
|
13
|
+
|
|
14
|
+
subject.search
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe "#reset" do
|
|
19
|
+
it { should respond_to(:reset) }
|
|
20
|
+
|
|
21
|
+
it "should render a submit HTML element" do
|
|
22
|
+
expect(subject).to receive(:submit)
|
|
23
|
+
|
|
24
|
+
subject.reset
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Riveter::Presenter do
|
|
4
|
+
describe "#to_presenter" do
|
|
5
|
+
subject { Object.new() }
|
|
6
|
+
|
|
7
|
+
it { should respond_to(:to_presenter) }
|
|
8
|
+
|
|
9
|
+
it {
|
|
10
|
+
expect {
|
|
11
|
+
subject.to_presenter(nil)
|
|
12
|
+
}.to raise_error(ArgumentError)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
it {
|
|
16
|
+
expect {
|
|
17
|
+
subject.to_presenter(Object)
|
|
18
|
+
}.to raise_error(ArgumentError)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
it { subject.to_presenter(TestPresenter).should_not be_nil }
|
|
22
|
+
it { subject.to_presenter(TestPresenter).should be_instance_of(TestPresenter) }
|
|
23
|
+
|
|
24
|
+
it { OpenStruct.new(:name => :test).to_presenter(TestPresenter).should respond_to(:name) }
|
|
25
|
+
it { OpenStruct.new(:name => :test).to_presenter(TestPresenter).name.should eq(:test) }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe "#with_presenter" do
|
|
29
|
+
subject { [1, 2, 3].each }
|
|
30
|
+
|
|
31
|
+
it { should respond_to(:with_presenter) }
|
|
32
|
+
|
|
33
|
+
it {
|
|
34
|
+
expect {
|
|
35
|
+
subject.with_presenter(nil)
|
|
36
|
+
}.to raise_error(ArgumentError)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
it {
|
|
40
|
+
expect {
|
|
41
|
+
subject.with_presenter(Object)
|
|
42
|
+
}.to raise_error(ArgumentError)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
it { subject.with_presenter(TestPresenter).should_not be_nil }
|
|
46
|
+
|
|
47
|
+
it "should yield to block for each item" do
|
|
48
|
+
block = Mock::Block.new()
|
|
49
|
+
expect(block).to receive(:call).exactly(subject.count).times
|
|
50
|
+
subject.with_presenter(TestPresenter, &block)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "should yield to block with the presenter for each item" do
|
|
54
|
+
subject.with_presenter(TestPresenter) do |item|
|
|
55
|
+
item.should be_instance_of(TestPresenter)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "should return enumerator if no block given" do
|
|
60
|
+
block = Mock::Block.new()
|
|
61
|
+
expect(block).to receive(:call).exactly(subject.count).times
|
|
62
|
+
subject.with_presenter(TestPresenter).each(&block)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
describe "instance" do
|
|
67
|
+
describe "#item" do
|
|
68
|
+
subject { TestPresenter.new(:item) }
|
|
69
|
+
it { should respond_to(:item) }
|
|
70
|
+
it { subject.item.should eq(:item) }
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
describe "#method_missing" do
|
|
74
|
+
let!(:item) {
|
|
75
|
+
Class.new().class_eval do
|
|
76
|
+
def some_method
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
self
|
|
80
|
+
end.new()
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
describe "methods on item" do
|
|
84
|
+
subject { TestPresenter.new(item) }
|
|
85
|
+
|
|
86
|
+
it "respond_to? yields true" do
|
|
87
|
+
should respond_to(:some_method)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it "delegates to item" do
|
|
91
|
+
expect(item).to receive(:some_method)
|
|
92
|
+
subject.some_method
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
describe "methods on view" do
|
|
97
|
+
let!(:view) {
|
|
98
|
+
Class.new().class_eval do
|
|
99
|
+
def some_other_method
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
self
|
|
103
|
+
end.new()
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
subject { TestPresenter.new(item, view) }
|
|
107
|
+
|
|
108
|
+
it "respond_to? yields true" do
|
|
109
|
+
should respond_to(:some_other_method)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it "delegates to item" do
|
|
113
|
+
expect(item).to receive(:some_method)
|
|
114
|
+
subject.some_method
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it "delegates to view" do
|
|
118
|
+
expect(view).to receive(:some_other_method)
|
|
119
|
+
|
|
120
|
+
subject.some_other_method
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it "raise error if no method" do
|
|
124
|
+
expect {
|
|
125
|
+
subject.non_existent_method
|
|
126
|
+
}.to raise_error
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Riveter::QueryFilter do
|
|
4
|
+
it_should_behave_like "a class with attributes", TestQueryFilter
|
|
5
|
+
|
|
6
|
+
describe "class" do
|
|
7
|
+
subject { TestQueryFilter }
|
|
8
|
+
|
|
9
|
+
describe ".filter_name" do
|
|
10
|
+
it { should respond_to(:filter_name) }
|
|
11
|
+
it { subject.filter_name.should be_a(ActiveModel::Name) }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe ".i18n_scope" do
|
|
15
|
+
it { should respond_to(:i18n_scope) }
|
|
16
|
+
it { subject.i18n_scope.should eq(:query_filters) }
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'riveter/spec_helper'
|
|
3
|
+
|
|
4
|
+
describe Riveter::Query do
|
|
5
|
+
describe "#initialize" do
|
|
6
|
+
it "should call #build_relation" do
|
|
7
|
+
expect_any_instance_of(TestQuery).to receive(:build_relation).with(:filter)
|
|
8
|
+
TestQuery.new(:filter)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "should assign the filter" do
|
|
12
|
+
TestQuery.new(:filter).query_filter.should eq(:filter)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should assign the options" do
|
|
16
|
+
TestQuery.new(:filter, :key => :value).options.should eq({:key => :value})
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "should assign the relation" do
|
|
20
|
+
query = TestQuery.new(nil)
|
|
21
|
+
query.relation.should eq(query.build_relation(:filter))
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe "#build_relation" do
|
|
26
|
+
it "should raise NotImplementedError if not implemented" do
|
|
27
|
+
klass = Class.new(Riveter::Query::Base)
|
|
28
|
+
expect {
|
|
29
|
+
klass.new(:filter)
|
|
30
|
+
}.to raise_error(NotImplementedError)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe "#find_each" do
|
|
35
|
+
it "should enumerate relation" do
|
|
36
|
+
# Note: Array implements `find_each_with_order`
|
|
37
|
+
allow_any_instance_of(TestQuery).to receive(:build_relation) { [1] }
|
|
38
|
+
query = TestQuery.new(nil)
|
|
39
|
+
expect(query.relation).to receive(:find_each_with_order)
|
|
40
|
+
query.find_each {}
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "should invoke block" do
|
|
44
|
+
block = Mock::Block.new()
|
|
45
|
+
expect(block).to receive(:call).at_least(:once)
|
|
46
|
+
|
|
47
|
+
fake_relation = [1]
|
|
48
|
+
allow(fake_relation).to receive(:find_each_with_order) do |*args, &block|
|
|
49
|
+
block.call(*args)
|
|
50
|
+
end
|
|
51
|
+
allow_any_instance_of(TestQuery).to receive(:relation) { fake_relation }
|
|
52
|
+
|
|
53
|
+
query = TestQuery.new(nil)
|
|
54
|
+
query.find_each &block
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
describe "#has_data?" do
|
|
59
|
+
it "should yield true when data available" do
|
|
60
|
+
allow_any_instance_of(TestQuery).to receive(:relation) { [1] }
|
|
61
|
+
query = TestQuery.new(nil)
|
|
62
|
+
query.has_data?.should be_true
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "should yield false when no data available" do
|
|
66
|
+
allow_any_instance_of(TestQuery).to receive(:relation) { [] }
|
|
67
|
+
query = TestQuery.new(nil)
|
|
68
|
+
query.has_data?.should be_false
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Riveter::Service do
|
|
4
|
+
describe "class" do
|
|
5
|
+
subject { TestService }
|
|
6
|
+
|
|
7
|
+
it "automatically registers as handler for TestCommand" do
|
|
8
|
+
Riveter::Service::Base.resolve(:test_command).should eq(subject)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe ".register_as_handler_for" do
|
|
12
|
+
let(:command_class) { TestCommand }
|
|
13
|
+
|
|
14
|
+
it { should respond_to(:register_as_handler_for) }
|
|
15
|
+
|
|
16
|
+
it "registers as handler for given command" do
|
|
17
|
+
expect(subject).to receive(:register_type).with(subject, command_class)
|
|
18
|
+
subject.register_as_handler_for(command_class)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "allows for more than one registration" do
|
|
22
|
+
my_test_command_class = Class.new(Riveter::Command::Base)
|
|
23
|
+
allow(my_test_command_class).to receive(:name) { 'MyTestCommand' } # anonymous classes need a name!
|
|
24
|
+
|
|
25
|
+
TestService.register_as_handler_for my_test_command_class
|
|
26
|
+
Riveter::Service::Base.resolve(:my_test_command).should eq(subject)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe "instance" do
|
|
32
|
+
subject { TestService.new() }
|
|
33
|
+
|
|
34
|
+
describe "#perform" do
|
|
35
|
+
it { should respond_to(:perform) }
|
|
36
|
+
|
|
37
|
+
it "should raise NotImplementedError if not implemented" do
|
|
38
|
+
expect {
|
|
39
|
+
subject.perform(nil)
|
|
40
|
+
}.to raise_error(NotImplementedError)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "should invoke" do
|
|
44
|
+
expect(subject).to receive(:perform) { true }
|
|
45
|
+
subject.perform(TestCommand.new()).should be_true
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'riveter/spec_helper'
|
|
3
|
+
|
|
4
|
+
describe "Spec Helper" do
|
|
5
|
+
describe Mock::Block do
|
|
6
|
+
it "yields a proc object" do
|
|
7
|
+
Mock::Block.new().to_proc.should be_a(Proc)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "the proc invokes the call method" do
|
|
11
|
+
expect_any_instance_of(Mock::Block).to receive(:call).at_least(:once)
|
|
12
|
+
Mock::Block.new().to_proc.call
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "default call method raises an error" do
|
|
16
|
+
expect {
|
|
17
|
+
Mock::Block.new().call
|
|
18
|
+
}.to raise_error(NotImplementedError)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|