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,209 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'riveter/spec_helper'
|
|
3
|
+
require 'riveter/core_extensions'
|
|
4
|
+
|
|
5
|
+
describe Riveter::CoreExtensions do
|
|
6
|
+
describe Riveter::CoreExtensions::BooleanSupport do
|
|
7
|
+
it { Object.should respond_to(:boolean?) }
|
|
8
|
+
it { Object.should respond_to(:to_b) }
|
|
9
|
+
|
|
10
|
+
it { true.boolean?.should be_true }
|
|
11
|
+
it { false.boolean?.should be_true }
|
|
12
|
+
it { Object.new().boolean?.should be_false }
|
|
13
|
+
|
|
14
|
+
[true, 1, 'yes', 'on', 'y', '1'].each do |value|
|
|
15
|
+
it { value.to_b.should be_true }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
[false, 0, 'no', 'off', 'n', '0'].each do |value|
|
|
19
|
+
it { value.to_b.should be_false }
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe Riveter::CoreExtensions::DateExtensions do
|
|
24
|
+
it { Date.should respond_to(:system_start_date) }
|
|
25
|
+
it { Date.should respond_to(:from_utc_ticks) }
|
|
26
|
+
it { Date.new().should respond_to(:to_utc_ticks) }
|
|
27
|
+
|
|
28
|
+
it { Date.system_start_date.should eq(Date.new(1970, 1, 1)) }
|
|
29
|
+
it { Date.from_utc_ticks(0).should eq(Date.new(1970, 1, 1)) }
|
|
30
|
+
it { Date.from_utc_ticks(86_400_000).should eq(Date.new(1970, 1, 2)) }
|
|
31
|
+
it { Date.new(1970, 1, 1).to_utc_ticks.should eq(0) }
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe Riveter::CoreExtensions::ArrayExtensions do
|
|
35
|
+
subject { [1, 2, 3, 4] }
|
|
36
|
+
|
|
37
|
+
describe "#cumulative_sum" do
|
|
38
|
+
it { should respond_to(:cumulative_sum) }
|
|
39
|
+
|
|
40
|
+
it { subject.cumulative_sum.should eq([1, 3, 6, 10]) }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
describe "#nil_sum" do
|
|
44
|
+
it { should respond_to(:nil_sum) }
|
|
45
|
+
|
|
46
|
+
it { subject.nil_sum.should eq(10) }
|
|
47
|
+
it { [1, 2, nil, 4].nil_sum.should eq(7) }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
describe "#average" do
|
|
51
|
+
it { should respond_to(:average) }
|
|
52
|
+
|
|
53
|
+
it { subject.average.should eq(2.5) }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe "#variance" do
|
|
57
|
+
it { should respond_to(:variance) }
|
|
58
|
+
|
|
59
|
+
it { subject.variance.should eq(1.6666666666666667) }
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
describe "#standard_deviation" do
|
|
63
|
+
it { should respond_to(:standard_deviation) }
|
|
64
|
+
|
|
65
|
+
it { subject.standard_deviation.should eq(1.2909944487358056) }
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
describe "#to_hash_for" do
|
|
69
|
+
it { should respond_to(:to_hash_for) }
|
|
70
|
+
|
|
71
|
+
it { subject.to_hash_for.should eq({1 => 1, 2 => 2, 3 => 3, 4 => 4}) }
|
|
72
|
+
it { subject.to_hash_for(&:to_s).should eq({'1' => 1, '2' => 2, '3' => 3, '4' => 4}) }
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
describe "#round" do
|
|
76
|
+
it { should respond_to(:round) }
|
|
77
|
+
|
|
78
|
+
it { subject.round(6).should eq([1, 2, 3, 4]) }
|
|
79
|
+
it { [1.456789, 2.987654].round(2).should eq([1.46, 2.99]) }
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
describe "#find_each_with_order" do
|
|
83
|
+
it { should respond_to(:find_each_with_order) }
|
|
84
|
+
it { should respond_to(:find_each) }
|
|
85
|
+
|
|
86
|
+
it "should invoke block" do
|
|
87
|
+
block = Mock::Block.new()
|
|
88
|
+
expect(block).to receive(:call).exactly(4).times
|
|
89
|
+
subject.find_each_with_order &block
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it "should not invoke block" do
|
|
93
|
+
block = Mock::Block.new()
|
|
94
|
+
expect(block).to_not receive(:call)
|
|
95
|
+
[].find_each_with_order &block
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
describe Riveter::CoreExtensions::HashExtensions do
|
|
101
|
+
describe "#rmerge" do
|
|
102
|
+
pending
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
describe "#rmerge!" do
|
|
106
|
+
pending
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
describe Riveter::CoreExtensions::ChainedQuerySupport do
|
|
111
|
+
subject do
|
|
112
|
+
Class.new().class_eval do
|
|
113
|
+
include Riveter::CoreExtensions::ChainedQuerySupport
|
|
114
|
+
end.new()
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it { should respond_to(:where?) }
|
|
118
|
+
it { subject.where?(false, {}).should eq(subject) }
|
|
119
|
+
it {
|
|
120
|
+
expect(subject).to receive(:where).with({:a => 'v'})
|
|
121
|
+
subject.where?(true, {:a => 'v'})
|
|
122
|
+
}
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
describe Riveter::CoreExtensions::BatchFinderSupport do
|
|
126
|
+
subject do
|
|
127
|
+
Class.new(Array).class_eval do
|
|
128
|
+
include Riveter::CoreExtensions::BatchFinderSupport
|
|
129
|
+
|
|
130
|
+
def limit(*args)
|
|
131
|
+
@limit = args.first
|
|
132
|
+
self
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def offset(*args)
|
|
136
|
+
self.shift(@limit)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
self
|
|
140
|
+
end.new().concat((1..2000).to_a)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
describe "#find_each_with_order" do
|
|
144
|
+
it { should respond_to(:find_each_with_order) }
|
|
145
|
+
|
|
146
|
+
it "should invoke block for each element" do
|
|
147
|
+
block = Mock::Block.new()
|
|
148
|
+
expect(block).to receive(:call).exactly(subject.length).times
|
|
149
|
+
subject.find_each_with_order(&block)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
it "should return enumerator if no block given" do
|
|
153
|
+
block = Mock::Block.new()
|
|
154
|
+
expect(block).to receive(:call).exactly(subject.length).times
|
|
155
|
+
subject.find_each_with_order.each(&block)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
context "with overridden batch size" do
|
|
159
|
+
let(:batch_size) { 10 }
|
|
160
|
+
|
|
161
|
+
it "should invoke block for each element" do
|
|
162
|
+
block = Mock::Block.new()
|
|
163
|
+
expect(block).to receive(:call).exactly(subject.length).times
|
|
164
|
+
expect(subject).to receive(:find_in_batches_with_order).with(:batch_size => batch_size).and_call_original
|
|
165
|
+
subject.find_each_with_order(:batch_size => batch_size, &block)
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
it "should return enumerator if no block given" do
|
|
169
|
+
block = Mock::Block.new()
|
|
170
|
+
expect(block).to receive(:call).exactly(subject.length).times
|
|
171
|
+
expect(subject).to receive(:find_in_batches_with_order).with(:batch_size => batch_size).and_call_original
|
|
172
|
+
subject.find_each_with_order(:batch_size => batch_size).each(&block)
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
describe "#find_in_batches_with_order" do
|
|
178
|
+
it { should respond_to(:find_in_batches_with_order) }
|
|
179
|
+
|
|
180
|
+
it "should invoke block for each element" do
|
|
181
|
+
block = Mock::Block.new()
|
|
182
|
+
expect(block).to receive(:call).exactly(subject.length / 1000).times
|
|
183
|
+
subject.find_in_batches_with_order(&block)
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
it "should return enumerator if no block given" do
|
|
187
|
+
block = Mock::Block.new()
|
|
188
|
+
expect(block).to receive(:call).exactly(subject.length / 1000).times
|
|
189
|
+
subject.find_in_batches_with_order.each(&block)
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
context "with overridden batch size" do
|
|
193
|
+
let(:batch_size) { 10 }
|
|
194
|
+
|
|
195
|
+
it "should invoke block for each element" do
|
|
196
|
+
block = Mock::Block.new()
|
|
197
|
+
expect(block).to receive(:call).exactly(subject.length / batch_size).times
|
|
198
|
+
subject.find_in_batches_with_order(:batch_size => batch_size, &block)
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
it "should return enumerator if no block given" do
|
|
202
|
+
block = Mock::Block.new()
|
|
203
|
+
expect(block).to receive(:call).exactly(subject.length / batch_size).times
|
|
204
|
+
subject.find_in_batches_with_order(:batch_size => batch_size).each(&block)
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
end
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Riveter::EnquiryController do
|
|
4
|
+
context "when not configured" do
|
|
5
|
+
describe "class" do
|
|
6
|
+
subject { TestEnquiryController }
|
|
7
|
+
|
|
8
|
+
it { should respond_to(:enquiry_controller_for) }
|
|
9
|
+
it { should_not respond_to(:enquiry_class) }
|
|
10
|
+
it { should_not respond_to(:enquiry_options) }
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe "instance" do
|
|
14
|
+
subject { TestEnquiryController.new }
|
|
15
|
+
|
|
16
|
+
it { should_not respond_to(:index) }
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
context "when configured" do
|
|
21
|
+
describe "class" do
|
|
22
|
+
subject { TestTestEnquiryController }
|
|
23
|
+
|
|
24
|
+
it { should respond_to(:enquiry_controller_for) }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe "instance" do
|
|
28
|
+
subject { TestTestEnquiryController.new }
|
|
29
|
+
|
|
30
|
+
it { should respond_to(:enquiry_class) }
|
|
31
|
+
it { should respond_to(:enquiry_options) }
|
|
32
|
+
it { should respond_to(:index) }
|
|
33
|
+
|
|
34
|
+
describe "#enquiry_class" do
|
|
35
|
+
it { subject.enquiry_class.should eq(TestEnquiry) }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe "#enquiry_options" do
|
|
39
|
+
it { subject.enquiry_options.should have_key(:as) }
|
|
40
|
+
it { subject.enquiry_options.should have_key(:attributes) }
|
|
41
|
+
|
|
42
|
+
it { subject.enquiry_options[:as].should eq('test') }
|
|
43
|
+
it { subject.enquiry_options[:attributes].should eq(TestEnquiry.query_filter_attributes) }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
describe "controller action" do
|
|
47
|
+
describe "#index" do
|
|
48
|
+
context "without params" do
|
|
49
|
+
before do
|
|
50
|
+
allow(subject).to receive(:params) { ActionController::Parameters.new({}) }
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "assigns @enquiry" do
|
|
54
|
+
subject.index
|
|
55
|
+
subject.send(:eval, '@enquiry').should_not be_nil
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
context "with params" do
|
|
60
|
+
before do
|
|
61
|
+
allow(subject).to receive(:params) { ActionController::Parameters.new({:test => {:name => 'test'}}) }
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "assigns @enquiry" do
|
|
65
|
+
subject.index
|
|
66
|
+
subject.send(:eval, '@enquiry').should_not be_nil
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "assigns attributes" do
|
|
70
|
+
subject.index
|
|
71
|
+
enquiry = subject.send(:eval, '@enquiry')
|
|
72
|
+
enquiry.filter.name.should eq('test')
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
context "for a valid enquiry" do
|
|
76
|
+
before do
|
|
77
|
+
allow_any_instance_of(TestEnquiry).to receive(:submit) { true }
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "assigns @enquiry" do
|
|
81
|
+
subject.index
|
|
82
|
+
subject.send(:eval, '@enquiry').should_not be_nil
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "invokes 'on_success' if defined" do
|
|
86
|
+
expect(subject).to receive(:on_success).with(kind_of(TestEnquiry))
|
|
87
|
+
subject.index
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
context "for an invalid enquiry" do
|
|
92
|
+
before do
|
|
93
|
+
allow_any_instance_of(TestEnquiry).to receive(:submit) { false }
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it "assigns @enquiry" do
|
|
97
|
+
subject.index
|
|
98
|
+
subject.send(:eval, '@enquiry').should_not be_nil
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it "invokes 'on_failure' if defined" do
|
|
102
|
+
expect(subject).to receive(:on_failure).with(kind_of(TestEnquiry))
|
|
103
|
+
subject.index
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
context "with reset param" do
|
|
109
|
+
before do
|
|
110
|
+
allow(subject).to receive(:params) { ActionController::Parameters.new({:reset => 'reset', :test => {:name => 'test'}}) }
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it "assigns @enquiry" do
|
|
114
|
+
subject.index
|
|
115
|
+
subject.send(:eval, '@enquiry').should_not be_nil
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
it "clears attributes" do
|
|
119
|
+
subject.index
|
|
120
|
+
enquiry = subject.send(:eval, '@enquiry')
|
|
121
|
+
enquiry.filter.name.should be_blank
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'riveter/enquiry_routes'
|
|
3
|
+
|
|
4
|
+
describe Riveter::EnquiryRoutes do
|
|
5
|
+
describe "instance" do
|
|
6
|
+
subject { TestEnquiryRoutes.new() }
|
|
7
|
+
|
|
8
|
+
describe "#enquiry" do
|
|
9
|
+
it { should respond_to(:enquiry) }
|
|
10
|
+
|
|
11
|
+
it "should define a GET and POST route" do
|
|
12
|
+
expect(subject).to receive(:get)
|
|
13
|
+
expect(subject).to receive(:post)
|
|
14
|
+
|
|
15
|
+
subject.enquiry :test_enquiry
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "should define a GET route for the :index action" do
|
|
19
|
+
expect(subject).to receive(:get).with('test', {
|
|
20
|
+
:controller => :test_enquiry,
|
|
21
|
+
:as => :test_enquiry,
|
|
22
|
+
:action => :index
|
|
23
|
+
})
|
|
24
|
+
allow(subject).to receive(:post)
|
|
25
|
+
|
|
26
|
+
subject.enquiry :test
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "should define a POST route for the :index action" do
|
|
30
|
+
allow(subject).to receive(:get)
|
|
31
|
+
expect(subject).to receive(:post).with('test', {
|
|
32
|
+
:controller => :test_enquiry,
|
|
33
|
+
:as => nil,
|
|
34
|
+
:action => :index
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
subject.enquiry :test
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "should allow overriding the controller" do
|
|
41
|
+
expect(subject).to receive(:get).with('test', {
|
|
42
|
+
:controller => :my_controller,
|
|
43
|
+
:as => :test_enquiry,
|
|
44
|
+
:action => :index
|
|
45
|
+
})
|
|
46
|
+
expect(subject).to receive(:post).with('test', {
|
|
47
|
+
:controller => :my_controller,
|
|
48
|
+
:as => nil,
|
|
49
|
+
:action => :index
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
subject.enquiry :test, :controller => :my_controller
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "should allow overriding the path" do
|
|
56
|
+
expect(subject).to receive(:get).with('do_some_thing', {
|
|
57
|
+
:controller => :test_enquiry,
|
|
58
|
+
:as => :test_enquiry,
|
|
59
|
+
:action => :index
|
|
60
|
+
})
|
|
61
|
+
expect(subject).to receive(:post).with('do_some_thing', {
|
|
62
|
+
:controller => :test_enquiry,
|
|
63
|
+
:as => nil,
|
|
64
|
+
:action => :index
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
subject.enquiry :test, :path => 'do_some_thing'
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "should allow overriding the path helper name" do
|
|
71
|
+
expect(subject).to receive(:get).with('test', {
|
|
72
|
+
:controller => :test_enquiry,
|
|
73
|
+
:as => :path_name,
|
|
74
|
+
:action => :index
|
|
75
|
+
})
|
|
76
|
+
expect(subject).to receive(:post).with('test', {
|
|
77
|
+
:controller => :test_enquiry,
|
|
78
|
+
:as => nil,
|
|
79
|
+
:action => :index
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
subject.enquiry :test, :as => :path_name
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "should allow overriding the index action" do
|
|
86
|
+
expect(subject).to receive(:get).with('test', {
|
|
87
|
+
:controller => :test_enquiry,
|
|
88
|
+
:as => :test_enquiry,
|
|
89
|
+
:action => :my_new_action
|
|
90
|
+
})
|
|
91
|
+
expect(subject).to receive(:post).with('test', {
|
|
92
|
+
:controller => :test_enquiry,
|
|
93
|
+
:as => nil,
|
|
94
|
+
:action => :my_new_action
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
subject.enquiry :test, :action => :my_new_action
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|