improve support for rspec scaffolding (thanks voxik) - closes #176

This commit is contained in:
Ryan Bates
2010-12-21 14:18:20 -08:00
parent 5e1e6e182b
commit 4339ac6546
2 changed files with 6 additions and 8 deletions

View File

@@ -61,20 +61,18 @@ module CanCan
end
def build_resource
if @options[:singleton] && resource_base.respond_to?("build_#{name}")
resource = resource_base.send("build_#{name}")
else
resource = resource_base.send("new")
end
method_name = @options[:singleton] && resource_base.respond_to?("build_#{name}") ? "build_#{name}" : "new"
resource = resource_base.send(method_name, @params[name] || {})
initial_attributes.each do |name, value|
resource.send("#{name}=", value)
end
resource.attributes = @params[name] if @params[name]
resource
end
def initial_attributes
current_ability.attributes_for(@params[:action].to_sym, resource_class)
current_ability.attributes_for(@params[:action].to_sym, resource_class).delete_if do |key, value|
@params[name] && @params[name].include?(key)
end
end
def find_resource