Skip to content
This repository
Browse code

Add specs for resource attributes.

Remove inconsistent line breaks.
  • Loading branch information...
commit b965f5bab40071e7e8c0764994ba2a6524ad523f 1 parent c2c0b86
Mike Pack authored June 04, 2012 andhapp committed June 19, 2012
2  lib/cancan/inherited_resource.rb
@@ -6,13 +6,11 @@ def load_resource_instance
6 6
         @controller.send :association_chain
7 7
         @controller.instance_variable_get("@#{instance_name}")
8 8
       elsif new_actions.include? @params[:action].to_sym
9  
-
10 9
         resource = @controller.send :build_resource
11 10
         initial_attributes.each do |attr_name, value|
12 11
           resource.send("#{attr_name}=", value)
13 12
         end
14 13
         resource
15  
-
16 14
       else
17 15
         @controller.send :resource
18 16
       end
18  spec/cancan/inherited_resource_spec.rb
@@ -39,4 +39,22 @@
39 39
     CanCan::InheritedResource.new(@controller).load_resource
40 40
     @controller.instance_variable_get(:@projects).should == :projects
41 41
   end
  42
+
  43
+  it "should build a new resource with attributes from current ability" do
  44
+    @params[:action] = "new"
  45
+    @ability.can(:create, Project, :name => "from conditions")
  46
+    stub(@controller).build_resource { Struct.new(:name).new }
  47
+    resource = CanCan::InheritedResource.new(@controller)
  48
+    resource.load_resource
  49
+    @controller.instance_variable_get(:@project).name.should == "from conditions"
  50
+  end
  51
+
  52
+  it "should override initial attributes with params" do
  53
+    @params.merge!(:action => "new", :project => {:name => "from params"})
  54
+    @ability.can(:create, Project, :name => "from conditions")
  55
+    stub(@controller).build_resource { Struct.new(:name).new }
  56
+    resource = CanCan::ControllerResource.new(@controller)
  57
+    resource.load_resource
  58
+    @controller.instance_variable_get(:@project).name.should == "from params"
  59
+  end
42 60
 end

0 notes on commit b965f5b

Please sign in to comment.
Something went wrong with that request. Please try again.