public
Description: resources_controller rails plugin: rc makes RESTful controllers fun
Homepage: http://plugins.ardes.com/doc/resources_controller
Clone URL: git://github.com/ianwhite/resources_controller.git
Click here to lend your support to: resources_controller and make a donation at www.pledgie.com !
resources_controller / spec / controllers / resource_saved_spec.rb
100644 48 lines (35 sloc) 1.487 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
require File.expand_path(File.join(File.dirname(__FILE__), '../app'))
 
describe CommentsController, "#resource_saved" do
  describe "Comment.new(<invalid attrs>)" do
    before { @controller.resource = Comment.new }
    
    it { @controller.should_not be_resource_saved }
  
    describe ".save" do
      before { @controller.resource.save }
 
      it { @controller.should_not be_resource_saved }
 
      describe "then update_attributes(<valid attrs>)" do
        before { @controller.resource.update_attributes :user => User.create!, :post => Post.create! }
        
        it { @controller.should be_resource_saved }
      end
    end
  end
    
  describe "Comment.find(<id>)" do
    before do
      Comment.create! :user => User.create!, :post => Post.create!
      @controller.resource = Comment.find(:first)
    end
    
    it { @controller.should be_resource_saved }
 
    it ".save should be saved" do
      @controller.resource.save
      @controller.should be_resource_saved
    end
 
    describe "then update_attributes(<invalid attrs>)" do
      before { @controller.resource.update_attributes :user => nil }
      
      it { @controller.should_not be_resource_saved }
    end
    
    describe "then update_attributes(<new valid attrs>)" do
      before { @controller.resource.update_attributes :user => User.create! }
      
      it { @controller.should be_resource_saved }
    end
  end
end