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,52 @@
|
|
|
1
|
+
module Riveter
|
|
2
|
+
module Generators
|
|
3
|
+
class QueryFilterGenerator < ::Rails::Generators::NamedBase
|
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
5
|
+
|
|
6
|
+
check_class_collision :suffix => 'QueryFilter'
|
|
7
|
+
|
|
8
|
+
argument :filter_attributes,
|
|
9
|
+
:type => :array,
|
|
10
|
+
:default => [],
|
|
11
|
+
:banner => "[attribute[:type[:required]] attribute[:type[:required]]]"
|
|
12
|
+
|
|
13
|
+
def initialize(args, *options)
|
|
14
|
+
super
|
|
15
|
+
parse_filter_attributes!
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def create_query_filter_file
|
|
19
|
+
template 'query_filter.rb', File.join('app/query_filters', class_path, "#{file_name}_query_filter.rb")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def create_module_file
|
|
23
|
+
return if regular_class_path.empty?
|
|
24
|
+
template 'module.rb', File.join('app/enums', "#{class_path.join('/')}.rb") if behavior == :invoke
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def create_locale_file
|
|
28
|
+
template 'query_filters.en.yml', File.join('config/locales', 'query_filters.en.yml') unless locale_file_exists?
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
hook_for :test_framework, :as => :query_filter
|
|
32
|
+
|
|
33
|
+
protected
|
|
34
|
+
|
|
35
|
+
def parse_filter_attributes!
|
|
36
|
+
self.filter_attributes = (filter_attributes || []).map do |attribute|
|
|
37
|
+
# expected in the form "name", "name:type" or "name:type:required"
|
|
38
|
+
parts = attribute.split(':')
|
|
39
|
+
OpenStruct.new(
|
|
40
|
+
:name => parts.first.underscore,
|
|
41
|
+
:type => ((parts.length > 1) ? parts[1] : 'string'),
|
|
42
|
+
:inject_options => ((parts.length == 3 && parts[2] == 'required') ? ', :required => true' : '')
|
|
43
|
+
)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def locale_file_exists?
|
|
48
|
+
File.exists?(File.join(destination_root, 'config', 'locales', 'query_filters.en.yml'))
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<% module_namespacing do -%>
|
|
2
|
+
class <%= class_name %>QueryFilter < Riveter::QueryFilter::Base
|
|
3
|
+
<% if filter_attributes.any? %>
|
|
4
|
+
<% filter_attributes.each do |attribute| -%>
|
|
5
|
+
attr_<%= attribute.type %> :<%= attribute.name %><%= attribute.inject_options %>
|
|
6
|
+
<% end -%>
|
|
7
|
+
<% else -%>
|
|
8
|
+
|
|
9
|
+
#
|
|
10
|
+
# define filter attributes
|
|
11
|
+
#
|
|
12
|
+
# E.g.
|
|
13
|
+
#
|
|
14
|
+
# attr_string :name[, options]
|
|
15
|
+
#
|
|
16
|
+
# options include:
|
|
17
|
+
# :required => true|false # default is false
|
|
18
|
+
# :default => 'a value' # default is nil
|
|
19
|
+
# :validate => true|false # default is true
|
|
20
|
+
#
|
|
21
|
+
# supported attributes:
|
|
22
|
+
#
|
|
23
|
+
# attr_string
|
|
24
|
+
# attr_text
|
|
25
|
+
# attr_integer
|
|
26
|
+
# attr_decimal
|
|
27
|
+
# attr_date
|
|
28
|
+
# attr_time
|
|
29
|
+
# attr_boolean
|
|
30
|
+
# attr_enum
|
|
31
|
+
# attr_array
|
|
32
|
+
# attr_hash
|
|
33
|
+
# attr_model
|
|
34
|
+
#
|
|
35
|
+
|
|
36
|
+
# optionally, define additional validations
|
|
37
|
+
<% end -%>
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
<% end -%>
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Files in the config/locales directory are used for internationalization
|
|
2
|
+
# and are automatically loaded by Rails. If you want to use locales other
|
|
3
|
+
# than English, add the necessary files in this directory.
|
|
4
|
+
#
|
|
5
|
+
# To use the locales, use `I18n.t`:
|
|
6
|
+
#
|
|
7
|
+
# I18n.t 'hello'
|
|
8
|
+
#
|
|
9
|
+
# In views, this is aliased to just `t`:
|
|
10
|
+
#
|
|
11
|
+
# <%%= t('hello') %>
|
|
12
|
+
#
|
|
13
|
+
# To use a different locale, set it with `I18n.locale`:
|
|
14
|
+
#
|
|
15
|
+
# I18n.locale = :es
|
|
16
|
+
#
|
|
17
|
+
# This would use the information in config/locales/es.yml.
|
|
18
|
+
#
|
|
19
|
+
# To learn more, please read the Rails Internationalization guide
|
|
20
|
+
# available at http://guides.rubyonrails.org/i18n.html.
|
|
21
|
+
|
|
22
|
+
en:
|
|
23
|
+
|
|
24
|
+
# shared attribute translations (NB: across all objects!)
|
|
25
|
+
attributes:
|
|
26
|
+
|
|
27
|
+
#
|
|
28
|
+
# E.g. shared "name" attribute
|
|
29
|
+
#
|
|
30
|
+
|
|
31
|
+
name: Name
|
|
32
|
+
|
|
33
|
+
# translations for query_filters
|
|
34
|
+
query_filters:
|
|
35
|
+
|
|
36
|
+
models:
|
|
37
|
+
|
|
38
|
+
#
|
|
39
|
+
# E.g. for ExampleQueryFilter as follows
|
|
40
|
+
#
|
|
41
|
+
example: Example Query Filter Name
|
|
42
|
+
|
|
43
|
+
attributes:
|
|
44
|
+
|
|
45
|
+
#
|
|
46
|
+
# E.g. for attributes of the ExampleQueryFilter as follows
|
|
47
|
+
#
|
|
48
|
+
example:
|
|
49
|
+
active_only: Active items only?
|
|
File without changes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Riveter
|
|
2
|
+
module Generators
|
|
3
|
+
class ServiceGenerator < ::Rails::Generators::NamedBase
|
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
5
|
+
|
|
6
|
+
check_class_collision :suffix => 'Service'
|
|
7
|
+
|
|
8
|
+
def create_service_file
|
|
9
|
+
template 'service.rb', File.join('app/services', class_path, "#{file_name}_service.rb")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def create_module_file
|
|
13
|
+
return if regular_class_path.empty?
|
|
14
|
+
template 'module.rb', File.join('app/services', "#{class_path.join('/')}.rb") if behavior == :invoke
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
hook_for :test_framework, :as => :service
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<% module_namespacing do -%>
|
|
2
|
+
class <%= class_name %>Service < Riveter::Service::Base
|
|
3
|
+
|
|
4
|
+
# associate this handler with the respective command
|
|
5
|
+
register_as_handler_for <%= class_name %>Command
|
|
6
|
+
|
|
7
|
+
def perform(command)
|
|
8
|
+
# TODO: provide implementation
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
end
|
|
12
|
+
<% end -%>
|
|
File without changes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Riveter
|
|
2
|
+
module Generators
|
|
3
|
+
class WorkerGenerator < ::Rails::Generators::NamedBase
|
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
5
|
+
|
|
6
|
+
check_class_collision :suffix => 'Worker'
|
|
7
|
+
|
|
8
|
+
def create_worker_file
|
|
9
|
+
template 'worker.rb', File.join('app/workers', class_path, "#{file_name}_worker.rb")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def create_module_file
|
|
13
|
+
return if regular_class_path.empty?
|
|
14
|
+
template 'module.rb', File.join('app/workers', "#{class_path.join('/')}.rb") if behavior == :invoke
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
hook_for :test_framework, :as => :worker
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module Rspec
|
|
2
|
+
module Generators
|
|
3
|
+
class CommandGenerator < ::Rails::Generators::NamedBase
|
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
5
|
+
|
|
6
|
+
def create_command_spec
|
|
7
|
+
template 'command_spec.rb', File.join('spec/commands', class_path, "#{file_name}_command_spec.rb")
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Rspec
|
|
2
|
+
module Generators
|
|
3
|
+
class CommandControllerGenerator < ::Rails::Generators::NamedBase
|
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
5
|
+
|
|
6
|
+
argument :new_action,
|
|
7
|
+
:type => :string,
|
|
8
|
+
:default => 'new',
|
|
9
|
+
:banner => 'new_action'
|
|
10
|
+
|
|
11
|
+
argument :create_action,
|
|
12
|
+
:type => :string,
|
|
13
|
+
:default => 'create',
|
|
14
|
+
:banner => 'create_action'
|
|
15
|
+
|
|
16
|
+
def create_command_controller_spec
|
|
17
|
+
template 'command_controller_spec.rb', File.join('spec/controllers', class_path, "#{file_name}_command_controller_spec.rb")
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'riveter/spec_helper'
|
|
3
|
+
|
|
4
|
+
describe <%= class_name %>CommandController do
|
|
5
|
+
render_views
|
|
6
|
+
|
|
7
|
+
# This should return the minimal set of attributes required to create a valid
|
|
8
|
+
# <%= class_name %>Command. As you add validations to <%= class_name %>Command, be sure to
|
|
9
|
+
# adjust the attributes here as well.
|
|
10
|
+
let(:valid_attributes) { {} }
|
|
11
|
+
|
|
12
|
+
# This should return the minimal set of values that should be in the session
|
|
13
|
+
# in order to pass any filters (e.g. authentication) defined in
|
|
14
|
+
# <%= class_name %>CommandController. Be sure to keep this updated too.
|
|
15
|
+
let(:valid_session) { {} }
|
|
16
|
+
|
|
17
|
+
describe "GET '<%= new_action %>'" do
|
|
18
|
+
it "assigns the command" do
|
|
19
|
+
get :<%= new_action %>, {}, valid_session
|
|
20
|
+
assigns(:command).should eq(<%= class_name %>Command.new())
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "renders the '<%= new_action %>' template" do
|
|
24
|
+
get :<%= new_action %>, {}, valid_session
|
|
25
|
+
response.should render_template(:<%= new_action %>)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe "POST '<%= create_action %>'" do
|
|
30
|
+
describe "with valid params" do
|
|
31
|
+
it "assigns the command" do
|
|
32
|
+
post :<%= create_action %>, {:<%= file_name %> => valid_attributes}, valid_session
|
|
33
|
+
assigns(:command).should eq(<%= class_name %>Command.new())
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "invokes the associated service object" do
|
|
37
|
+
post :<%= create_action %>, {:<%= file_name %> => valid_attributes}, valid_session
|
|
38
|
+
|
|
39
|
+
pending
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "invokes the on_success callback" do
|
|
43
|
+
post :<%= create_action %>, {:<%= file_name %> => valid_attributes}, valid_session
|
|
44
|
+
pending
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# TODO: complete specification for on success logic
|
|
48
|
+
it "on_success (redirects to ...)" do
|
|
49
|
+
post :<%= create_action %>, {:<%= file_name %> => valid_attributes}, valid_session
|
|
50
|
+
# response.should redirect_to(...)
|
|
51
|
+
pending
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
describe "with invalid params" do
|
|
56
|
+
it "assigns the command" do
|
|
57
|
+
allow_any_instance_of(<%= class_name %>Command).to receive(:valid?) { false }
|
|
58
|
+
post :<%= create_action %>, {:<%= file_name %> => {}}, valid_session
|
|
59
|
+
assigns(:command).should eq(<%= class_name %>Command.new())
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "re-renders the 'new' template" do
|
|
63
|
+
allow_any_instance_of(<%= class_name %>Command).to receive(:valid?) { false }
|
|
64
|
+
post :<%= create_action %>, {:<%= file_name %> => {}}, valid_session
|
|
65
|
+
response.should render_template(:<%= new_action %>)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module Rspec
|
|
2
|
+
module Generators
|
|
3
|
+
class EnquiryGenerator < ::Rails::Generators::NamedBase
|
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
5
|
+
|
|
6
|
+
def create_enquiry_spec
|
|
7
|
+
template 'enquiry_spec.rb', File.join('spec/enquiries', class_path, "#{file_name}_enquiry_spec.rb")
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'riveter/spec_helper'
|
|
3
|
+
|
|
4
|
+
describe <%= class_name %>Enquiry do
|
|
5
|
+
|
|
6
|
+
before do
|
|
7
|
+
# TODO: setup data required to exercise the enquiry
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# This should return the minimal set of attributes required to create a valid <%= class_name %>QueryFilter.
|
|
11
|
+
let(:valid_query_filter_attributes) { {} }
|
|
12
|
+
|
|
13
|
+
#
|
|
14
|
+
# NOTE: If this spec fails, then all the following ones will fail too!!!
|
|
15
|
+
#
|
|
16
|
+
it "is configured correctly" do
|
|
17
|
+
expect {
|
|
18
|
+
<%= class_name %>Enquiry.new()
|
|
19
|
+
}.to_not raise_error
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe "#submit" do
|
|
23
|
+
it "succeeds with valid attributes" do
|
|
24
|
+
subject.submit(valid_query_filter_attributes).should be_true
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "fails with invalid attributes" do
|
|
28
|
+
allow(subject).to receive(:create_query_filter) { Mock::InvalidQueryFilter.new() }
|
|
29
|
+
subject.submit().should be_false
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe "#has_data?" do
|
|
34
|
+
it "succeeds with valid attributes" do
|
|
35
|
+
subject.submit(valid_query_filter_attributes)
|
|
36
|
+
subject.has_data?.should be_true
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "fails with invalid attributes" do
|
|
40
|
+
allow(subject).to receive(:create_query_filter) { Mock::InvalidQueryFilter.new() }
|
|
41
|
+
subject.submit()
|
|
42
|
+
subject.has_data?.should be_false
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
describe "#query_results" do
|
|
47
|
+
it "succeeds with valid attributes" do
|
|
48
|
+
subject.submit(valid_query_filter_attributes)
|
|
49
|
+
subject.query_results.should_not be_nil
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "can be iterated" do
|
|
53
|
+
block = Mock::Block.new()
|
|
54
|
+
expect(block).to receive(:call).any_number_of_times
|
|
55
|
+
|
|
56
|
+
subject.submit(valid_query_filter_attributes)
|
|
57
|
+
subject.query_results.each &block
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "fails with invalid attributes" do
|
|
61
|
+
allow(subject).to receive(:create_query_filter) { Mock::InvalidQueryFilter.new() }
|
|
62
|
+
subject.submit()
|
|
63
|
+
subject.query_results.should be_nil
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
pending "add some examples to (or delete) #{__FILE__}"
|
|
68
|
+
|
|
69
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module Rspec
|
|
2
|
+
module Generators
|
|
3
|
+
class EnquiryControllerGenerator < ::Rails::Generators::NamedBase
|
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
5
|
+
|
|
6
|
+
argument :action_name,
|
|
7
|
+
:type => :string,
|
|
8
|
+
:default => 'index',
|
|
9
|
+
:banner => 'action_name'
|
|
10
|
+
|
|
11
|
+
def create_enquiry_controller_spec
|
|
12
|
+
template 'enquiry_controller_spec.rb', File.join('spec/controllers', class_path, "#{file_name}_enquiry_controller_spec.rb")
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'riveter/spec_helper'
|
|
3
|
+
|
|
4
|
+
describe <%= class_name %>EnquiryController do
|
|
5
|
+
render_views
|
|
6
|
+
|
|
7
|
+
# This should return the minimal set of attributes required to create a valid <%= class_name %>QueryFilter.
|
|
8
|
+
let(:valid_query_filter_attributes) { {} }
|
|
9
|
+
|
|
10
|
+
# This should return the minimal set of values that should be in the session
|
|
11
|
+
# in order to pass any filters (e.g. authentication) defined in
|
|
12
|
+
# <%= class_name %>EnquiryController. Be sure to keep this updated.
|
|
13
|
+
let(:valid_session) { {} }
|
|
14
|
+
|
|
15
|
+
describe "GET '<%= action_name %>'" do
|
|
16
|
+
it "assigns the enquiry" do
|
|
17
|
+
get :<%= action_name %>, {}, valid_session
|
|
18
|
+
assigns(:enquiry).should eq(<%= class_name %>Enquiry.new())
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe "POST '<%= action_name %>'" do
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
pending "add some examples to (or delete) #{__FILE__}"
|
|
31
|
+
|
|
32
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module Rspec
|
|
2
|
+
module Generators
|
|
3
|
+
class EnumGenerator < ::Rails::Generators::NamedBase
|
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
5
|
+
|
|
6
|
+
def create_enum_spec
|
|
7
|
+
template 'enum_spec.rb', File.join('spec/enums', class_path, "#{file_name}_enum_spec.rb")
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module Rspec
|
|
2
|
+
module Generators
|
|
3
|
+
class PresenterGenerator < ::Rails::Generators::NamedBase
|
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
5
|
+
|
|
6
|
+
def create_presenter_spec
|
|
7
|
+
template 'presenter_spec.rb', File.join('spec/presenters', class_path, "#{file_name}_presenter_spec.rb")
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module Rspec
|
|
2
|
+
module Generators
|
|
3
|
+
class QueryGenerator < ::Rails::Generators::NamedBase
|
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
5
|
+
|
|
6
|
+
def create_query_spec
|
|
7
|
+
template 'query_spec.rb', File.join('spec/queries', class_path, "#{file_name}_query_spec.rb")
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'riveter/spec_helper'
|
|
3
|
+
|
|
4
|
+
describe <%= class_name %>Query do
|
|
5
|
+
|
|
6
|
+
context "with data" do
|
|
7
|
+
before do
|
|
8
|
+
# TODO: create fixture data
|
|
9
|
+
FactoryGirl.create_list :<%= class_name.underscore %>, 10
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
let(:filter) { OpenStruct.new() }
|
|
13
|
+
subject { <%= class_name %>Query.new(filter) }
|
|
14
|
+
|
|
15
|
+
it { subject.relation.should_not be_nil }
|
|
16
|
+
it { subject.has_data?.should be_true }
|
|
17
|
+
it {
|
|
18
|
+
block = Mock::Block.new
|
|
19
|
+
expect(block).to receive(:call).at_least(:once)
|
|
20
|
+
subject.find_each &block
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
context "without data" do
|
|
26
|
+
let(:filter) { OpenStruct.new() }
|
|
27
|
+
subject { <%= class_name %>Query.new(filter) }
|
|
28
|
+
|
|
29
|
+
it { subject.relation.should_not be_nil }
|
|
30
|
+
it { subject.has_data?.should be_false }
|
|
31
|
+
it {
|
|
32
|
+
block = Mock::Block.new
|
|
33
|
+
expect(block).to_not receive(:call)
|
|
34
|
+
subject.find_each &block
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
pending "add some examples to (or delete) #{__FILE__}"
|
|
40
|
+
|
|
41
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module Rspec
|
|
2
|
+
module Generators
|
|
3
|
+
class QueryFilterGenerator < ::Rails::Generators::NamedBase
|
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
5
|
+
|
|
6
|
+
def create_query_filter_spec
|
|
7
|
+
template 'query_filter_spec.rb', File.join('spec/query_filters', class_path, "#{file_name}_query_filter_spec.rb")
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module Rspec
|
|
2
|
+
module Generators
|
|
3
|
+
class ServiceGenerator < ::Rails::Generators::NamedBase
|
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
5
|
+
|
|
6
|
+
def create_service_spec
|
|
7
|
+
template 'service_spec.rb', File.join('spec/services', class_path, "#{file_name}_service_spec.rb")
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
File without changes
|