rails_model_stacker 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/lib/rails_model_stacker/factory_stacker.rb +21 -0
- data/lib/rails_model_stacker/rms.rb +51 -0
- data/lib/rails_model_stacker/spec_stacker.rb +38 -0
- data/license +7 -0
- data/rails_model_stacker.gemspec +21 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2e3021a48eee6c39b9dd1bc1ff813d2e95fccf82
|
4
|
+
data.tar.gz: c5f0a5fac96f14281ad115d1364142abeebae351
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 66205a846a246e72e7ced420378decac2132e7d29c0e3cf15c22ee0b166205446231f20ff56e7a91c41b2d55954a9b286d61526b1872902b5dd775dba049fc0c
|
7
|
+
data.tar.gz: 64310d712d6d657c73c34dec430929e261f4b8a19c87cf3d5cab9d0269fffd51479f3bd816d31e4d4b2b33d63242fd9f9a262d19ff411da2f5bbe9fffca33cd2
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
/doc
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#factory girl helpers
|
2
|
+
#
|
3
|
+
#to use:
|
4
|
+
# require 'factory_stacker'
|
5
|
+
#in spec/spec_helper
|
6
|
+
module FactoryGirl
|
7
|
+
|
8
|
+
##
|
9
|
+
#short hand sequence
|
10
|
+
#+column+:: symbol of column name
|
11
|
+
def auto_sequence column
|
12
|
+
sequence(column) { |n| "#{column.to_s} #{n}" }
|
13
|
+
end
|
14
|
+
|
15
|
+
##
|
16
|
+
#short hand sequence for multiple columns
|
17
|
+
#+columns+:: array of symboles of column names
|
18
|
+
def auto_sequencer columns
|
19
|
+
columns.each { |k| sequence(k) }
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
#Adds Some helpers for declaring traits and valdation on multiple fields in ActiveRecord
|
3
|
+
module RailsModelStacker
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
class_methods do
|
7
|
+
##
|
8
|
+
#Declare a trait or validation on attributes
|
9
|
+
#
|
10
|
+
# declare_trait [:name, :email], :validates_presence_of
|
11
|
+
#
|
12
|
+
#attributes:: array of symbol of field names
|
13
|
+
#trait:: symbol of the trait
|
14
|
+
def declare_trait_for(attributes, trait)
|
15
|
+
attributes.each { |key| send(trait,key) }
|
16
|
+
end
|
17
|
+
|
18
|
+
##
|
19
|
+
#Ensures attributes will be present
|
20
|
+
#+attributes+:: array of symbols of field names
|
21
|
+
def require_presence_of attributes
|
22
|
+
declare_trait_for attributes, :validates_presence_of
|
23
|
+
end
|
24
|
+
|
25
|
+
def require_uniqness_of attributes
|
26
|
+
delcare_trait_for attributes, :validates_uniqueness_of
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
#declares the trait has_and_belongs_to_many on all attributes
|
31
|
+
#+attributes+:: array of symbols of field names
|
32
|
+
def declare_join_on attributes
|
33
|
+
declare_trait_for attributes, :has_and_belongs_to_many
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
#see declare_join_on
|
38
|
+
def declare_belongs_to attributes
|
39
|
+
declare_trait_for attributes, :belongs_to
|
40
|
+
end
|
41
|
+
|
42
|
+
##
|
43
|
+
#see declare_join_on
|
44
|
+
def declare_has_many attributes
|
45
|
+
declare_trait_for attributes, :has_many
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
ActiveRecord::Base.send(:include, RailsModelStacker)
|
@@ -0,0 +1,38 @@
|
|
1
|
+
##
|
2
|
+
# Allows testing of multiple columns in a database for a single trait
|
3
|
+
#
|
4
|
+
module SpecStacker
|
5
|
+
|
6
|
+
##
|
7
|
+
#it should test value for action
|
8
|
+
#+value+:: symbol for a column name
|
9
|
+
#+action+:: symbol for an action (eg. +validate_presence_of+)
|
10
|
+
def it_should value, action
|
11
|
+
it { should send(action, value) }
|
12
|
+
end
|
13
|
+
|
14
|
+
##
|
15
|
+
#test attributes with action
|
16
|
+
#+attributes+:: array of symbols of columns names
|
17
|
+
#+action+:: the action to check, see it_should
|
18
|
+
def should_all attributes, action
|
19
|
+
attributes.each { |k| it_should(k, action) }
|
20
|
+
end
|
21
|
+
|
22
|
+
##
|
23
|
+
#test if attributes are present
|
24
|
+
#+attributes+:: array of symbols of column names
|
25
|
+
def should_all_be_present attributes
|
26
|
+
should_all attributes, :validate_presence_of
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
#test if all attributes have_and_belong_to_many
|
31
|
+
#+value+:: symbol of column name
|
32
|
+
#
|
33
|
+
#the normal identifier is too long.
|
34
|
+
def should_all_join attributes
|
35
|
+
should_all attributes, :have_and_belong_to_many
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
data/license
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright 2017 Matthew Petricone
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,21 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "rails_model_stacker"
|
6
|
+
s.version = "0.0.3"
|
7
|
+
s.date = "2017-07-13"
|
8
|
+
s.summary = "Rails Model Stacker"
|
9
|
+
s.description = "Shorter Active Record validations and associations with RSpec and shoulda support"
|
10
|
+
s.authors = ["Matthew Petricone"]
|
11
|
+
s.email = "strstream@gmail.com"
|
12
|
+
s.files = `git ls-files`.split($/)
|
13
|
+
s.require_paths = ["lib"]
|
14
|
+
s.license = "MIT"
|
15
|
+
s.required_ruby_version = '>= 2.3.3'
|
16
|
+
s.add_runtime_dependency 'rails', '~> 5.0'
|
17
|
+
s.add_runtime_dependency 'rspec', '~> 3.0'
|
18
|
+
s.add_runtime_dependency 'factory_girl_rails', "~> 4.8"
|
19
|
+
s.add_runtime_dependency 'shoulda-matchers', "~> 3.1"
|
20
|
+
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_model_stacker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Petricone
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: factory_girl_rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.8'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: shoulda-matchers
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.1'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.1'
|
69
|
+
description: Shorter Active Record validations and associations with RSpec and shoulda
|
70
|
+
support
|
71
|
+
email: strstream@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- lib/rails_model_stacker/factory_stacker.rb
|
78
|
+
- lib/rails_model_stacker/rms.rb
|
79
|
+
- lib/rails_model_stacker/spec_stacker.rb
|
80
|
+
- license
|
81
|
+
- rails_model_stacker.gemspec
|
82
|
+
homepage:
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
metadata: {}
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 2.3.3
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 2.6.10
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: Rails Model Stacker
|
106
|
+
test_files: []
|