OSDN Git Service

pass test
[pettanr/pettanr.git] / spec / controllers / licenses_controller_spec.rb
1 # -*- encoding: utf-8 -*-
2 #ライセンス
3 require 'spec_helper'
4
5 describe LicensesController do
6   before do
7     @admin = Factory :admin
8     @lc = Factory :license
9     @cl = Factory :common_license, :license_id => @lc.id
10     @user = Factory( :user_yas)
11     @author = @user.author
12     @artist = Factory :artist_yas, :author_id => @author.id
13   end
14
15   describe '一覧表示に於いて' do
16     before do
17       sign_in @user
18       License.stub(:list).and_return([@lc, @lc, @lc])
19     end
20     context 'パラメータpageについて' do
21       it '@pageに値が入る' do
22         get :index, :page => 5
23         assigns(:page).should eq 5
24       end
25       it '省略されると@pageに1値が入る' do
26         get :index
27         assigns(:page).should eq 1
28       end
29       it '与えられたpage_sizeがセットされている' do
30         get :index, :page_size => 15
31         assigns(:page_size).should eq 15
32       end
33       it '省略されると@page_sizeにデフォルト値が入る' do
34         get :index
35         assigns(:page_size).should eq License.default_page_size
36       end
37       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
38         get :index, :page_size => 1500
39         assigns(:page_size).should eq License.max_page_size
40       end
41       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
42         get :index, :page_size => 0
43         assigns(:page_size).should eq License.default_page_size
44       end
45     end
46     context 'つつがなく終わるとき' do
47       it 'ステータスコード200 OKを返す' do
48         get :index
49         response.should be_success 
50       end
51       it 'ライセンスモデルに一覧を問い合わせている' do
52         License.should_receive(:list).exactly(1)
53         get :index
54       end
55       it '@licensesにリストを取得している' do
56         get :index
57         assigns(:licenses).should have_at_least(3).items
58       end
59       context 'html形式' do
60         it 'indexテンプレートを描画する' do
61           get :index
62           response.should render_template("index")
63         end
64       end
65       context 'json形式' do
66         it 'jsonデータを返す' do
67           get :index, :format => :json
68           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
69         end
70         it 'データがリスト構造になっている' do
71           get :index, :format => :json
72           json = JSON.parse response.body
73           json.should have_at_least(3).items
74         end
75         it 'リストの先頭くらいはライセンスっぽいものであって欲しい' do
76           get :index, :format => :json
77           json = JSON.parse response.body
78           json.first.has_key?("url").should be_true
79         end
80       end
81     end
82     context '作家権限がないとき' do
83       before do
84         sign_out @user
85       end
86       it 'ステータスコード200 okを返す' do
87         get :index
88         response.status.should eq 200
89       end
90     end
91   end
92   
93   describe '単体表示に於いて' do
94     before do
95       sign_in @user
96       License.stub(:show).and_return(@lc)
97     end
98     context 'つつがなく終わるとき' do
99       it 'ステータスコード200 OKを返す' do
100         get :show, :id => @lc.id
101         response.should be_success
102       end
103       it 'ライセンスモデルに単体取得を問い合わせている' do
104         License.should_receive(:show).exactly(1)
105         get :show
106       end
107       it '@licenseにアレを取得している' do
108         get :show, :id => @lc.id
109         assigns(:license).id.should eq(@lc.id)
110       end
111       context 'html形式' do
112         it 'showテンプレートを描画する' do
113           get :show, :id => @lc.id
114           response.should render_template("show")
115         end
116       end
117       context 'json形式' do
118         it 'jsonデータを返す' do
119           get :show, :id => @lc.id, :format => :json
120           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
121         end
122         it 'データがアレになっている' do
123           get :show, :id => @lc.id, :format => :json
124           json = JSON.parse response.body
125           json["name"].should match(/peta/)
126         end
127       end
128     end
129     context '作家権限がないとき' do
130       before do
131         sign_out @user
132       end
133       it 'ステータスコード200 okを返す' do
134         get :show, :id => @lc.id
135         response.status.should eq 200
136       end
137     end
138   end
139   
140 end