OSDN Git Service

fix: any
[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 = FactoryGirl.create :admin
8     @lg = FactoryGirl.create :license_group
9     @sp = FactoryGirl.create :system_picture
10     @user = FactoryGirl.create( :user_yas)
11     @author = FactoryGirl.create :author, :user_id => @user.id
12     @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
13   end
14
15 if MagicNumber['run_mode'] == 1
16   describe '一覧表示に於いて' do
17     before do
18       @l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
19       sign_in @user
20       License.stub(:list).and_return([@l, @l, @l])
21     end
22     context 'つつがなく終わるとき' do
23       it 'ステータスコード200 OKを返す' do
24         get :index
25         response.should be_success 
26       end
27       it 'ライセンスモデルに一覧を問い合わせている' do
28         License.should_receive(:list).exactly(1)
29         get :index
30       end
31       it '@licensesにリストを取得している' do
32         get :index
33         assigns(:licenses).should have_at_least(3).items
34       end
35       context 'html形式' do
36         it 'indexテンプレートを描画する' do
37           get :index
38           response.should render_template("index")
39         end
40       end
41       context 'json形式' do
42         it 'jsonデータを返す' do
43           get :index, :format => :json
44           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
45         end
46         it 'ライセンスモデルにjson一覧出力オプションを問い合わせている' do
47           License.should_receive(:list_json_opt).exactly(1)
48           get :index, :format => :json
49         end
50         it 'データがリスト構造になっている' do
51           get :index, :format => :json
52           json = JSON.parse response.body
53           json.should have_at_least(3).items
54         end
55         it 'リストの先頭くらいはライセンスっぽいものであって欲しい' do
56           get :index, :format => :json
57           json = JSON.parse response.body
58           json.first.has_key?("name").should be_true
59           json.first.has_key?("caption").should be_true
60           json.first.has_key?("url").should be_true
61         end
62       end
63     end
64     context '作家権限がないとき' do
65       before do
66         sign_out @user
67       end
68       it 'ステータスコード200 okを返す' do
69         get :index
70         response.status.should eq 200
71       end
72     end
73   end
74   
75   describe '単体表示に於いて' do
76     before do
77       sign_in @user
78       @l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
79       License.stub(:show).and_return(@l)
80     end
81     context 'つつがなく終わるとき' do
82       it 'ステータスコード200 OKを返す' do
83         get :show, :id => @l.id
84         response.should be_success
85       end
86       it 'ライセンスモデルに単体取得を問い合わせている' do
87         License.should_receive(:show).exactly(1)
88         get :show
89       end
90       it '@licenseにアレを取得している' do
91         get :show, :id => @l.id
92         assigns(:license).id.should eq(@l.id)
93       end
94       context 'html形式' do
95         it 'showテンプレートを描画する' do
96           get :show, :id => @l.id
97           response.should render_template("show")
98         end
99       end
100       context 'json形式' do
101         it 'jsonデータを返す' do
102           get :show, :id => @l.id, :format => :json
103           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
104         end
105         it 'ライセンスモデルにjson単体出力オプションを問い合わせている' do
106           License.should_receive(:show_json_opt).exactly(1)
107           get :show, :id => @l.id, :format => :json
108         end
109         it 'データがアレになっている' do
110           get :show, :id => @l.id, :format => :json
111           json = JSON.parse response.body
112           json["name"].should match(/peta/)
113           json["caption"].should_not be_nil
114           json["url"].should_not be_nil
115         end
116       end
117     end
118     context '作家権限がないとき' do
119       before do
120         sign_out @user
121       end
122       it 'ステータスコード200 okを返す' do
123         get :show, :id => @l.id
124         response.status.should eq 200
125       end
126     end
127   end
128   
129   describe '管理名検索の一覧に於いて' do
130     before do
131       @l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
132       sign_in @user
133       License.stub(:list_by_name).with(any_args).and_return([@l])
134     end
135     context 'つつがなく終わるとき' do
136       it 'ライセンスモデルに管理名検索を問い合わせている' do
137         License.should_receive(:list_by_name).exactly(1)
138         get :search, :name => @l.name
139       end
140       it '@licensesにリストを取得している' do
141         get :search, :name => @l.name
142         assigns(:licenses).should have_at_least(1).items
143       end
144       context 'html形式' do
145         it 'ステータスコード200 OKを返す' do
146           get :search, :name => @l.name
147           response.should be_success 
148         end
149         it 'searchテンプレートを描画する' do
150           get :search, :name => @l.name
151           response.should render_template("search")
152         end
153       end
154       context 'json形式' do
155         it 'ステータスコード200 OKを返す' do
156           get :search, :name => @l.name, :format => :json
157           response.should be_success 
158         end
159         it 'jsonデータを返す' do
160           get :search, :name => @l.name, :format => :json
161           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
162         end
163         it 'データがリスト構造になっている' do
164           get :search, :name => @l.name, :format => :json
165           json = JSON.parse response.body
166           json.should have_at_least(1).items
167         end
168         it 'リストの先頭くらいはライセンスっぽいものであって欲しい' do
169           get :search, :name => @l.name, :format => :json
170           json = JSON.parse response.body
171           json.first.has_key?("name").should be_true
172           json.first.has_key?("caption").should be_true
173           json.first.has_key?("url").should be_true
174         end
175       end
176     end
177     context 'ユーザ権限がないとき' do
178       before do
179         sign_out @user
180       end
181       it 'ステータスコード200 okを返す' do
182         get :index
183         response.status.should eq 200
184       end
185     end
186   end
187   
188 else
189   describe '一覧表示に於いて' do
190     before do
191       @l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
192       sign_in @user
193       License.stub(:list).and_return([@l, @l, @l])
194     end
195       context 'つつがなく終わるとき' do
196       it 'ステータスコード200 OKを返す' do
197         get :index
198         response.should be_success 
199       end
200       context 'html形式' do
201         it 'indexテンプレートを描画する' do
202           get :index
203           response.should render_template("index")
204         end
205       end
206       context 'json形式' do
207         it 'jsonデータを返す' do
208           get :index, :format => :json
209           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
210         end
211       end
212     end
213     context '作家権限がないとき' do
214       before do
215         sign_out @user
216       end
217       it 'ステータスコード200 okを返す' do
218         get :index
219         response.status.should eq 200
220       end
221       context 'html形式' do
222         it 'indexテンプレートを描画する' do
223           get :index
224           response.should render_template("index")
225         end
226       end
227       context 'json形式' do
228         it 'jsonデータを返す' do
229           get :index, :format => :json
230           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
231         end
232       end
233     end
234   end
235   
236   describe '単体表示に於いて' do
237     before do
238       sign_in @user
239       @l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
240       License.stub(:show).and_return(@l)
241     end
242     context 'つつがなく終わるとき' do
243       it 'ステータスコード200 OKを返す' do
244         get :show, :id => @l.id
245         response.should be_success
246       end
247       context 'html形式' do
248         it 'showテンプレートを描画する' do
249           get :show, :id => @l.id
250           response.should render_template("show")
251         end
252       end
253       context 'json形式' do
254         it 'jsonデータを返す' do
255           get :show, :id => @l.id, :format => :json
256           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
257         end
258       end
259     end
260     context '作家権限がないとき' do
261       before do
262         sign_out @user
263       end
264       it 'ステータスコード200 okを返す' do
265         get :show, :id => @l.id
266         response.status.should eq 200
267       end
268       context 'html形式' do
269         it 'showテンプレートを描画する' do
270           get :show, :id => @l.id
271           response.should render_template("show")
272         end
273       end
274       context 'json形式' do
275         it 'jsonデータを返す' do
276           get :show, :id => @l.id, :format => :json
277           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
278         end
279       end
280     end
281   end
282   
283 end
284 end