context_validations 0.0.2 → 0.0.3

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: 67d37cb351ac12e521c94e794876897740f49f9e
4
- data.tar.gz: f3bbd51b2e4571c43653baafcc3bda40e48fed21
3
+ metadata.gz: d11c171439aaf9f2e7e22d2dea1e148f061f0daa
4
+ data.tar.gz: 4d430fc4aac414999a209f76411c10962bf1bd88
5
5
  SHA512:
6
- metadata.gz: 9bf2e6d88e94472acc2ca903744096520615f40a1231186b92a0f8834dd80421249b7d1f686cce59a4d7510374f3c3007ddb807b40f3d6fd764fd510019d522b
7
- data.tar.gz: ab7b9e658d84b0f075c81c54c2946c5d9fd3f70914daf39728e26aa86d7999863acd7d53005e27a356e658e2854d0d411f9d83b84ca7785ed3ad38a5ec333288
6
+ metadata.gz: 6586b690a8e4e97cae04a5e8a77636245ee0b875b870daadb0c86263483e5f70500b7b3196fcbc2f0ae8fcd4d50c795f4680b6ad3767762208a0e9a6a5b507fa
7
+ data.tar.gz: 42563e3c5c1a493f09493e837f01a4e3ffe8aa920864c1b2a0f09a249b6ef5c538c336ec49f1328791a511f649aa57e307c26cea7e4ba08255e5a09a7bb63abf
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,25 @@
1
+ # Contribution Guidelines #
2
+
3
+ ## Submitting a new issue ##
4
+
5
+ If you want to ensure that your issue gets fixed *fast* you should
6
+ attempt to reproduce the issue in an isolated example application that
7
+ you can share.
8
+
9
+ ## Making a pull request ##
10
+
11
+ If you'd like to submit a pull request please adhere to the following:
12
+
13
+ 1. Your code *must* be tested. Please TDD your code!
14
+ 2. No single-character variables
15
+ 3. Two-spaces instead of tabs
16
+ 4. Single-quotes instead of double-quotes unless you are using string
17
+ interpolation or escapes.
18
+ 5. General Rails/Ruby naming conventions for files and classes
19
+ 6. *Do not* use Ruby 1.9 stubby proc syntax
20
+
21
+ Please note that you must adhere to each of the above mentioned rules.
22
+ Failure to do so will result in an immediate closing of the pull
23
+ request. If you update and rebase the pull request to follow the
24
+ guidelines your pull request will be re-opened and considered for
25
+ inclusion.
data/README.md CHANGED
@@ -4,17 +4,51 @@
4
4
  [![Dependency Status](https://gemnasium.com/dockyard/context_validations.png?travis)](https://gemnasium.com/dockyard/context_validations)
5
5
  [![Code Climate](https://codeclimate.com/github/dockyard/context_validations.png)](https://codeclimate.com/github/dockyard/context_validations)
6
6
 
7
- Rails exceptions automatically opened as issues on GitHub
7
+ Context based validations for model instances.
8
8
 
9
9
  ## Looking for help? ##
10
10
 
11
11
  If it is a bug [please open an issue on GitHub](https://github.com/dockyard/context_validations/issues).
12
12
 
13
- ## About ##
13
+ ## Installation ##
14
14
 
15
- Context based validations for model instances.
15
+ In your `Gemfile`
16
16
 
17
- ## Example ##
17
+ ```ruby
18
+ gem 'context_validations'
19
+ ```
20
+
21
+ You can either mixin the moduels on a case-by-case basis or make the
22
+ changes global:
23
+
24
+ ### Case-by-case ###
25
+
26
+ ```ruby
27
+ # model
28
+ class User < ActiveModel::Base
29
+ include ContextValidations::Model
30
+ end
31
+
32
+ # controller
33
+ class UsersController < ApplicationController
34
+ include ContextValidations::Controller
35
+ end
36
+ ```
37
+
38
+ ### Global ###
39
+ Create an initializer: `config/initializers/context_validations.rb`
40
+
41
+ ```ruby
42
+ class ActiveRecord::Base
43
+ include ContextValidations::Model
44
+ end
45
+
46
+ class ActionController::Base
47
+ include ContextValidations::Controller
48
+ end
49
+ ```
50
+
51
+ ## Usage ##
18
52
 
19
53
  ```ruby
20
54
  class UserController < ApplicationController
@@ -85,7 +119,7 @@ end
85
119
  ```
86
120
 
87
121
  ### Models ###
88
- When the `ContextValidations::Model` module is mixed into the module all
122
+ When the `ContextValidations::Model` module is mixed into the model all
89
123
  of the validation callbacks are removed from that model.
90
124
 
91
125
  Because we are setting the validations on the instance you should not
@@ -116,3 +150,4 @@ on how to properly submit issues and pull requests.
116
150
  [@dockyard](http://twitter.com/dockyard)
117
151
 
118
152
  [Licensed under the MIT license](http://www.opensource.org/licenses/mit-license.php)
153
+
@@ -34,7 +34,8 @@ module ContextValidations::Controller
34
34
  end
35
35
  @validations = []
36
36
  base_validations
37
- if respond_to?("#{context}_validations")
37
+ if respond_to?("#{context}_validations") || private_methods.include?("#{context}_validations".to_sym) ||
38
+ protected_methods.include?("#{context}_validations".to_sym)
38
39
  send("#{context}_validations")
39
40
  end
40
41
  @validations
@@ -1,3 +1,3 @@
1
1
  module ContextValidations
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -24,22 +24,81 @@ class UsersController
24
24
  end
25
25
  end
26
26
 
27
+ class ProtectedController
28
+ include ContextValidations::Controller
29
+
30
+ def create
31
+ validations(:create)
32
+ end
33
+
34
+ protected
35
+
36
+ def base_validations
37
+ validates :first_name, :presence => true
38
+ end
39
+
40
+ def create_validations
41
+ validates :password, :presence => true
42
+ end
43
+ end
44
+
45
+ class PrivateController
46
+ include ContextValidations::Controller
47
+
48
+ def create
49
+ validations(:create)
50
+ end
51
+
52
+ private
53
+
54
+ def base_validations
55
+ validates :first_name, :presence => true
56
+ end
57
+
58
+ def create_validations
59
+ validates :password, :presence => true
60
+ end
61
+ end
62
+
63
+
27
64
  describe 'Controller' do
28
- before do
29
- @controller = UsersController.new
65
+ context 'Public validations' do
66
+ before do
67
+ @controller = UsersController.new
68
+ end
69
+
70
+ if RUBY_VERSION >= '2'
71
+ it 'combines base and create validations for create action, context is implied' do
72
+ @controller.create.length.must_equal 2
73
+ end
74
+ end
75
+
76
+ it 'combines base and create validations for other create action, context is forced' do
77
+ @controller.other_create.length.must_equal 2
78
+ end
79
+
80
+ it 'uses base validations when context validations are not set for update action' do
81
+ @controller.update.length.must_equal 1
82
+ end
30
83
  end
31
84
 
32
- if RUBY_VERSION >= '2'
33
- it 'combines base and create validations for create action, context is implied' do
85
+ context 'Protected validations' do
86
+ before do
87
+ @controller = ProtectedController.new
88
+ end
89
+
90
+ it 'combines base and create validations for other create action, context is forced' do
34
91
  @controller.create.length.must_equal 2
35
92
  end
36
93
  end
37
94
 
38
- it 'combines base and create validations for other create action, context is forced' do
39
- @controller.other_create.length.must_equal 2
40
- end
95
+ context 'Private validations' do
96
+ before do
97
+ @controller = PrivateController.new
98
+ end
41
99
 
42
- it 'uses base validations when context validations are not set for update action' do
43
- @controller.update.length.must_equal 1
100
+ it 'combines base and create validations for other create action, context is forced' do
101
+ @controller.create.length.must_equal 2
102
+ end
44
103
  end
45
104
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: context_validations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Cardarella
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-09 00:00:00.000000000 Z
11
+ date: 2013-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -103,6 +103,7 @@ extra_rdoc_files: []
103
103
  files:
104
104
  - .gitignore
105
105
  - .travis.yml
106
+ - CONTRIBUTING.md
106
107
  - Gemfile
107
108
  - README.md
108
109
  - Rakefile