comply 1.5.0 → 2.0.0.beta

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
- SHA1:
3
- metadata.gz: fe65a8f58c234deb6cd6076f2fd7bb2f3156704a
4
- data.tar.gz: 9aeff5a90f702b671b6a5adc44d9d580c44c86d7
2
+ SHA256:
3
+ metadata.gz: 79951d02439eb2cfe02f21dfc8fbe347da0ccd679dfa9eea95200309b9ade9d1
4
+ data.tar.gz: 11b1625f62e6994c182095f681566b61e1cffd7820ea4f77dbe1d69fc16850af
5
5
  SHA512:
6
- metadata.gz: 73906bc41d482038914ecd7e0cd69ac1d176c74adac56e05c1e8a0138ac11a92e90890d15f162a3a6447edd8fb64383cb185a251432ebb4f9604154981d133b1
7
- data.tar.gz: 12e732771f7564c71fa2e77579165163d653227969bcb4e7155f25112d1495167d26a49fcfd15b6e954c078698c77c3eba69a02b9961a0bf92982464e47c5716
6
+ metadata.gz: a0666d15222e8585ff5f6ca58d5b764ecc4f78ed03d243c493980b849a9094c712b3424345dcecb86748bc725faff274d0f9b7f8e7d36dc7dfc559418764974a
7
+ data.tar.gz: a5b290fc2732d251bc790137859e2f72794258e58095fc9d5ccef99dd426120d93a8d1178758467bef4b72f6ce94af09c9e4725993e97fee893741836365cc29
data/README.md CHANGED
@@ -13,11 +13,6 @@ Include Comply in your gemfile:
13
13
  ```ruby
14
14
  gem 'comply'
15
15
  ```
16
- If you are using Rails 3, you need to include `strong_parameters`
17
- ```ruby
18
- gem 'comply'
19
- gem 'strong_parameters'
20
- ```
21
16
  Mount the engine in your `routes.rb`:
22
17
  ```ruby
23
18
  mount Comply::Engine => '/comply'
@@ -68,6 +63,45 @@ Want success messages to add some personality to your forms? Add the message as
68
63
  <%= f.text_field :title, data: { validate: true, validate_success: "Sweet title yo!" } %>
69
64
  ```
70
65
 
66
+ ### Validation contexts
67
+ Supplementary reading on validation contexts:
68
+ - [ActiveRecord Validations :on](http://guides.rubyonrails.org/active_record_validations.html#on)
69
+ - [Also see api.rubyonrails.org](http://api.rubyonrails.org/classes/ActiveRecord/Validations.html#method-i-valid-3F)
70
+ - [Mastering Rails Validations: Contexts](http://blog.arkency.com/2014/04/mastering-rails-validations-contexts/)
71
+
72
+ By default, all validations run through Comply's `Comply::ValidationsController` will be in the `:comply` validation
73
+ context. This gives you the option to modify how your application runs its validations. The most common way to use
74
+ validation contexts, is when you want to skip a certain validation. Let's say we didn't want to check the uniqueness
75
+ of a particular attribute when asking Comply to validate a model. You would do this:
76
+
77
+ ```ruby
78
+ class SomeModel < ActiveRecord::Base
79
+ validates :my_attribute, uniqueness: true, unless: -> { validation_context == :comply }
80
+ # or perhaps you *ONLY* want to run the validation when in the :comply context
81
+ validates :other_attribute, numericality: true, on: :comply
82
+ end
83
+ ```
84
+
85
+ You now have the option to specify your own context if you inherit from `Comply::ValidationsController` if your
86
+ model has a specific business case for needing to run/not-run a set of validations for a given context.
87
+
88
+ ```ruby
89
+ class SomeController < Comply::ValidationsController
90
+ # ... snip
91
+ protected
92
+
93
+ def validation_context
94
+ :my_new_context
95
+ end
96
+ end
97
+
98
+ class SomeModel
99
+ validates :my_attribute, uniqueness: true, unless: -> { validation_context == :my_new_context }
100
+ end
101
+ ```
102
+
103
+ That's it!
104
+
71
105
  ### Event triggers
72
106
  You can change the jQuery event which triggers the input validation with the `data-validate-event` attribute.
73
107
  ```erb
@@ -14,7 +14,7 @@ class Comply.BaseValidatableForm
14
14
  @validate inputs: @inputs, submit: true
15
15
 
16
16
  validate: (options) ->
17
- $.get @validationRoute, @_params(), (response) =>
17
+ $.post @validationRoute, @_params(), (response) =>
18
18
  @_onValidate(response, options)
19
19
 
20
20
  if @_allSuccess(response)
@@ -1,5 +1,4 @@
1
1
  module Comply
2
2
  class ApplicationController < ActionController::Base
3
- include ::SslRequirement
4
3
  end
5
4
  end
@@ -1,24 +1,24 @@
1
- begin
2
- require 'strong_parameters'
3
- rescue LoadError
4
- end
5
-
6
1
  module Comply
7
2
  class ValidationsController < Comply::ApplicationController
8
- ssl_allowed :show
9
-
10
- before_filter :require_model, :require_fields
3
+ before_action :require_model, :require_fields
11
4
 
12
5
  if ActiveModel.const_defined?(:ForbiddenAttributesProtection)
13
6
  include ActiveModel::ForbiddenAttributesProtection
14
7
  end
15
8
 
16
9
  def show
10
+ ActiveSupport::Deprecation.warn('GET support going away: use POST to access this endpoint') if request.request_method == 'GET'
17
11
  @instance = validation_instance
18
- @instance.valid?
12
+ @instance.valid?(validation_context)
19
13
  render json: { error: @instance.errors }
20
14
  end
21
15
 
16
+ protected
17
+
18
+ def validation_context
19
+ :comply
20
+ end
21
+
22
22
  private
23
23
 
24
24
  def validation_instance
@@ -1,3 +1,5 @@
1
1
  Comply::Engine.routes.draw do
2
- match '/validations' => 'validations#show', via: :get
2
+ match '/validations' => 'validations#show', via: [:get, :post]
3
+ # allow CORS requests
4
+ match 'validations', via: [:options], to: proc { [200, {}, ['']] }
3
5
  end
@@ -1,5 +1,4 @@
1
1
  require 'comply/engine'
2
- require 'ssl_requirement'
3
2
  require 'comply/whitelist_constantize'
4
3
 
5
4
  module Comply
@@ -1,3 +1,3 @@
1
1
  module Comply
2
- VERSION = '1.5.0'
2
+ VERSION = '2.0.0.beta'
3
3
  end
@@ -1,4 +1,4 @@
1
- require 'active_model/validations'
1
+ require 'active_model'
2
2
 
3
3
  module Comply
4
4
  module WhitelistConstantize
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comply
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 2.0.0.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - "@jacobaweiss"
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2016-02-03 00:00:00.000000000 Z
15
+ date: 2020-05-17 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: coffee-rails
@@ -28,36 +28,8 @@ dependencies:
28
28
  - - ">="
29
29
  - !ruby/object:Gem::Version
30
30
  version: '0'
31
- - !ruby/object:Gem::Dependency
32
- name: bartt-ssl_requirement
33
- requirement: !ruby/object:Gem::Requirement
34
- requirements:
35
- - - "~>"
36
- - !ruby/object:Gem::Version
37
- version: 1.4.2
38
- type: :runtime
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- requirements:
42
- - - "~>"
43
- - !ruby/object:Gem::Version
44
- version: 1.4.2
45
31
  - !ruby/object:Gem::Dependency
46
32
  name: rails
47
- requirement: !ruby/object:Gem::Requirement
48
- requirements:
49
- - - '='
50
- - !ruby/object:Gem::Version
51
- version: 4.0.13
52
- type: :runtime
53
- prerelease: false
54
- version_requirements: !ruby/object:Gem::Requirement
55
- requirements:
56
- - - '='
57
- - !ruby/object:Gem::Version
58
- version: 4.0.13
59
- - !ruby/object:Gem::Dependency
60
- name: protected_attributes
61
33
  requirement: !ruby/object:Gem::Requirement
62
34
  requirements:
63
35
  - - ">="
@@ -88,16 +60,16 @@ dependencies:
88
60
  name: rspec-rails
89
61
  requirement: !ruby/object:Gem::Requirement
90
62
  requirements:
91
- - - "~>"
63
+ - - ">="
92
64
  - !ruby/object:Gem::Version
93
- version: 3.2.0
65
+ version: '0'
94
66
  type: :development
95
67
  prerelease: false
96
68
  version_requirements: !ruby/object:Gem::Requirement
97
69
  requirements:
98
- - - "~>"
70
+ - - ">="
99
71
  - !ruby/object:Gem::Version
100
- version: 3.2.0
72
+ version: '0'
101
73
  - !ruby/object:Gem::Dependency
102
74
  name: sqlite3
103
75
  requirement: !ruby/object:Gem::Requirement
@@ -151,14 +123,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
151
123
  version: '0'
152
124
  required_rubygems_version: !ruby/object:Gem::Requirement
153
125
  requirements:
154
- - - ">="
126
+ - - ">"
155
127
  - !ruby/object:Gem::Version
156
- version: '0'
128
+ version: 1.3.1
157
129
  requirements: []
158
- rubyforge_project:
159
- rubygems_version: 2.2.3
130
+ rubygems_version: 3.1.2
160
131
  signing_key:
161
132
  specification_version: 4
162
133
  summary: Inline validation of your ActiveRecord models via the AJAX internets
163
134
  test_files: []
164
- has_rdoc: