OSDN Git Service

fix: any
[pettanr/pettanr.git] / spec / controllers / license_groups_controller_spec.rb
1 # -*- encoding: utf-8 -*-
2 #ライセンスグループ
3 require 'spec_helper'
4
5 describe LicenseGroupsController do
6   before do
7     @admin = FactoryGirl.create :admin
8     @user = FactoryGirl.create( :user_yas)
9     @author = FactoryGirl.create :author, :user_id => @user.id
10     @sp = FactoryGirl.create :system_picture
11     @lg = FactoryGirl.create :license_group, :name => 'peta'
12     @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
13   end
14
15 if MagicNumber['run_mode'] == 1
16   describe '一覧表示に於いて' do
17     before do
18       sign_in @user
19       LicenseGroup.stub(:list).and_return([@lg, @lg, @lg])
20     end
21     context 'つつがなく終わるとき' do
22       it 'ステータスコード200 OKを返す' do
23         get :index
24         response.should be_success 
25       end
26       it 'ライセンスグループモデルに一覧を問い合わせている' do
27         LicenseGroup.should_receive(:list).exactly(1)
28         get :index
29       end
30       it '@license_groupsにリストを取得している' do
31         get :index
32         assigns(:license_groups).should have_at_least(3).items
33       end
34       context 'html形式' do
35         it 'indexテンプレートを描画する' do
36           get :index
37           response.should render_template("index")
38         end
39       end
40       context 'json形式' do
41         it 'jsonデータを返す' do
42           get :index, :format => :json
43           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
44         end
45         it 'ライセンスグループモデルにjson一覧出力オプションを問い合わせている' do
46           LicenseGroup.should_receive(:list_json_opt).exactly(1)
47           get :index, :format => :json
48         end
49         it 'データがリスト構造になっている' do
50           get :index, :format => :json
51           json = JSON.parse response.body
52           json.should have_at_least(3).items
53         end
54         it 'リストの先頭くらいはライセンスグループっぽいものであって欲しい' do
55           get :index, :format => :json
56           json = JSON.parse response.body
57           json.first.has_key?("name").should be_true
58           json.first.has_key?("classname").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       LicenseGroup.stub(:show).and_return(@lg)
79     end
80     context 'つつがなく終わるとき' do
81       it 'ステータスコード200 OKを返す' do
82         get :show, :id => @lg.id
83         response.should be_success
84       end
85       it 'ライセンスモデルに単体取得を問い合わせている' do
86         LicenseGroup.should_receive(:show).exactly(1)
87         get :show
88       end
89       it '@license_groupにアレを取得している' do
90         get :show, :id => @lg.id
91         assigns(:license_group).id.should eq(@lg.id)
92       end
93       context 'html形式' do
94         it 'showテンプレートを描画する' do
95           get :show, :id => @lg.id
96           response.should render_template("show")
97         end
98       end
99       context 'json形式' do
100         it 'jsonデータを返す' do
101           get :show, :id => @lg.id, :format => :json
102           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
103         end
104         it 'ライセンスグループモデルにjson単体出力オプションを問い合わせている' do
105           LicenseGroup.should_receive(:show_json_opt).exactly(1)
106           get :show, :id => @lg.id, :format => :json
107         end
108         it 'データがアレになっている' do
109           get :show, :id => @lg.id, :format => :json
110           json = JSON.parse response.body
111           json["name"].should match(/peta/)
112           json["classname"].should_not be_nil
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 => @lg.id
124         response.status.should eq 200
125       end
126     end
127   end
128   
129 else
130   describe '一覧表示に於いて' do
131     before do
132       sign_in @user
133       LicenseGroup.stub(:list).and_return([@lg, @lg, @lg])
134     end
135     context 'つつがなく終わるとき' do
136       it 'ステータスコード200 OKを返す' do
137         get :index
138         response.should be_success 
139       end
140       context 'html形式' do
141         it 'indexテンプレートを描画する' do
142           get :index
143           response.should render_template("index")
144         end
145       end
146       context 'json形式' do
147         it 'jsonデータを返す' do
148           get :index, :format => :json
149           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
150         end
151       end
152     end
153     context '作家権限がないとき' do
154       before do
155         sign_out @user
156       end
157       it 'ステータスコード200 okを返す' do
158         get :index
159         response.status.should eq 200
160       end
161       context 'html形式' do
162         it 'indexテンプレートを描画する' do
163           get :index
164           response.should render_template("index")
165         end
166       end
167       context 'json形式' do
168         it 'jsonデータを返す' do
169           get :index, :format => :json
170           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
171         end
172       end
173     end
174   end
175   
176   describe '単体表示に於いて' do
177     before do
178       sign_in @user
179       LicenseGroup.stub(:show).and_return(@lg)
180     end
181     context 'つつがなく終わるとき' do
182       it 'ステータスコード200 OKを返す' do
183         get :show, :id => @lg.id
184         response.should be_success
185       end
186       context 'html形式' do
187         it 'showテンプレートを描画する' do
188           get :show, :id => @lg.id
189           response.should render_template("show")
190         end
191       end
192       context 'json形式' do
193         it 'jsonデータを返す' do
194           get :show, :id => @lg.id, :format => :json
195           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
196         end
197       end
198     end
199     context '作家権限がないとき' do
200       before do
201         sign_out @user
202       end
203       it 'ステータスコード200 okを返す' do
204         get :show, :id => @lg.id
205         response.status.should eq 200
206       end
207       context 'html形式' do
208         it 'showテンプレートを描画する' do
209           get :show, :id => @lg.id
210           response.should render_template("show")
211         end
212       end
213       context 'json形式' do
214         it 'jsonデータを返す' do
215           get :show, :id => @lg.id, :format => :json
216           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
217         end
218       end
219     end
220   end
221   
222 end
223 end