auto_specs 0.0.1.alpha → 0.0.1.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4483793151af907e9122b6886669d376466d9ed
4
- data.tar.gz: a3090e708e8c061d6ebb154082242e494495e661
3
+ metadata.gz: 8d731dc2b8f930cbed569b6d1e4f12eb09a027c8
4
+ data.tar.gz: 9703773fd6552a2cd7f222a4c467b5e4ca38fd60
5
5
  SHA512:
6
- metadata.gz: c4d0e9564b26463792efb941e56ca9b2383b856bc06d98c7df294f73cedea6fe8dcd266ced9af7af43c10b699da2160917223d5e913b9f645146708975d47fee
7
- data.tar.gz: a9f3713fa900bfdb12ee194ea63f4b988c3819d3cec400477a40e03e7efe0270241170d7928a9a5339cb465639becc03de55e935a4ef7f9c37be492d263d07d3
6
+ metadata.gz: 1b1caa6a30530c35800016f5a6ac590531d7d50a812683602813af62273df2ea206bae5f008702ccbdd367c0aa8e12766f152970f351b33abca0d8459772b200
7
+ data.tar.gz: e8944c624ceb733ebaa70c000f09cecc37f63a7167e132600bbd1f4923116dc59e3951d19711d259245d4a21b9a4d8e7fe45481f1832356ad1ff4b602e23a1f3
data/README.md CHANGED
@@ -15,9 +15,6 @@ In order to use this gem, the following steps needs to be done before installing
15
15
 
16
16
  The reason we chose `rspec` and `shoulda-matcher` is due to their simple and efficient DSL which makes writing tests easier.
17
17
 
18
- ### Currently we are generating the `associations` but it is being planned for `validations` too. There is an [open issue](https://github.com/aditya-kapoor/auto-specs/issues/5) for this.
19
-
20
-
21
18
  ## Installation
22
19
 
23
20
  Add this line to your application's Gemfile:
@@ -38,10 +35,10 @@ Or install it yourself as:
38
35
 
39
36
  Upon installation in the rails app, the gem presents you with two `rake` tasks namely:
40
37
 
41
- 1. auto_specs:model
42
- 2. auto_spec:controller [TODO]
38
+ 1. auto_specs:models
39
+ 2. auto_spec:controllers [TODO]
43
40
 
44
- Running `rake auto_specs:model` would generate the model file specs in the `spec` directory.
41
+ Running `rake auto_specs:models` would generate the model file specs in the `spec` directory.
45
42
 
46
43
  ## Contributing
47
44
 
data/auto_specs.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Aditya Kapoor"]
10
10
  spec.email = ["aditya.kapoor@vinsol.com"]
11
11
  spec.summary = "Adds certain tasks that would automatically generate some specs for you."
12
- spec.description = ""
12
+ spec.description = "Don't Write Specs Yourself."
13
13
  spec.homepage = "https://github.com/aditya-kapoor/auto-specs"
14
14
  spec.license = "MIT"
15
15
 
@@ -0,0 +1,34 @@
1
+ module AutoSpecs
2
+ module ActiveRecord
3
+ module Validations
4
+ module Helpers
5
+ module GeneralMethods
6
+ private
7
+ def on_option
8
+ "on(:#{ options[:on] })"
9
+ end
10
+
11
+ def message_option
12
+ "with_message('#{ options[:message] }')"
13
+ end
14
+
15
+ def scope_option
16
+ "scoped_to(:#{ options[:scope] })"
17
+ end
18
+
19
+ def case_sensitive_option
20
+ options[:case_sensitive] ? "case_sensitive" : "case_insensitive"
21
+ end
22
+
23
+ def allow_nil_option
24
+ "allow_nil"
25
+ end
26
+
27
+ def allow_blank_option
28
+ "allow_blank"
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,14 @@
1
+ module AutoSpecs
2
+ module ActiveRecord
3
+ module Validations
4
+ module Helpers
5
+ module InclusionMethods
6
+ private
7
+ def in_option
8
+ "in_#{ options[:in].class.name.downcase }(#{ options[:in] })"
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,30 @@
1
+ module AutoSpecs
2
+ module ActiveRecord
3
+ module Validations
4
+ module Helpers
5
+ module LengthMethods
6
+ private
7
+ def minimum_option
8
+ "is_at_least(#{ options[:minimum] })"
9
+ end
10
+
11
+ def maximum_option
12
+ "is_at_most(#{ options[:maximum] })"
13
+ end
14
+
15
+ def is_option
16
+ "is_equal_to(#{ options[:is] })"
17
+ end
18
+
19
+ def too_short_option
20
+ "with_short_message('#{ options[:too_short] }')"
21
+ end
22
+
23
+ def too_long_option
24
+ "with_long_message('#{ options[:too_long] }')"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ module AutoSpecs
2
+ module ActiveRecord
3
+ module Validations
4
+ module Helpers
5
+ module NumericalityMethods
6
+ [:less_than, :less_than_or_equal_to, :equal_to, :greater_than, :greater_than_or_equal_to].each do |option|
7
+ method_name = "#{ option }_option"
8
+ define_method method_name do
9
+ "is_#{ option }(#{ options[option] })"
10
+ end
11
+ private method_name
12
+ end
13
+
14
+ private
15
+ def only_integer_option
16
+ "only_integer"
17
+ end
18
+
19
+ def even_option
20
+ options[:even] ? "even" : "odd"
21
+ end
22
+
23
+ def odd_option
24
+ options[:odd] ? "odd" : "even"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,15 @@
1
+ module AutoSpecs
2
+ module ActiveRecord
3
+ module Validations
4
+ MAPPINGS = {
5
+ 'PresenceValidator' => 'validate_presence_of',
6
+ 'UniquenessValidator' => 'validate_uniqueness_of',
7
+ 'NumericalityValidator' => 'validate_numericality_of',
8
+ 'LengthValidator' => 'validate_length_of',
9
+ 'ConfirmationValidator' => 'validate_confirmation_of',
10
+ 'InclusionValidator' => 'validate_inclusion_of',
11
+ 'ExclusionValidator' => 'validate_exclusion_of'
12
+ }
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,43 @@
1
+ require 'auto_specs/active_record/validations/mapping'
2
+ require 'auto_specs/active_record/validations/helpers/general_methods'
3
+ require 'auto_specs/active_record/validations/helpers/numericality_methods'
4
+ require 'auto_specs/active_record/validations/helpers/length_methods'
5
+ require 'auto_specs/active_record/validations/helpers/inclusion_methods'
6
+
7
+ module AutoSpecs
8
+ module ActiveRecord
9
+ module Validations
10
+ class SpecBuilder
11
+ include Helpers::GeneralMethods
12
+ include Helpers::NumericalityMethods
13
+ include Helpers::LengthMethods
14
+ include Helpers::InclusionMethods
15
+
16
+ attr_accessor :attributes, :validator_class, :options
17
+
18
+ def initialize(validator_object)
19
+ @validator_class = validator_object.class.to_s.demodulize
20
+ @attributes = validator_object.attributes
21
+ @options = validator_object.options
22
+ end
23
+
24
+ def to_s
25
+ attributes.collect do |_attr_|
26
+ "it { should #{ shoulda_validation_mapping }(:#{ _attr_ })#{ append_options } }"
27
+ end.join("\n")
28
+ end
29
+
30
+ private
31
+ def shoulda_validation_mapping
32
+ ActiveRecord::Validations::MAPPINGS[validator_class]
33
+ end
34
+
35
+ def append_options
36
+ options.keys.collect do |key|
37
+ send("#{ key }_option")
38
+ end.join(".").prepend('.')
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,5 +1,6 @@
1
1
  require 'auto_specs/generators/base'
2
2
  require 'auto_specs/active_record/associations/spec_builder'
3
+ require 'auto_specs/active_record/validations/spec_builder'
3
4
 
4
5
  module AutoSpecs
5
6
  module Generators
@@ -22,7 +23,7 @@ module AutoSpecs
22
23
  def push_file
23
24
  within_file_code do
24
25
  generate_code_for_associations
25
- # generate_code_for_validations
26
+ generate_code_for_validations
26
27
  end
27
28
  write_file
28
29
  end
@@ -53,8 +54,12 @@ describe #{ model_name } do)
53
54
  def generate_code_for_validations
54
55
  generate_code_block_for('Validations')
55
56
  model_name.validators.each do |validator|
56
- # TODO...
57
+ self.file_contents += %Q(
58
+ #{ AutoSpecs::ActiveRecord::Validations::SpecBuilder.new(validator).to_s })
57
59
  end
60
+ self.file_contents += %Q(
61
+ end
62
+ )
58
63
  end
59
64
 
60
65
  def generate_code_block_for(entity)
@@ -1,3 +1,3 @@
1
1
  module AutoSpecs
2
- VERSION = "0.0.1.alpha"
2
+ VERSION = "0.0.1.alpha.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auto_specs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.alpha
4
+ version: 0.0.1.alpha.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aditya Kapoor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-31 00:00:00.000000000 Z
11
+ date: 2015-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
- description: ''
41
+ description: Don't Write Specs Yourself.
42
42
  email:
43
43
  - aditya.kapoor@vinsol.com
44
44
  executables: []
@@ -55,6 +55,12 @@ files:
55
55
  - lib/auto_specs/active_record/associations/mapping.rb
56
56
  - lib/auto_specs/active_record/associations/spec_builder.rb
57
57
  - lib/auto_specs/active_record/models/generator.rb
58
+ - lib/auto_specs/active_record/validations/helpers/general_methods.rb
59
+ - lib/auto_specs/active_record/validations/helpers/inclusion_methods.rb
60
+ - lib/auto_specs/active_record/validations/helpers/length_methods.rb
61
+ - lib/auto_specs/active_record/validations/helpers/numericality_methods.rb
62
+ - lib/auto_specs/active_record/validations/mapping.rb
63
+ - lib/auto_specs/active_record/validations/spec_builder.rb
58
64
  - lib/auto_specs/generators/base.rb
59
65
  - lib/auto_specs/generators/model.rb
60
66
  - lib/auto_specs/tasks.rb