Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Commit

Permalink
Rename :assignment option to :assign_as
Browse files Browse the repository at this point in the history
  • Loading branch information
martijn authored and andhapp committed Jun 23, 2012
1 parent 7b55ea0 commit 4ec2166
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/cancan/controller_additions.rb
Expand Up @@ -112,8 +112,8 @@ def load_and_authorize_resource(*args)
# [:+prepend+] # [:+prepend+]
# Passing +true+ will use prepend_before_filter instead of a normal before_filter. # Passing +true+ will use prepend_before_filter instead of a normal before_filter.
# #
# [:+assignment+] # [:+assign_as+]
# Passing to ActiveRecord for support Mass-Assignment Role # Passed as the role when mass assigning attributes (from Rails 3.1 onwards)
# #
def load_resource(*args) def load_resource(*args)
cancan_resource_class.add_before_filter(self, :load_resource, *args) cancan_resource_class.add_before_filter(self, :load_resource, *args)
Expand Down
6 changes: 3 additions & 3 deletions lib/cancan/controller_resource.rb
Expand Up @@ -82,9 +82,9 @@ def load_collection
end end


def build_resource def build_resource
# use Rails 3.1's assign_attribute when resource_params[:assignment] is present # use Rails 3.1's assign_attribute when resource_params[:assign_as] is present
if @options && @options[:assignment].present? && (resource = resource_base.new).respond_to?(:assign_attributes) if @options && @options[:assign_as].present? && (resource = resource_base.new).respond_to?(:assign_attributes)
resource.assign_attributes(resource_params || {}, :as => @options[:assignment]) resource.assign_attributes(resource_params || {}, :as => @options[:assign_as])
else else
resource = resource_base.new(resource_params || {}) resource = resource_base.new(resource_params || {})
end end
Expand Down
4 changes: 2 additions & 2 deletions spec/cancan/controller_resource_spec.rb
Expand Up @@ -501,9 +501,9 @@ class Section
project.secret.should be_false project.secret.should be_false
end end


it "should be able to mass assign secret when using assignment" do it "should be able to mass assign secret when using :assign_as" do
@params.merge!(:action => "create", :project => { :name => "foobar", :secret => "1" }) @params.merge!(:action => "create", :project => { :name => "foobar", :secret => "1" })
resource = CanCan::ControllerResource.new(@controller, :assignment => :admin) resource = CanCan::ControllerResource.new(@controller, :assign_as => :admin)
resource.load_resource resource.load_resource


project = @controller.instance_variable_get(:@project) project = @controller.instance_variable_get(:@project)
Expand Down

0 comments on commit 4ec2166

Please sign in to comment.