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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b51c150059867905f381fcd4a303bcae0464683
4
- data.tar.gz: e2aa27934831b4e6066b63e6c7edc7577beed1cb
3
+ metadata.gz: 490a7f61ea22d7e68dcf0b8b634322d69e2989d3
4
+ data.tar.gz: 5593071d86a1e9372f755844be534ebf60b3ba98
5
5
  SHA512:
6
- metadata.gz: 72454455538bb878d56831daf6ec8281e749e0f2118852f4107d2191d2bc656412e8f38e031722a9a9b1be7f8d6df14d77d8250e749c3571104dacfd23908269
7
- data.tar.gz: 952dc079df4c947453484ab371d8fe1920368d111e23d7c66c0912a3383d05ea8ebae7375b1ef36902cfc01c6c2ce0ec6ed71285947c5ce0d9d797a49c73ee73
6
+ metadata.gz: ff3996ed69e012715a3dfdceefaca6406fe3cb0b808c6c19c5ca696608d7b74392299885847fe41d15aefdf432dab6488ec4e3eb084ef95e428c6fb5e9d89c6e
7
+ data.tar.gz: d3a29892bceebcfa3a928c372fb323fcf88d1cc566a5b0b5a65681d0a6d697bda83f0dac09752426c9efc54b7e4e922b1c3fbaec6dc024487d453b87d9b0a092
data/.travis.yml CHANGED
@@ -2,10 +2,7 @@ language: ruby
2
2
  cache: bundler
3
3
 
4
4
  rvm:
5
- - 2.0.0
6
5
  - 2.1.0
7
- - 2.1.1
8
- - 2.1.2
9
6
 
10
7
  script: 'bundle exec rake spec'
11
8
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- riveter (0.0.1)
4
+ riveter (0.0.3)
5
5
  actionpack
6
6
  activemodel
7
7
  activerecord
data/README.md CHANGED
@@ -1,4 +1,8 @@
1
- # Riveter [![Build Status](https://secure.travis-ci.org/virtualstaticvoid/riveter.png?branch=master)](http://travis-ci.org/virtualstaticvoid/riveter) [![Code Climate](https://codeclimate.com/github/virtualstaticvoid/riveter.png)](https://codeclimate.com/github/virtualstaticvoid/riveter)
1
+ # Riveter
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/riveter.svg)](http://badge.fury.io/rb/riveter)
4
+ [![Build Status](https://secure.travis-ci.org/virtualstaticvoid/riveter.png?branch=master)](http://travis-ci.org/virtualstaticvoid/riveter)
5
+ [![Code Climate](https://codeclimate.com/github/virtualstaticvoid/riveter.png)](https://codeclimate.com/github/virtualstaticvoid/riveter)
2
6
 
3
7
  Provides several useful patterns, packaged in a gem, for use in Rails.
4
8
  Includes generators to help you improve consistency in your applications.
@@ -0,0 +1,2 @@
1
+ module Riveter
2
+ end
@@ -4,7 +4,7 @@ module Riveter
4
4
  query_filter_class_name = query_filter.class.name.underscore
5
5
  options = {
6
6
  :as => query_filter_class_name.gsub(/_query_filter$/, ''),
7
- :url => query_filter_class_name,
7
+ :url => query_filter_class_name.gsub(/_query_filter$/, ''),
8
8
  :method => :get
9
9
  }.merge(options)
10
10
 
@@ -37,7 +37,7 @@ module Haml
37
37
  when :integer, :decimal, :boolean, :date, :time, :datetime
38
38
  ", :as => :#{type}"
39
39
  when :enum
40
- ", :collection => #{name.titleize}.collection"
40
+ ", :collection => #{name.titleize}Enum.collection"
41
41
  when :model
42
42
  ", :collection => #{name.titleize}.all"
43
43
  else
@@ -37,7 +37,7 @@ module Haml
37
37
  when :integer, :decimal, :boolean, :date, :time, :datetime
38
38
  ", :as => :#{type}"
39
39
  when :enum
40
- ", :collection => #{name.titleize}.collection"
40
+ ", :collection => #{name.titleize}Enum.collection"
41
41
  when :model
42
42
  ", :collection => #{name.titleize}.all"
43
43
  else
@@ -14,6 +14,11 @@ module Riveter
14
14
 
15
15
  check_class_collision :suffix => 'Enquiry'
16
16
 
17
+ argument :filter_attributes,
18
+ :type => :array,
19
+ :default => [],
20
+ :banner => "[attribute[:type[:required]] attribute[:type[:required]]]"
21
+
17
22
  def create_enquiry_file
18
23
  template 'enquiry.rb', File.join('app/enquiries', class_path, "#{file_name}_enquiry.rb")
19
24
  end
@@ -16,7 +16,7 @@ module Riveter
16
16
  end
17
17
 
18
18
  def create_enum_file
19
- template 'enum.rb', File.join('app/enums', class_path, "#{file_name}.rb")
19
+ template 'enum.rb', File.join('app/enums', class_path, "#{file_name}_enum.rb")
20
20
  end
21
21
 
22
22
  def create_module_file
@@ -21,7 +21,7 @@ module Riveter
21
21
 
22
22
  def create_module_file
23
23
  return if regular_class_path.empty?
24
- template 'module.rb', File.join('app/enums', "#{class_path.join('/')}.rb") if behavior == :invoke
24
+ template 'module.rb', File.join('app/query_filters', "#{class_path.join('/')}.rb") if behavior == :invoke
25
25
  end
26
26
 
27
27
  def create_locale_file
@@ -1,13 +1,6 @@
1
1
  module Riveter
2
2
  class BooleanessValidator < ActiveModel::EachValidator
3
- def initialize(options)
4
- @allow_nil, @allow_blank = options.delete(:allow_nil), options.delete(:allow_blank)
5
- super
6
- end
7
-
8
3
  def validate_each(record, attribute, value)
9
- return if (@allow_nil && value.nil?) || (@allow_blank && value.blank?)
10
-
11
4
  unless [true, false].include?(value)
12
5
  record.errors.add(attribute, :booleaness, :value => value)
13
6
  end
@@ -1,3 +1,3 @@
1
1
  module Riveter
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples_for "a generator with locale file output" do |file_name|
4
+ describe "the generated files" do
5
+ describe "the #{file_name}.en.yml" do
6
+ describe "creates when missing" do
7
+ before do
8
+ run_generator %w(foo_bar)
9
+ end
10
+
11
+ subject { file("config/locales/#{file_name}.en.yml") }
12
+
13
+ it { should exist }
14
+ it { should contain("#{file_name}:") }
15
+ end
16
+
17
+ describe "skips when exists" do
18
+ before do
19
+ FileUtils.mkdir_p(file('config/locales'))
20
+ File.open(file("config/locales/#{file_name}.en.yml"), 'w') {|f| f.write 'untouched' }
21
+ run_generator %w(foo_bar)
22
+ end
23
+
24
+ subject { file("config/locales/#{file_name}.en.yml") }
25
+
26
+ it { should exist }
27
+ it { should contain('untouched')}
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ shared_examples_for "a generator with output to routes" do |route|
34
+ describe "the generated files" do
35
+ describe "the route" do
36
+ before do
37
+ run_generator %w(foo_bar)
38
+ end
39
+
40
+ subject { file('config/routes.rb') }
41
+
42
+ it { should contain(route) }
43
+ end
44
+ end
45
+ end
46
+
47
+ shared_examples_for "a generator with a module" do |path|
48
+ describe "the module" do
49
+ before do
50
+ run_generator %w(test_ns/foo_bar)
51
+ end
52
+
53
+ subject { file("#{path}/test_ns.rb") }
54
+
55
+ it { should exist }
56
+ end
57
+ end
@@ -2,33 +2,52 @@ require 'spec_helper'
2
2
  require 'generators/haml/command_controller/command_controller_generator'
3
3
 
4
4
  describe Haml::Generators::CommandControllerGenerator, :type => :generator do
5
- it "creates the view with defaults" do
6
- gen = generator %w(create_something)
5
+ it "should run all tasks in the generator" do
6
+ gen = generator %w(foo_bar)
7
7
  expect(gen).to receive(:create_template_file)
8
8
  capture(:stdout) { gen.invoke_all }
9
9
  end
10
10
 
11
- it "creates the view with specified action name" do
12
- gen = generator %w(create_something create)
13
- expect(gen).to receive(:create_template_file)
14
- capture(:stdout) { gen.invoke_all }
15
- end
11
+ describe "the generated files" do
12
+ describe "the view" do
13
+ describe "with defaults" do
14
+ before do
15
+ run_generator %w(foo_bar)
16
+ end
16
17
 
17
- it "creates the view with specified action name and attributes" do
18
- gen = generator %w(create_something create name:string:required active:boolean other)
19
- expect(gen).to receive(:create_template_file)
20
- capture(:stdout) { gen.invoke_all }
21
- end
18
+ subject { file('app/views/foo_bar_command/new.html.haml') }
22
19
 
23
- describe "the generated files" do
24
- before do
25
- run_generator %w(create_something create name:string:required active:boolean other)
26
- end
20
+ it { should exist }
21
+ it { should contain('= command_form_for') }
22
+ end
27
23
 
28
- describe "the view" do
29
- subject { file('app/views/create_something_command/create.html.haml') }
24
+ describe "with specified action name" do
25
+ before do
26
+ run_generator %w(foo_bar create)
27
+ end
28
+
29
+ subject { file('app/views/foo_bar_command/create.html.haml') }
30
+
31
+ it { should exist }
32
+ it { should contain('= command_form_for') }
33
+ end
34
+
35
+ describe "with specified action name and attributes" do
36
+ before do
37
+ run_generator %w(foo_bar baz qux:string quux:string:required corge:enum grault:boolean garply:model other)
38
+ end
39
+
40
+ subject { file('app/views/foo_bar_command/baz.html.haml') }
30
41
 
31
- it { should exist }
42
+ it { should exist }
43
+ it { should contain('= command_form_for') }
44
+ it { should contain('= f.input :qux') }
45
+ it { should contain('= f.input :quux') }
46
+ it { should contain('= f.input :corge, :collection => CorgeEnum.collection') }
47
+ it { should contain('= f.input :grault') }
48
+ it { should contain('= f.input :garply, :collection => Garply.all') }
49
+ it { should contain('= f.input :other') }
50
+ end
32
51
  end
33
52
  end
34
53
  end
@@ -2,33 +2,52 @@ require 'spec_helper'
2
2
  require 'generators/haml/enquiry_controller/enquiry_controller_generator'
3
3
 
4
4
  describe Haml::Generators::EnquiryControllerGenerator, :type => :generator do
5
- it "creates the view with defaults" do
6
- gen = generator %w(list_something)
5
+ it "should run all tasks in the generator" do
6
+ gen = generator %w(foo_bar)
7
7
  expect(gen).to receive(:create_template_file)
8
8
  capture(:stdout) { gen.invoke_all }
9
9
  end
10
10
 
11
- it "creates the view with specified action name" do
12
- gen = generator %w(list_something list)
13
- expect(gen).to receive(:create_template_file)
14
- capture(:stdout) { gen.invoke_all }
15
- end
11
+ describe "the generated files" do
12
+ describe "the view" do
13
+ describe "with defaults" do
14
+ before do
15
+ run_generator %w(foo_bar)
16
+ end
16
17
 
17
- it "creates the view with specified action name and attributes" do
18
- gen = generator %w(list_something list name:string:required active:boolean other)
19
- expect(gen).to receive(:create_template_file)
20
- capture(:stdout) { gen.invoke_all }
21
- end
18
+ subject { file('app/views/foo_bar_enquiry/index.html.haml') }
22
19
 
23
- describe "the generated files" do
24
- before do
25
- run_generator %w(list_something list name:string:required active:boolean other)
26
- end
20
+ it { should exist }
21
+ it { should contain('= enquiry_form_for') }
22
+ end
27
23
 
28
- describe "the view" do
29
- subject { file('app/views/list_something_enquiry/list.html.haml') }
24
+ describe "with specified action name" do
25
+ before do
26
+ run_generator %w(foo_bar baz)
27
+ end
28
+
29
+ subject { file('app/views/foo_bar_enquiry/baz.html.haml') }
30
+
31
+ it { should exist }
32
+ it { should contain('= enquiry_form_for') }
33
+ end
34
+
35
+ describe "with specified action name and attributes" do
36
+ before do
37
+ run_generator %w(foo_bar baz qux:string quux:string:required corge:enum grault:boolean garply:model other)
38
+ end
39
+
40
+ subject { file('app/views/foo_bar_enquiry/baz.html.haml') }
30
41
 
31
- it { should exist }
42
+ it { should exist }
43
+ it { should contain('= enquiry_form_for') }
44
+ it { should contain('= f.input :qux') }
45
+ it { should contain('= f.input :quux') }
46
+ it { should contain('= f.input :corge, :collection => CorgeEnum.collection') }
47
+ it { should contain('= f.input :grault') }
48
+ it { should contain('= f.input :garply, :collection => Garply.all') }
49
+ it { should contain('= f.input :other') }
50
+ end
32
51
  end
33
52
  end
34
53
  end
@@ -1,58 +1,54 @@
1
1
  require 'spec_helper'
2
2
  require 'generators/riveter/command/command_generator'
3
- require 'fileutils'
4
3
 
5
4
  describe Riveter::Generators::CommandGenerator, :type => :generator do
6
- it "creates the command with defaults" do
7
- gen = generator %w(create_something --no-command-controller)
8
- expect(gen).to receive(:create_command_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 command with specified attributes" do
13
- gen = generator %w(create_something name:string:required active:boolean other --no-command-controller)
10
+ it "should run all tasks in the generator" do
11
+ gen = generator %w(foo_bar)
14
12
  expect(gen).to receive(:create_command_file)
15
- capture(:stdout) { gen.invoke_all }
16
- end
17
-
18
- it "creates a module file" do
19
- gen = generator %w(test_ns/create_something name:string:required active:boolean other --no-command-controller)
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(create_something --no-command-controller)
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_command_controller)
18
+ expect(gen).to receive(:_invoke_from_option_test_framework)
19
+
20
+ capture(:stdout) { gen.invoke_all }
32
21
  end
33
22
 
34
23
  describe "the generated files" do
35
24
  describe "the command" do
36
- before do
37
- run_generator %w(create_something name:string:required active:boolean other --no-command-controller)
38
- end
25
+ describe "with defaults" do
26
+ before do
27
+ run_generator %w(foo_bar)
28
+ end
39
29
 
40
- subject { file('app/commands/create_something_command.rb') }
30
+ subject { file('app/commands/foo_bar_command.rb') }
41
31
 
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/commands.en.yml'), 'w') {|f| f.write 'empty' }
49
- run_generator %w(create_something name:string:required active:boolean other --no-command-controller)
32
+ it { should exist }
33
+ it { should contain('class FooBarCommand') }
50
34
  end
51
35
 
52
- subject { file('config/locales/commands.en.yml') }
36
+ describe "with attributes" do
37
+ before do
38
+ run_generator %w(foo_bar name:string:required active:boolean other)
39
+ end
40
+
41
+ subject { file('app/commands/foo_bar_command.rb') }
53
42
 
54
- it { should exist }
55
- it { File.open(file('config/locales/commands.en.yml'), 'r') {|f| f.read }.should eq('empty') }
43
+ it { should exist }
44
+ it { should contain('class FooBarCommand') }
45
+ it { should contain('attr_string :name, :required => true') }
46
+ it { should contain('attr_boolean :active') }
47
+ it { should contain('attr_string :other') }
48
+ end
56
49
  end
50
+
51
+ it_should_behave_like 'a generator with a module', 'app/commands'
52
+ it_should_behave_like 'a generator with locale file output', 'commands'
57
53
  end
58
54
  end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+ require 'generators/riveter/command_controller/command_controller_generator'
3
+
4
+ describe Riveter::Generators::CommandControllerGenerator, :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_command_controller_file)
13
+ expect(gen).to receive(:create_module_file)
14
+ expect(gen).to receive(:add_command_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_command_controller.rb') }
31
+
32
+ it { should exist }
33
+ it { should contain('command_controller_for FooBarCommand') }
34
+ end
35
+
36
+ describe "with action names" do
37
+ before do
38
+ run_generator %w(foo_bar start doit)
39
+ end
40
+
41
+ subject { file('app/controllers/foo_bar_command_controller.rb') }
42
+
43
+ it { should exist }
44
+ it { should contain('command_controller_for FooBarCommand, :new_action => :start, :create_action => :doit') }
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', 'command :foo_bar'
50
+ end
51
+ end