regressor 0.5.8 → 0.6.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bfdcab4e5984a23cebaa698fe65888d2e9133cac
4
- data.tar.gz: 11333c03404c2d9744abc14eb11f317d3d0dec96
3
+ metadata.gz: 3ccfb10d1fd8a5fdc9ad01688d0467054945c949
4
+ data.tar.gz: dd774a46ce48e915590195e0044947cc36231240
5
5
  SHA512:
6
- metadata.gz: 4acccb1b860384c10200da8c5c38da8f21700a6d7245866971de24d40be9aaf27c9ebfcc8d0fd863d51ad5d980e0d24a490c6cbd5b337d1b876e4da4ed012593
7
- data.tar.gz: ed378bf13882af17043aec5f78ee22fa314802a9629a082d19b3fb7a1f7f00f8a0b60231c09c7768f30b2c80972f49029b234025f21928dfb96434df290ddf4f
6
+ metadata.gz: 514cf199208a5835383a4ae2cb034510b55f1507a87953ea0339e3b00180501ac7eeefe5de6cf88dc5fc74357fb84d27228867dfba17377a58bcf04d0b1b4873
7
+ data.tar.gz: 51080b07d9aeece110b6fa6bb7b66c6bd57f7abf06d35bd19973c4eb05ff607acfcd7dd2f269c017b619f533edd0ee7dec799a5307660607ca94fc260b8dfd7e
@@ -4,7 +4,7 @@ module Regressor
4
4
  module AfterFilter
5
5
  def after_callbacks
6
6
  after_filters.map do |filter_name|
7
- "it { should use_after_filter(:#{filter_name}) }"
7
+ "it { should use_after_filter(#{filter_name}) }"
8
8
  end.compact.uniq.join("\n ")
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ module Regressor
4
4
  module AroundFilter
5
5
  def around_callbacks
6
6
  around_filters.map do |filter_name|
7
- "it { should use_around_filter(:#{filter_name}) }"
7
+ "it { should use_around_filter(#{filter_name}) }"
8
8
  end.compact.uniq.join("\n ")
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ module Regressor
4
4
  module BeforeFilter
5
5
  def before_callbacks
6
6
  before_filters.map do |filter_name|
7
- "it { should use_before_filter(:#{filter_name}) }"
7
+ "it { should use_before_filter(#{filter_name}) }"
8
8
  end.compact.uniq.join("\n ")
9
9
  end
10
10
  end
@@ -20,7 +20,8 @@ module Regressor
20
20
  all_filters = controller._process_action_callbacks
21
21
  all_filters = all_filters.select { |f| f.kind == kind } if kind
22
22
  # Reject procs
23
- all_filters.map(&:raw_filter).reject{|filter| filter.class == Proc}
23
+ all_filters = all_filters.map(&:raw_filter).reject{|filter| filter.class == Proc}
24
+ all_filters.map {|filter| filter.is_a?(Symbol) ? ":#{filter}" : filter.to_s}
24
25
  end
25
26
  end
26
27
  end
@@ -0,0 +1,45 @@
1
+ require 'model/factory_model'
2
+
3
+ module Regressor
4
+ class FactoryGenerator < Rails::Generators::Base
5
+ source_root(File.expand_path(File.dirname(__FILE__)))
6
+
7
+ def create_regression_files
8
+ load_application
9
+ generate_factories
10
+ end
11
+
12
+ private
13
+
14
+ def generate_factories
15
+ load_ar_models.each do |model|
16
+ save_generate(model) do
17
+ @model = ::Regressor::Model::FactoryModel.new(model)
18
+ create_file "#{Regressor.configuration.regression_factory_path}/#{model.underscore.singularize}_factory.rb",
19
+ ERB.new(File.new(File.expand_path('../../templates/factory/factory_template.erb', File.dirname(__FILE__))).read).result(binding)
20
+ end
21
+ end
22
+ end
23
+
24
+ def load_application
25
+ Rails.application.try(:eager_load!)
26
+ end
27
+
28
+ def load_ar_models
29
+ if defined?(::ActiveRecord::Base)
30
+ ActiveRecord::Base.descendants.map(&:name).reject { |x| Regressor.configuration.excluded_models.include? x }
31
+ else
32
+ []
33
+ end
34
+ end
35
+
36
+ def save_generate(model)
37
+ begin
38
+ yield
39
+ rescue => e
40
+ puts "Cannot create factory for #{model}. Reason #{e.message}"
41
+ end
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,31 @@
1
+ module Regressor
2
+ module Model
3
+ module Validation
4
+ def wrap_conditional_validations validator, specs
5
+ if_mock = if_condition_mock validator
6
+ unless_mock = unless_condition_mock validator
7
+ padding = if_mock.blank? && unless_mock.blank? ? '' : ' '
8
+ specs = specs.map do |spec|
9
+ "#{padding}#{spec}"
10
+ end.uniq.join("\n ")
11
+ if if_mock.blank? && unless_mock.blank?
12
+ specs
13
+ else
14
+ "context \"with conditions\" do\n before do\n#{if_mock}#{unless_mock} end\n\n#{specs}\n end\n"
15
+ end
16
+ end
17
+
18
+ def if_condition_mock validator
19
+ if_condition = validator.options[:if]
20
+ return '' unless if_condition && if_condition.is_a?(Symbol)
21
+ " allow(subject).to receive(:#{if_condition.to_s}).and_return(true)\n"
22
+ end
23
+
24
+ def unless_condition_mock validator
25
+ unless_condition = validator.options[:unless]
26
+ return '' unless unless_condition && unless_condition.is_a?(Symbol)
27
+ " allow(subject).to receive(:#{unless_condition.to_s}).and_return(false)\n"
28
+ end
29
+ end
30
+ end
31
+ end
@@ -3,23 +3,24 @@ module Regressor
3
3
  module Validation
4
4
  module Length
5
5
  def length_validators
6
- extract_validators(::ActiveModel::Validations::LengthValidator).inject([]) do |result, validator|
7
- result << generate_length_examples(validator, validator.options[:minimum]-1, validator.options[:minimum]) if validator.options[:minimum]
8
- result << generate_length_examples(validator, validator.options[:maximum] + 1, validator.options[:maximum]) if validator.options[:maximum]
9
- result
10
- end.flatten.compact.uniq.join("\n ")
6
+ extract_validators(::ActiveModel::Validations::LengthValidator).flatten.map do |validator|
7
+ specs = []
8
+ specs.concat generate_length_examples(validator, validator.options[:minimum]-1, validator.options[:minimum]) if validator.options[:minimum]
9
+ specs.concat generate_length_examples(validator, validator.options[:maximum] + 1, validator.options[:maximum]) if validator.options[:maximum]
10
+ wrap_conditional_validations validator, specs.flatten.compact.uniq
11
+ end.join("\n ")
11
12
  end
12
13
 
13
14
  private
14
15
 
15
16
  def generate_length_examples(validator, upper_bound, lower_bound)
16
- validator.attributes.inject([]) do |result, attribute|
17
- result << "it { is_expected.to allow_value(Faker::Lorem.characters(#{lower_bound})).for :#{attribute} }"
18
- result << "it { is_expected.not_to allow_value(Faker::Lorem.characters(#{upper_bound})).for :#{attribute} }"
19
- result
17
+ validator.attributes.map do |attribute|
18
+ [
19
+ "it { is_expected.to allow_value(Faker::Lorem.characters(#{lower_bound})).for :#{attribute} }",
20
+ "it { is_expected.not_to allow_value(Faker::Lorem.characters(#{upper_bound})).for :#{attribute} }"
21
+ ]
20
22
  end
21
23
  end
22
-
23
24
  end
24
25
  end
25
26
  end
@@ -3,14 +3,15 @@ module Regressor
3
3
  module Validation
4
4
  module Numericality
5
5
  def numericality_validators
6
- extract_validators(::ActiveModel::Validations::NumericalityValidator).inject([]) do |result, validator|
6
+ extract_validators(::ActiveModel::Validations::NumericalityValidator).flatten.map do |validator|
7
+ specs = []
7
8
  if validator.options.blank?
8
- result += validator_without_options(validator)
9
+ specs.concat validator_without_options(validator)
9
10
  else
10
- result += validator_with_options(validator)
11
+ specs.concat validator_with_options(validator)
11
12
  end
12
- result
13
- end.uniq.join("\n ")
13
+ wrap_conditional_validations validator, specs.flatten.compact.uniq
14
+ end.join("\n ")
14
15
  end
15
16
 
16
17
  private
@@ -3,9 +3,12 @@ module Regressor
3
3
  module Validation
4
4
  module Presence
5
5
  def presence_validators
6
- extract_validators(::ActiveRecord::Validations::PresenceValidator).map(&:attributes).flatten.map do |attribute|
7
- "it { is_expected.to validate_presence_of :#{attribute} }"
8
- end.uniq.join("\n ")
6
+ extract_validators(::ActiveRecord::Validations::PresenceValidator).flatten.map do |validator|
7
+ specs = validator.attributes.map do |attribute|
8
+ "it { is_expected.to validate_presence_of :#{attribute} }"
9
+ end.uniq
10
+ wrap_conditional_validations validator, specs
11
+ end.join("\n ")
9
12
  end
10
13
  end
11
14
  end
@@ -9,6 +9,8 @@ require_relative 'active_record/database/column'
9
9
  require_relative 'active_record/database/index'
10
10
  require_relative 'active_record/nested/attribute'
11
11
  require_relative 'active_record/enum'
12
+ require_relative 'active_record/validation'
13
+
12
14
 
13
15
  module Regressor
14
16
  module Model
@@ -17,6 +19,7 @@ module Regressor
17
19
  include Relation::BelongTo
18
20
  include Relation::HasOne
19
21
  include Relation::HasMany
22
+ include Validation
20
23
  include Validation::Presence
21
24
  include Validation::Length
22
25
  include Validation::Numericality
@@ -0,0 +1,13 @@
1
+ module Regressor
2
+ module Model
3
+ class FactoryModel
4
+ # === Attribute Accessors ===
5
+ attr_accessor :model
6
+
7
+ # === Methods ===
8
+ def initialize(model)
9
+ @model = model
10
+ end
11
+ end
12
+ end
13
+ end
@@ -11,6 +11,7 @@ module Regressor
11
11
  class Configuration
12
12
  attr_accessor :regression_path,
13
13
  :regression_controller_path,
14
+ :regression_factory_path,
14
15
  :excluded_models,
15
16
  :excluded_controllers,
16
17
  :include_enums
@@ -18,6 +19,7 @@ module Regressor
18
19
  def initialize
19
20
  @regression_path = 'spec/models/regression'
20
21
  @regression_controller_path = 'spec/controllers/regression'
22
+ @regression_factory_path = 'spec/factories'
21
23
  @excluded_models = []
22
24
  @excluded_controllers = []
23
25
  @include_enums = true
@@ -1,3 +1,3 @@
1
1
  module Regressor
2
- VERSION = "0.5.8"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -0,0 +1,8 @@
1
+ require 'faker'
2
+
3
+ FactoryGirl.define do
4
+
5
+ factory :<%= @model.model.to_s.underscore.gsub('/', '_') %>, class: <%= @model.model %> do
6
+ end
7
+
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: regressor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.8
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erwin Schens
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-07 00:00:00.000000000 Z
11
+ date: 2015-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shoulda-matchers
@@ -137,6 +137,7 @@ files:
137
137
  - lib/controller/routing/rest/routes.rb
138
138
  - lib/controller/util.rb
139
139
  - lib/generators/regressor/controller_generator.rb
140
+ - lib/generators/regressor/factory_generator.rb
140
141
  - lib/generators/regressor/install_generator.rb
141
142
  - lib/generators/regressor/model_generator.rb
142
143
  - lib/generators/regressor/mongoid/model_generator.rb
@@ -148,11 +149,13 @@ files:
148
149
  - lib/model/active_record/relation/has_many.rb
149
150
  - lib/model/active_record/relation/has_one.rb
150
151
  - lib/model/active_record/util.rb
152
+ - lib/model/active_record/validation.rb
151
153
  - lib/model/active_record/validation/length.rb
152
154
  - lib/model/active_record/validation/numericality.rb
153
155
  - lib/model/active_record/validation/presence.rb
154
156
  - lib/model/active_record_model.rb
155
157
  - lib/model/expression.rb
158
+ - lib/model/factory_model.rb
156
159
  - lib/model/mongoid/database/field.rb
157
160
  - lib/model/mongoid/document/timestamp.rb
158
161
  - lib/model/mongoid/document/version.rb
@@ -164,6 +167,7 @@ files:
164
167
  - lib/regressor.rb
165
168
  - lib/regressor/version.rb
166
169
  - lib/templates/controller/controller_spec_template.erb
170
+ - lib/templates/factory/factory_template.erb
167
171
  - lib/templates/model/active_record/model_template.erb
168
172
  - lib/templates/model/mongoid/model_template.erb
169
173
  - lib/templates/regressor.rb