riveter 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +0 -3
  3. data/Gemfile.lock +1 -1
  4. data/README.md +5 -1
  5. data/app/helpers/riveter.rb +2 -0
  6. data/app/helpers/riveter/query_filter_form_helper.rb +1 -1
  7. data/lib/generators/haml/command_controller/command_controller_generator.rb +1 -1
  8. data/lib/generators/haml/enquiry_controller/enquiry_controller_generator.rb +1 -1
  9. data/lib/generators/riveter/enquiry/enquiry_generator.rb +5 -0
  10. data/lib/generators/riveter/enum/enum_generator.rb +1 -1
  11. data/lib/generators/riveter/query_filter/query_filter_generator.rb +1 -1
  12. data/lib/riveter/booleaness_validator.rb +0 -7
  13. data/lib/riveter/version.rb +1 -1
  14. data/spec/examples/generator_examples.rb +57 -0
  15. data/spec/generators/haml/command_controller/command_controller_generator_spec.rb +38 -19
  16. data/spec/generators/haml/enquiry_controller/enquiry_controller_generator_spec.rb +38 -19
  17. data/spec/generators/riveter/command/command_generator_spec.rb +32 -36
  18. data/spec/generators/riveter/command_controller/command_controller_generator_spec.rb +51 -0
  19. data/spec/generators/riveter/enquiry/enquiry_generator_spec.rb +53 -0
  20. data/spec/generators/riveter/enquiry_controller/enquiry_controller_generator_spec.rb +51 -0
  21. data/spec/generators/riveter/enum/enum_generator_spec.rb +64 -0
  22. data/spec/generators/riveter/install/install_generator_spec.rb +6 -0
  23. data/spec/generators/riveter/presenter/presenter_generator_spec.rb +32 -0
  24. data/spec/generators/riveter/query/query_generator_spec.rb +32 -0
  25. data/spec/generators/riveter/query_filter/query_filter_generator_spec.rb +31 -36
  26. data/spec/generators/riveter/service/service_generator_spec.rb +33 -0
  27. data/spec/generators/riveter/worker/worker_generator_spec.rb +32 -0
  28. data/spec/generators/rspec/command/command_generator_spec.rb +24 -0
  29. data/spec/generators/rspec/command_controller/command_controller_generator_spec.rb +36 -0
  30. data/spec/generators/rspec/enquiry/enquiry_generator_spec.rb +24 -0
  31. data/spec/generators/rspec/enquiry_controller/enquiry_controller_generator_spec.rb +36 -0
  32. data/spec/generators/rspec/enum/enum_generator_spec.rb +24 -0
  33. data/spec/generators/rspec/presenter/presenter_generator_spec.rb +24 -0
  34. data/spec/generators/rspec/query/query_generator_spec.rb +24 -0
  35. data/spec/generators/rspec/query_filter/query_filter_generator_spec.rb +24 -0
  36. data/spec/generators/rspec/service/service_generator_spec.rb +24 -0
  37. data/spec/generators/rspec/worker/worker_generator_spec.rb +24 -0
  38. data/spec/helpers/riveter/command_form_helper_spec.rb +26 -0
  39. data/spec/helpers/riveter/enquiry_form_helper_spec.rb +26 -0
  40. data/spec/helpers/riveter/query_filter_form_helper_spec.rb +26 -0
  41. data/spec/riveter/booleaness_validator_spec.rb +83 -0
  42. data/spec/riveter/command_spec.rb +7 -2
  43. data/spec/spec_helper.rb +3 -17
  44. data/spec/support/test_class_with_attributes.rb +3 -0
  45. data/spec/support/test_service.rb +0 -5
  46. metadata +47 -2
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+ require 'generators/riveter/enquiry/enquiry_generator'
3
+
4
+ describe Riveter::Generators::EnquiryGenerator, :type => :generator do
5
+ before do
6
+ FileUtils.mkdir_p(file('config/locales'))
7
+ File.open(file('config/routes.rb'), 'w') {|f| f.write "TestApp::Application.routes.draw do\nend\n" }
8
+ end
9
+
10
+ it "should run all tasks in the generator" do
11
+ gen = generator %w(foo_bar)
12
+ expect(gen).to receive(:create_enquiry_file)
13
+ expect(gen).to receive(:create_module_file)
14
+
15
+ # hooks
16
+ expect(gen).to receive(:_invoke_from_option_enquiry_controller)
17
+ expect(gen).to receive(:_invoke_from_option_query)
18
+ expect(gen).to receive(:_invoke_from_option_query_filter)
19
+ expect(gen).to receive(:_invoke_from_option_test_framework)
20
+
21
+ capture(:stdout) { gen.invoke_all }
22
+ end
23
+
24
+ describe "the generated files" do
25
+ describe "the enquiry" do
26
+ describe "with defaults" do
27
+ before do
28
+ run_generator %w(foo_bar)
29
+ end
30
+
31
+ subject { file('app/enquiries/foo_bar_enquiry.rb') }
32
+
33
+ it { should exist }
34
+ it { should contain('class FooBarEnquiry') }
35
+ end
36
+
37
+ describe "with attributes" do
38
+ before do
39
+ run_generator %w(foo_bar name:string:required active:boolean other)
40
+ end
41
+
42
+ subject { file('app/enquiries/foo_bar_enquiry.rb') }
43
+
44
+ it { should exist }
45
+ it { should contain('class FooBarEnquiry') }
46
+ it { should contain('filter_with FooBarQueryFilter') }
47
+ it { should contain('query_with FooBarQuery') }
48
+ end
49
+ end
50
+
51
+ it_should_behave_like 'a generator with a module', 'app/enquiries'
52
+ end
53
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+ require 'generators/riveter/enquiry_controller/enquiry_controller_generator'
3
+
4
+ describe Riveter::Generators::EnquiryControllerGenerator, :type => :generator do
5
+ before do
6
+ FileUtils.mkdir_p(file('config'))
7
+ File.open(file('config/routes.rb'), 'w') {|f| f.write "TestApp::Application.routes.draw do\nend\n" }
8
+ end
9
+
10
+ it "should run all tasks in the generator" do
11
+ gen = generator %w(foo_bar)
12
+ expect(gen).to receive(:create_enquiry_controller_file)
13
+ expect(gen).to receive(:create_module_file)
14
+ expect(gen).to receive(:add_enquiry_route)
15
+
16
+ # hooks
17
+ expect(gen).to receive(:_invoke_from_option_template_engine)
18
+ expect(gen).to receive(:_invoke_from_option_test_framework)
19
+
20
+ capture(:stdout) { gen.invoke_all }
21
+ end
22
+
23
+ describe "the generated files" do
24
+ describe "the controller" do
25
+ describe "with defaults" do
26
+ before do
27
+ run_generator %w(foo_bar)
28
+ end
29
+
30
+ subject { file('app/controllers/foo_bar_enquiry_controller.rb') }
31
+
32
+ it { should exist }
33
+ it { should contain('enquiry_controller_for FooBarEnquiry') }
34
+ end
35
+
36
+ describe "with action names" do
37
+ before do
38
+ run_generator %w(foo_bar showme)
39
+ end
40
+
41
+ subject { file('app/controllers/foo_bar_enquiry_controller.rb') }
42
+
43
+ it { should exist }
44
+ it { should contain('enquiry_controller_for FooBarEnquiry, :action => :showme') }
45
+ end
46
+ end
47
+
48
+ it_should_behave_like 'a generator with a module', 'app/controllers'
49
+ it_should_behave_like 'a generator with output to routes', 'enquiry :foo_bar'
50
+ end
51
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+ require 'generators/riveter/enum/enum_generator'
3
+
4
+ describe Riveter::Generators::EnumGenerator, :type => :generator do
5
+ before do
6
+ FileUtils.mkdir_p(file('config/locales'))
7
+ end
8
+
9
+ it "should run all tasks in the generator" do
10
+ gen = generator %w(foo_bar)
11
+ expect(gen).to receive(:create_enum_file)
12
+ expect(gen).to receive(:create_module_file)
13
+ expect(gen).to receive(:create_locale_file)
14
+
15
+ # hooks
16
+ expect(gen).to receive(:_invoke_from_option_test_framework)
17
+
18
+ capture(:stdout) { gen.invoke_all }
19
+ end
20
+
21
+ describe "the generated files" do
22
+ describe "the enum" do
23
+ describe "with defaults" do
24
+ before do
25
+ run_generator %w(foo_bar)
26
+ end
27
+
28
+ subject { file('app/enums/foo_bar_enum.rb') }
29
+
30
+ it { should exist }
31
+ it { should contain('module FooBarEnum') }
32
+ end
33
+
34
+ describe "with members (implied as integers)" do
35
+ before do
36
+ run_generator %w(foo_bar baz qux)
37
+ end
38
+
39
+ subject { file('app/enums/foo_bar_enum.rb') }
40
+
41
+ it { should exist }
42
+ it { should contain('module FooBarEnum') }
43
+ it { should contain('Baz = 1') }
44
+ it { should contain('Qux = 2') }
45
+ end
46
+
47
+ describe "with members and values" do
48
+ before do
49
+ run_generator %w(foo_bar baz:10 qux:20)
50
+ end
51
+
52
+ subject { file('app/enums/foo_bar_enum.rb') }
53
+
54
+ it { should exist }
55
+ it { should contain('module FooBarEnum') }
56
+ it { should contain('Baz = 10') }
57
+ it { should contain('Qux = 20') }
58
+ end
59
+ end
60
+
61
+ it_should_behave_like 'a generator with a module', 'app/enums'
62
+ it_should_behave_like 'a generator with locale file output', 'enums'
63
+ end
64
+ end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+ require 'generators/riveter/install/install_generator'
3
+
4
+ describe Riveter::Generators::InstallGenerator, :type => :generator do
5
+ pending
6
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ require 'generators/riveter/presenter/presenter_generator'
3
+
4
+ describe Riveter::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_file)
8
+ expect(gen).to receive(:create_module_file)
9
+
10
+ # hooks
11
+ expect(gen).to receive(:_invoke_from_option_test_framework)
12
+
13
+ capture(:stdout) { gen.invoke_all }
14
+ end
15
+
16
+ describe "the generated files" do
17
+ describe "the presenter" do
18
+ describe "with defaults" do
19
+ before do
20
+ run_generator %w(foo_bar)
21
+ end
22
+
23
+ subject { file('app/presenters/foo_bar_presenter.rb') }
24
+
25
+ it { should exist }
26
+ it { should contain('class FooBarPresenter') }
27
+ end
28
+ end
29
+
30
+ it_should_behave_like 'a generator with a module', 'app/presenters'
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ require 'generators/riveter/query/query_generator'
3
+
4
+ describe Riveter::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_file)
8
+ expect(gen).to receive(:create_module_file)
9
+
10
+ # hooks
11
+ expect(gen).to receive(:_invoke_from_option_test_framework)
12
+
13
+ capture(:stdout) { gen.invoke_all }
14
+ end
15
+
16
+ describe "the generated files" do
17
+ describe "the query" do
18
+ describe "with defaults" do
19
+ before do
20
+ run_generator %w(foo_bar)
21
+ end
22
+
23
+ subject { file('app/queries/foo_bar_query.rb') }
24
+
25
+ it { should exist }
26
+ it { should contain('class FooBarQuery') }
27
+ end
28
+ end
29
+
30
+ it_should_behave_like 'a generator with a module', 'app/queries'
31
+ end
32
+ end
@@ -1,58 +1,53 @@
1
1
  require 'spec_helper'
2
2
  require 'generators/riveter/query_filter/query_filter_generator'
3
- require 'fileutils'
4
3
 
5
4
  describe Riveter::Generators::QueryFilterGenerator, :type => :generator do
6
- it "creates the query filter with defaults" do
7
- gen = generator %w(active_items)
8
- expect(gen).to receive(:create_query_filter_file)
9
- capture(:stdout) { gen.invoke_all }
5
+ before do
6
+ FileUtils.mkdir_p(file('config/locales'))
7
+ File.open(file('config/routes.rb'), 'w') {|f| f.write "TestApp::Application.routes.draw do\nend\n" }
10
8
  end
11
9
 
12
- it "creates the query filter with specified attributes" do
13
- gen = generator %w(active_items name:string:required active:boolean other)
10
+ it "should run all tasks in the generator" do
11
+ gen = generator %w(foo_bar)
14
12
  expect(gen).to receive(:create_query_filter_file)
15
- capture(:stdout) { gen.invoke_all }
16
- end
17
-
18
- it "creates a module file" do
19
- gen = generator %w(test_ns/active_items name:string:required active:boolean other)
20
13
  expect(gen).to receive(:create_module_file)
21
- capture(:stdout) { gen.invoke_all }
22
- end
23
-
24
- it "creates a locale file if it doesn't exist" do
25
- gen = generator %w(active_items)
26
14
  expect(gen).to receive(:create_locale_file)
27
- capture(:stdout) { gen.invoke_all }
28
- end
29
15
 
30
- it "skips creating a locale file if it exists" do
31
- pending
16
+ # hooks
17
+ expect(gen).to receive(:_invoke_from_option_test_framework)
18
+
19
+ capture(:stdout) { gen.invoke_all }
32
20
  end
33
21
 
34
22
  describe "the generated files" do
35
23
  describe "the query filter" do
36
- before do
37
- run_generator %w(active_items name:string:required active:boolean other)
38
- end
24
+ describe "with defaults" do
25
+ before do
26
+ run_generator %w(foo_bar)
27
+ end
39
28
 
40
- subject { file('app/query_filters/active_items_query_filter.rb') }
29
+ subject { file('app/query_filters/foo_bar_query_filter.rb') }
41
30
 
42
- it { should exist }
43
- end
44
-
45
- describe "the commands.en.yml locale" do
46
- before do
47
- FileUtils.mkdir_p(file('config/locales'))
48
- File.open(file('config/locales/query_filters.en.yml'), 'w') {|f| f.write 'empty' }
49
- run_generator %w(active_items name:string:required active:boolean other)
31
+ it { should exist }
32
+ it { should contain('class FooBarQueryFilter') }
50
33
  end
51
34
 
52
- subject { file('config/locales/query_filters.en.yml') }
35
+ describe "with attributes" do
36
+ before do
37
+ run_generator %w(foo_bar name:string:required active:boolean other)
38
+ end
39
+
40
+ subject { file('app/query_filters/foo_bar_query_filter.rb') }
53
41
 
54
- it { should exist }
55
- it { File.open(file('config/locales/query_filters.en.yml'), 'r') {|f| f.read }.should eq('empty') }
42
+ it { should exist }
43
+ it { should contain('class FooBarQueryFilter') }
44
+ it { should contain('attr_string :name, :required => true') }
45
+ it { should contain('attr_boolean :active') }
46
+ it { should contain('attr_string :other') }
47
+ end
56
48
  end
49
+
50
+ it_should_behave_like 'a generator with a module', 'app/query_filters'
51
+ it_should_behave_like 'a generator with locale file output', 'query_filters'
57
52
  end
58
53
  end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+ require 'generators/riveter/service/service_generator'
3
+
4
+ describe Riveter::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_file)
8
+ expect(gen).to receive(:create_module_file)
9
+
10
+ # hooks
11
+ expect(gen).to receive(:_invoke_from_option_test_framework)
12
+
13
+ capture(:stdout) { gen.invoke_all }
14
+ end
15
+
16
+ describe "the generated files" do
17
+ describe "the service" do
18
+ describe "with defaults" do
19
+ before do
20
+ run_generator %w(foo_bar)
21
+ end
22
+
23
+ subject { file('app/services/foo_bar_service.rb') }
24
+
25
+ it { should exist }
26
+ it { should contain('class FooBarService') }
27
+ it { should contain('register_as_handler_for FooBarCommand') }
28
+ end
29
+ end
30
+
31
+ it_should_behave_like 'a generator with a module', 'app/services'
32
+ end
33
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ require 'generators/riveter/worker/worker_generator'
3
+
4
+ describe Riveter::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_file)
8
+ expect(gen).to receive(:create_module_file)
9
+
10
+ # hooks
11
+ expect(gen).to receive(:_invoke_from_option_test_framework)
12
+
13
+ capture(:stdout) { gen.invoke_all }
14
+ end
15
+
16
+ describe "the generated files" do
17
+ describe "the worker" do
18
+ describe "with defaults" do
19
+ before do
20
+ run_generator %w(foo_bar)
21
+ end
22
+
23
+ subject { file('app/workers/foo_bar_worker.rb') }
24
+
25
+ it { should exist }
26
+ it { should contain('class FooBarWorker') }
27
+ end
28
+ end
29
+
30
+ it_should_behave_like 'a generator with a module', 'app/workers'
31
+ end
32
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ require 'generators/rspec/command/command_generator'
3
+
4
+ describe Rspec::Generators::CommandGenerator, :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_command_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/commands/foo_bar_command_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/command_controller/command_controller_generator'
3
+
4
+ describe Rspec::Generators::CommandControllerGenerator, :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_command_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_command_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 qux)
26
+ end
27
+
28
+ subject { file('spec/controllers/foo_bar_command_controller_spec.rb') }
29
+
30
+ it { should exist }
31
+ it { should contain("GET 'baz'") }
32
+ it { should contain("POST 'qux'") }
33
+ end
34
+ end
35
+ end
36
+ end