jcfischer / make_resourceful

Hampton Catlins and Nex3's make_resourceful plugin

This URL has Read+Write access

make_resourceful / spec / response_spec.rb
100644 38 lines (30 sloc) 1.205 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
require File.dirname(__FILE__) + '/spec_helper'
 
describe Resourceful::Response, "when first created" do
  before(:each) { @response = Resourceful::Response.new }
 
  it "should have an empty formats array" do
    @response.formats.should == []
  end
end
 
describe Resourceful::Response, "with a few formats" do
  before :each do
    @response = Resourceful::Response.new
    @response.html
    @response.js {'javascript'}
    @response.xml {'xml'}
  end
 
  it "should store the formats and blocks" do
    @response.formats.should have_any {|f,p| f == :js && p.call == 'javascript'}
    @response.formats.should have_any {|f,p| f == :xml && p.call == 'xml'}
  end
 
  it "should give formats without a block an empty block" do
    @response.formats.should have_any {|f,p| f == :html && Proc === p && p.call.nil?}
  end
 
  it "shouldn't allow duplicate formats" do
    @response.js {'not javascript'}
    @response.formats.should have_any {|f,p| f == :js && p.call == 'javascript'}
    @response.formats.should_not have_any {|f,p| f == :js && p.call == 'not javascript'}
  end
 
  it "should keep the formats in sorted order" do
    @response.formats.map(&:first).should == [:html, :js, :xml]
  end
end