From f1ddd93be89ae3b8d7783e5e110e0961973ab3a9 Mon Sep 17 00:00:00 2001 From: Jason Leonard Date: Mon, 14 Sep 2015 17:56:37 -0400 Subject: [PATCH 1/4] Updating gems. --- Gemfile | 4 ++-- Gemfile.lock | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 Gemfile.lock diff --git a/Gemfile b/Gemfile index f656c23..1edf195 100644 --- a/Gemfile +++ b/Gemfile @@ -3,6 +3,6 @@ source "http://rubygems.org" gem 'rake', '~> 0.8.7' gem 'rspec', '~> 2.4.0' -gem 'activesupport', '~> 3.2.0' -gem 'activemodel', '~> 3.2.0' +gem 'activesupport' +gem 'activemodel' # gem 'ruby-debug' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..c9ce9b0 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,38 @@ +GEM + remote: http://rubygems.org/ + specs: + activemodel (4.2.4) + activesupport (= 4.2.4) + builder (~> 3.1) + activesupport (4.2.4) + i18n (~> 0.7) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.3, >= 0.3.4) + tzinfo (~> 1.1) + builder (3.2.2) + diff-lcs (1.1.3) + i18n (0.7.0) + json (1.8.3) + minitest (5.8.0) + rake (0.8.7) + rspec (2.4.0) + rspec-core (~> 2.4.0) + rspec-expectations (~> 2.4.0) + rspec-mocks (~> 2.4.0) + rspec-core (2.4.0) + rspec-expectations (2.4.0) + diff-lcs (~> 1.1.2) + rspec-mocks (2.4.0) + thread_safe (0.3.5) + tzinfo (1.2.2) + thread_safe (~> 0.1) + +PLATFORMS + ruby + +DEPENDENCIES + activemodel + activesupport + rake (~> 0.8.7) + rspec (~> 2.4.0) From 18bb1caefc9ce504afbb0b0be122ce6f40120ee0 Mon Sep 17 00:00:00 2001 From: Jason Leonard Date: Tue, 15 Sep 2015 11:56:10 -0400 Subject: [PATCH 2/4] Fixing 'undefined method validate' error. Needed to reconfigure 'define_callbacks' method. --- Gemfile | 1 + Gemfile.lock | 2 ++ lib/grouped_validations.rb | 10 ++++++---- lib/grouped_validations/callback.rb | 5 +++++ 4 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 lib/grouped_validations/callback.rb diff --git a/Gemfile b/Gemfile index 1edf195..f7ac225 100644 --- a/Gemfile +++ b/Gemfile @@ -5,4 +5,5 @@ gem 'rake', '~> 0.8.7' gem 'rspec', '~> 2.4.0' gem 'activesupport' gem 'activemodel' +gem 'method_source' # gem 'ruby-debug' diff --git a/Gemfile.lock b/Gemfile.lock index c9ce9b0..4047421 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -14,6 +14,7 @@ GEM diff-lcs (1.1.3) i18n (0.7.0) json (1.8.3) + method_source (0.8.2) minitest (5.8.0) rake (0.8.7) rspec (2.4.0) @@ -34,5 +35,6 @@ PLATFORMS DEPENDENCIES activemodel activesupport + method_source rake (~> 0.8.7) rspec (~> 2.4.0) diff --git a/lib/grouped_validations.rb b/lib/grouped_validations.rb index 4eba31e..7e022e0 100644 --- a/lib/grouped_validations.rb +++ b/lib/grouped_validations.rb @@ -1,5 +1,6 @@ require 'active_model/validations' require 'grouped_validations/active_model' +require 'grouped_validations/callback' module GroupedValidations extend ActiveSupport::Concern @@ -29,7 +30,7 @@ def validate(*args, &block) end def _define_group_validation_callbacks(group) - define_callbacks :"validate_#{group}", :scope => 'validate' + define_callbacks :"validate_#{group}", :scope => :callback_method, callback_method: :validate end end @@ -45,6 +46,7 @@ def valid?(context=nil) def groups_valid?(*groups) options = groups.extract_options! errors.clear + run_validations! groups.each do |group| raise "Validation group '#{group}' not defined" unless validation_groups.include?(group) _run_group_validation_callbacks(group, options[:context]) @@ -59,12 +61,12 @@ def grouped_errors(context=nil) grouped = {} with_validation_context(context) do - _run_validate_callbacks + run_callbacks(:validate) grouped[nil] = errors validation_groups.each do |group| @errors = nil - send(:"_run_validate_#{group}_callbacks") + run_callbacks(:"validate_#{group}") grouped[group] = errors end end @@ -75,7 +77,7 @@ def grouped_errors(context=nil) def _run_group_validation_callbacks(group, context=nil) with_validation_context(context) do - send(:"_run_validate_#{group}_callbacks") + run_callbacks(:"validate_#{group}") end end diff --git a/lib/grouped_validations/callback.rb b/lib/grouped_validations/callback.rb new file mode 100644 index 0000000..7fa39f7 --- /dev/null +++ b/lib/grouped_validations/callback.rb @@ -0,0 +1,5 @@ +class ActiveSupport::Callbacks::Callback + def callback_method + chain_config[:callback_method] + end +end \ No newline at end of file From 0cf0d6c6bb667f10cbcb5430141506674e685d9e Mon Sep 17 00:00:00 2001 From: Jason Leonard Date: Tue, 17 Nov 2015 14:24:22 -0500 Subject: [PATCH 3/4] Forgot to remove method_source gem. --- Gemfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Gemfile b/Gemfile index f7ac225..1edf195 100644 --- a/Gemfile +++ b/Gemfile @@ -5,5 +5,4 @@ gem 'rake', '~> 0.8.7' gem 'rspec', '~> 2.4.0' gem 'activesupport' gem 'activemodel' -gem 'method_source' # gem 'ruby-debug' From dc4207a7966fe691a240a47718b3d9689861a76f Mon Sep 17 00:00:00 2001 From: Jason Leonard Date: Tue, 17 Nov 2015 15:07:08 -0500 Subject: [PATCH 4/4] Removing gemfile.lock from version control. --- Gemfile.lock | 40 ---------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 Gemfile.lock diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 4047421..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,40 +0,0 @@ -GEM - remote: http://rubygems.org/ - specs: - activemodel (4.2.4) - activesupport (= 4.2.4) - builder (~> 3.1) - activesupport (4.2.4) - i18n (~> 0.7) - json (~> 1.7, >= 1.7.7) - minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) - tzinfo (~> 1.1) - builder (3.2.2) - diff-lcs (1.1.3) - i18n (0.7.0) - json (1.8.3) - method_source (0.8.2) - minitest (5.8.0) - rake (0.8.7) - rspec (2.4.0) - rspec-core (~> 2.4.0) - rspec-expectations (~> 2.4.0) - rspec-mocks (~> 2.4.0) - rspec-core (2.4.0) - rspec-expectations (2.4.0) - diff-lcs (~> 1.1.2) - rspec-mocks (2.4.0) - thread_safe (0.3.5) - tzinfo (1.2.2) - thread_safe (~> 0.1) - -PLATFORMS - ruby - -DEPENDENCIES - activemodel - activesupport - method_source - rake (~> 0.8.7) - rspec (~> 2.4.0)