riveter 0.0.1 → 0.0.3
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 +4 -4
- data/.travis.yml +0 -3
- data/Gemfile.lock +1 -1
- data/README.md +5 -1
- data/app/helpers/riveter.rb +2 -0
- data/app/helpers/riveter/query_filter_form_helper.rb +1 -1
- data/lib/generators/haml/command_controller/command_controller_generator.rb +1 -1
- data/lib/generators/haml/enquiry_controller/enquiry_controller_generator.rb +1 -1
- data/lib/generators/riveter/enquiry/enquiry_generator.rb +5 -0
- data/lib/generators/riveter/enum/enum_generator.rb +1 -1
- data/lib/generators/riveter/query_filter/query_filter_generator.rb +1 -1
- data/lib/riveter/booleaness_validator.rb +0 -7
- data/lib/riveter/version.rb +1 -1
- data/spec/examples/generator_examples.rb +57 -0
- data/spec/generators/haml/command_controller/command_controller_generator_spec.rb +38 -19
- data/spec/generators/haml/enquiry_controller/enquiry_controller_generator_spec.rb +38 -19
- data/spec/generators/riveter/command/command_generator_spec.rb +32 -36
- data/spec/generators/riveter/command_controller/command_controller_generator_spec.rb +51 -0
- data/spec/generators/riveter/enquiry/enquiry_generator_spec.rb +53 -0
- data/spec/generators/riveter/enquiry_controller/enquiry_controller_generator_spec.rb +51 -0
- data/spec/generators/riveter/enum/enum_generator_spec.rb +64 -0
- data/spec/generators/riveter/install/install_generator_spec.rb +6 -0
- data/spec/generators/riveter/presenter/presenter_generator_spec.rb +32 -0
- data/spec/generators/riveter/query/query_generator_spec.rb +32 -0
- data/spec/generators/riveter/query_filter/query_filter_generator_spec.rb +31 -36
- data/spec/generators/riveter/service/service_generator_spec.rb +33 -0
- data/spec/generators/riveter/worker/worker_generator_spec.rb +32 -0
- data/spec/generators/rspec/command/command_generator_spec.rb +24 -0
- data/spec/generators/rspec/command_controller/command_controller_generator_spec.rb +36 -0
- data/spec/generators/rspec/enquiry/enquiry_generator_spec.rb +24 -0
- data/spec/generators/rspec/enquiry_controller/enquiry_controller_generator_spec.rb +36 -0
- data/spec/generators/rspec/enum/enum_generator_spec.rb +24 -0
- data/spec/generators/rspec/presenter/presenter_generator_spec.rb +24 -0
- data/spec/generators/rspec/query/query_generator_spec.rb +24 -0
- data/spec/generators/rspec/query_filter/query_filter_generator_spec.rb +24 -0
- data/spec/generators/rspec/service/service_generator_spec.rb +24 -0
- data/spec/generators/rspec/worker/worker_generator_spec.rb +24 -0
- data/spec/helpers/riveter/command_form_helper_spec.rb +26 -0
- data/spec/helpers/riveter/enquiry_form_helper_spec.rb +26 -0
- data/spec/helpers/riveter/query_filter_form_helper_spec.rb +26 -0
- data/spec/riveter/booleaness_validator_spec.rb +83 -0
- data/spec/riveter/command_spec.rb +7 -2
- data/spec/spec_helper.rb +3 -17
- data/spec/support/test_class_with_attributes.rb +3 -0
- data/spec/support/test_service.rb +0 -5
- metadata +47 -2
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'generators/rspec/enquiry/enquiry_generator'
|
3
|
+
|
4
|
+
describe Rspec::Generators::EnquiryGenerator, :type => :generator do
|
5
|
+
it "should run all tasks in the generator" do
|
6
|
+
gen = generator %w(foo_bar)
|
7
|
+
expect(gen).to receive(:create_enquiry_spec)
|
8
|
+
capture(:stdout) { gen.invoke_all }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "the generated files" do
|
12
|
+
describe "the spec" do
|
13
|
+
describe "with defaults" do
|
14
|
+
before do
|
15
|
+
run_generator %w(foo_bar)
|
16
|
+
end
|
17
|
+
|
18
|
+
subject { file('spec/enquiries/foo_bar_enquiry_spec.rb') }
|
19
|
+
|
20
|
+
it { should exist }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'generators/rspec/enquiry_controller/enquiry_controller_generator'
|
3
|
+
|
4
|
+
describe Rspec::Generators::EnquiryControllerGenerator, :type => :generator do
|
5
|
+
it "should run all tasks in the generator" do
|
6
|
+
gen = generator %w(foo_bar)
|
7
|
+
expect(gen).to receive(:create_enquiry_controller_spec)
|
8
|
+
capture(:stdout) { gen.invoke_all }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "the generated files" do
|
12
|
+
describe "the spec" do
|
13
|
+
describe "with defaults" do
|
14
|
+
before do
|
15
|
+
run_generator %w(foo_bar)
|
16
|
+
end
|
17
|
+
|
18
|
+
subject { file('spec/controllers/foo_bar_enquiry_controller_spec.rb') }
|
19
|
+
|
20
|
+
it { should exist }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "with action names" do
|
24
|
+
before do
|
25
|
+
run_generator %w(foo_bar baz)
|
26
|
+
end
|
27
|
+
|
28
|
+
subject { file('spec/controllers/foo_bar_enquiry_controller_spec.rb') }
|
29
|
+
|
30
|
+
it { should exist }
|
31
|
+
it { should contain("GET 'baz'") }
|
32
|
+
it { should contain("POST 'baz'") }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'generators/rspec/enum/enum_generator'
|
3
|
+
|
4
|
+
describe Rspec::Generators::EnumGenerator, :type => :generator do
|
5
|
+
it "should run all tasks in the generator" do
|
6
|
+
gen = generator %w(foo_bar)
|
7
|
+
expect(gen).to receive(:create_enum_spec)
|
8
|
+
capture(:stdout) { gen.invoke_all }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "the generated files" do
|
12
|
+
describe "the spec" do
|
13
|
+
describe "with defaults" do
|
14
|
+
before do
|
15
|
+
run_generator %w(foo_bar)
|
16
|
+
end
|
17
|
+
|
18
|
+
subject { file('spec/enums/foo_bar_enum_spec.rb') }
|
19
|
+
|
20
|
+
it { should exist }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'generators/rspec/presenter/presenter_generator'
|
3
|
+
|
4
|
+
describe Rspec::Generators::PresenterGenerator, :type => :generator do
|
5
|
+
it "should run all tasks in the generator" do
|
6
|
+
gen = generator %w(foo_bar)
|
7
|
+
expect(gen).to receive(:create_presenter_spec)
|
8
|
+
capture(:stdout) { gen.invoke_all }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "the generated files" do
|
12
|
+
describe "the spec" do
|
13
|
+
describe "with defaults" do
|
14
|
+
before do
|
15
|
+
run_generator %w(foo_bar)
|
16
|
+
end
|
17
|
+
|
18
|
+
subject { file('spec/presenters/foo_bar_presenter_spec.rb') }
|
19
|
+
|
20
|
+
it { should exist }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'generators/rspec/query/query_generator'
|
3
|
+
|
4
|
+
describe Rspec::Generators::QueryGenerator, :type => :generator do
|
5
|
+
it "should run all tasks in the generator" do
|
6
|
+
gen = generator %w(foo_bar)
|
7
|
+
expect(gen).to receive(:create_query_spec)
|
8
|
+
capture(:stdout) { gen.invoke_all }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "the generated files" do
|
12
|
+
describe "the spec" do
|
13
|
+
describe "with defaults" do
|
14
|
+
before do
|
15
|
+
run_generator %w(foo_bar)
|
16
|
+
end
|
17
|
+
|
18
|
+
subject { file('spec/queries/foo_bar_query_spec.rb') }
|
19
|
+
|
20
|
+
it { should exist }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'generators/rspec/query_filter/query_filter_generator'
|
3
|
+
|
4
|
+
describe Rspec::Generators::QueryFilterGenerator, :type => :generator do
|
5
|
+
it "should run all tasks in the generator" do
|
6
|
+
gen = generator %w(foo_bar)
|
7
|
+
expect(gen).to receive(:create_query_filter_spec)
|
8
|
+
capture(:stdout) { gen.invoke_all }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "the generated files" do
|
12
|
+
describe "the spec" do
|
13
|
+
describe "with defaults" do
|
14
|
+
before do
|
15
|
+
run_generator %w(foo_bar)
|
16
|
+
end
|
17
|
+
|
18
|
+
subject { file('spec/query_filters/foo_bar_query_filter_spec.rb') }
|
19
|
+
|
20
|
+
it { should exist }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'generators/rspec/service/service_generator'
|
3
|
+
|
4
|
+
describe Rspec::Generators::ServiceGenerator, :type => :generator do
|
5
|
+
it "should run all tasks in the generator" do
|
6
|
+
gen = generator %w(foo_bar)
|
7
|
+
expect(gen).to receive(:create_service_spec)
|
8
|
+
capture(:stdout) { gen.invoke_all }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "the generated files" do
|
12
|
+
describe "the spec" do
|
13
|
+
describe "with defaults" do
|
14
|
+
before do
|
15
|
+
run_generator %w(foo_bar)
|
16
|
+
end
|
17
|
+
|
18
|
+
subject { file('spec/services/foo_bar_service_spec.rb') }
|
19
|
+
|
20
|
+
it { should exist }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'generators/rspec/worker/worker_generator'
|
3
|
+
|
4
|
+
describe Rspec::Generators::WorkerGenerator, :type => :generator do
|
5
|
+
it "should run all tasks in the generator" do
|
6
|
+
gen = generator %w(foo_bar)
|
7
|
+
expect(gen).to receive(:create_worker_spec)
|
8
|
+
capture(:stdout) { gen.invoke_all }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "the generated files" do
|
12
|
+
describe "the spec" do
|
13
|
+
describe "with defaults" do
|
14
|
+
before do
|
15
|
+
run_generator %w(foo_bar)
|
16
|
+
end
|
17
|
+
|
18
|
+
subject { file('spec/workers/foo_bar_worker_spec.rb') }
|
19
|
+
|
20
|
+
it { should exist }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../../../app/helpers/riveter/command_form_helper'
|
3
|
+
|
4
|
+
describe Riveter::CommandFormHelper do
|
5
|
+
subject {
|
6
|
+
Class.new().tap do |klass|
|
7
|
+
klass.send :include, Riveter::CommandFormHelper
|
8
|
+
end.new()
|
9
|
+
}
|
10
|
+
|
11
|
+
describe "#command_form_for" do
|
12
|
+
it "delegates to default form_for" do
|
13
|
+
command = TestCommand.new()
|
14
|
+
expect(subject).to receive(:form_for).with(command, :as => 'test', :url => 'test')
|
15
|
+
|
16
|
+
subject.command_form_for(command)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "delegates to simple form if available" do
|
20
|
+
command = TestCommand.new()
|
21
|
+
expect(subject).to receive(:simple_form_for).with(command, :as => 'test', :url => 'test')
|
22
|
+
|
23
|
+
subject.command_form_for(command)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../../../app/helpers/riveter/enquiry_form_helper'
|
3
|
+
|
4
|
+
describe Riveter::EnquiryFormHelper do
|
5
|
+
subject {
|
6
|
+
Class.new().tap do |klass|
|
7
|
+
klass.send :include, Riveter::EnquiryFormHelper
|
8
|
+
end.new()
|
9
|
+
}
|
10
|
+
|
11
|
+
describe "#enquiry_form_for" do
|
12
|
+
it "delegates to default form_for" do
|
13
|
+
enquiry = TestEnquiry.new()
|
14
|
+
expect(subject).to receive(:form_for).with(enquiry.query_filter, :as => 'test', :url => 'test', :method => :get)
|
15
|
+
|
16
|
+
subject.enquiry_form_for(enquiry)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "delegates to simple form if available" do
|
20
|
+
enquiry = TestEnquiry.new()
|
21
|
+
expect(subject).to receive(:simple_form_for).with(enquiry.query_filter, :as => 'test', :url => 'test', :method => :get)
|
22
|
+
|
23
|
+
subject.enquiry_form_for(enquiry)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../../../app/helpers/riveter/query_filter_form_helper'
|
3
|
+
|
4
|
+
describe Riveter::QueryFilterFormHelper do
|
5
|
+
subject {
|
6
|
+
Class.new().tap do |klass|
|
7
|
+
klass.send :include, Riveter::QueryFilterFormHelper
|
8
|
+
end.new()
|
9
|
+
}
|
10
|
+
|
11
|
+
describe "#query_filter_form_for" do
|
12
|
+
it "delegates to default form_for" do
|
13
|
+
query_filter = TestQueryFilter.new()
|
14
|
+
expect(subject).to receive(:form_for).with(query_filter, :as => 'test', :url => 'test', :method => :get)
|
15
|
+
|
16
|
+
subject.query_filter_form_for(query_filter)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "delegates to simple form if available" do
|
20
|
+
query_filter = TestQueryFilter.new()
|
21
|
+
expect(subject).to receive(:simple_form_for).with(query_filter, :as => 'test', :url => 'test', :method => :get)
|
22
|
+
|
23
|
+
subject.query_filter_form_for(query_filter)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Riveter::BooleanessValidator do
|
4
|
+
subject { Riveter::BooleanessValidator }
|
5
|
+
|
6
|
+
describe "#validate_each" do
|
7
|
+
def record_for(value)
|
8
|
+
record = double()
|
9
|
+
allow(record).to receive(:read_attribute_for_validation) { value }
|
10
|
+
record
|
11
|
+
end
|
12
|
+
|
13
|
+
def errors
|
14
|
+
errors = double
|
15
|
+
allow(errors).to receive(:add)
|
16
|
+
errors
|
17
|
+
end
|
18
|
+
|
19
|
+
context "valid data" do
|
20
|
+
describe "with defaults" do
|
21
|
+
it {
|
22
|
+
validator = subject.new(:attributes => [:test])
|
23
|
+
record = record_for('not_a_boolean')
|
24
|
+
expect(record).to receive(:errors).and_return(errors)
|
25
|
+
|
26
|
+
validator.validate(record)
|
27
|
+
}
|
28
|
+
|
29
|
+
it {
|
30
|
+
validator = subject.new(:attributes => [:test])
|
31
|
+
record = record_for(true)
|
32
|
+
expect(record).to_not receive(:errors)
|
33
|
+
|
34
|
+
validator.validate(record)
|
35
|
+
}
|
36
|
+
|
37
|
+
it {
|
38
|
+
validator = subject.new(:attributes => [:test])
|
39
|
+
record = record_for(false)
|
40
|
+
expect(record).to_not receive(:errors)
|
41
|
+
|
42
|
+
validator.validate(record)
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "with allow_nil" do
|
47
|
+
it {
|
48
|
+
validator = subject.new(:attributes => [:test], :allow_nil => false)
|
49
|
+
record = record_for(nil)
|
50
|
+
expect(record).to receive(:errors).and_return(errors)
|
51
|
+
|
52
|
+
validator.validate(record)
|
53
|
+
}
|
54
|
+
|
55
|
+
it {
|
56
|
+
validator = subject.new(:attributes => [:test], :allow_nil => true)
|
57
|
+
record = record_for(nil)
|
58
|
+
expect(record).to_not receive(:errors)
|
59
|
+
|
60
|
+
validator.validate(record)
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "with allow_blank" do
|
65
|
+
it {
|
66
|
+
validator = subject.new(:attributes => [:test], :allow_blank => false)
|
67
|
+
record = record_for('')
|
68
|
+
expect(record).to receive(:errors).and_return(errors)
|
69
|
+
|
70
|
+
validator.validate(record)
|
71
|
+
}
|
72
|
+
|
73
|
+
it {
|
74
|
+
validator = subject.new(:attributes => [:test], :allow_blank => true)
|
75
|
+
record = record_for('')
|
76
|
+
expect(record).to_not receive(:errors)
|
77
|
+
|
78
|
+
validator.validate(record)
|
79
|
+
}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -15,6 +15,11 @@ describe Riveter::Command do
|
|
15
15
|
it { should respond_to(:i18n_scope) }
|
16
16
|
it { subject.i18n_scope.should eq(:commands) }
|
17
17
|
end
|
18
|
+
|
19
|
+
describe ".success_notice" do
|
20
|
+
it { should respond_to(:success_notice) }
|
21
|
+
it { subject.success_notice.should eq('Successfully executed Test command.') }
|
22
|
+
end
|
18
23
|
end
|
19
24
|
|
20
25
|
describe "instance" do
|
@@ -57,9 +62,9 @@ describe Riveter::Command do
|
|
57
62
|
|
58
63
|
it "should invoke associated service" do
|
59
64
|
allow(subject).to receive(:valid?) { true }
|
60
|
-
expect_any_instance_of(TestService).to receive(:perform) { true }
|
65
|
+
expect_any_instance_of(TestService).to receive(:perform).with(subject, :arg) { true }
|
61
66
|
|
62
|
-
subject.submit(:name => 'test')
|
67
|
+
subject.submit(:arg, :name => 'test')
|
63
68
|
end
|
64
69
|
end
|
65
70
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -15,28 +15,14 @@ require 'haml'
|
|
15
15
|
require 'rspec/autorun'
|
16
16
|
require 'shoulda/matchers'
|
17
17
|
require 'ammeter/init'
|
18
|
+
|
19
|
+
require 'fileutils'
|
18
20
|
require 'simplecov'
|
19
21
|
require 'pry'
|
20
22
|
|
21
23
|
SimpleCov.start do
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
class TestApp < Rails::Application
|
26
|
-
config.root = File.dirname(__FILE__)
|
24
|
+
add_filter 'spec'
|
27
25
|
end
|
28
|
-
Rails.application = TestApp
|
29
|
-
|
30
|
-
module Rails
|
31
|
-
def self.root
|
32
|
-
@root ||= File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp', 'rails'))
|
33
|
-
end
|
34
|
-
end
|
35
|
-
Rails.application.config.root = Rails.root
|
36
|
-
|
37
|
-
# Call configure to load the settings from
|
38
|
-
# Rails.application.config.generators to Rails::Generators
|
39
|
-
Rails::Generators.configure! Rails.application.config.generators
|
40
26
|
|
41
27
|
# require supporting ruby files with custom matchers and macros, etc
|
42
28
|
Dir[File.expand_path("../support/**/*.rb", __FILE__)].each {|f| require f }
|