Skip to content

Commit

Permalink
add validate options
Browse files Browse the repository at this point in the history
  • Loading branch information
yulii committed Apr 13, 2014
1 parent 7423686 commit 24bdf24
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/rescue/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def self.included(base)

def rescue_respond call, params, options = {}
begin
send(call, params)
send(call, params, (options[:validate] ? { context: options[:validate] } : {}))
success_message = options[:success]||Flash.message(self, :success)
flash[:success] = success_message unless success_message.blank?
instance_exec(&options[:render])
Expand Down
10 changes: 5 additions & 5 deletions lib/rescue/controllers/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ def self.define_call object, clazz, var_sym
id = (params.empty? ? send(:params) : params).delete(Rescue.config.primary_key)
instance_variable_set(var_sym, clazz.where(params).find(id))
end
object.send(:define_method, :create_call) do |params|
object.send(:define_method, :create_call) do |params, validate = {}|
new_call(params)
instance_variable_get(var_sym).save!
instance_variable_get(var_sym).save!(validate)
end
object.send(:define_method, :update_call) do |params|
object.send(:define_method, :update_call) do |params, validate = {}|
find_call
instance_variable_get(var_sym).attributes = params
instance_variable_get(var_sym).save!
instance_variable_get(var_sym).save!(validate)
end
object.send(:define_method, :destroy_call) do |params|
object.send(:define_method, :destroy_call) do |params, validate = {}|
find_call(params)
instance_variable_get(var_sym).destroy
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rescue/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Rescue
VERSION = "0.3.7"
VERSION = "0.3.8"
end
2 changes: 1 addition & 1 deletion spec/rescue/controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def rescue_execute
object.stub(:flash).and_return(flash)
object.stub(:controller_path).and_return('rescue')
object.stub(:action_name).and_return('action')
object.stub(:stub_call).with({}).and_return(nil)
object.stub(:stub_call).with({},{}).and_return(nil)
object
end

Expand Down

0 comments on commit 24bdf24

Please sign in to comment.