1 # -*- encoding: utf-8 -*-
5 describe LicensesController 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
15 if MagicNumber['run_mode'] == 1
16 describe '一覧表示に於いて' do
18 @l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
20 License.stub(:list).and_return([@l, @l, @l])
22 context 'つつがなく終わるとき' do
23 it 'ステータスコード200 OKを返す' do
25 response.should be_success
27 it 'ライセンスモデルに一覧を問い合わせている' do
28 License.should_receive(:list).exactly(1)
31 it '@licensesにリストを取得している' do
33 assigns(:licenses).should have_at_least(3).items
36 it 'indexテンプレートを描画する' do
38 response.should render_template("index")
43 get :index, :format => :json
44 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
46 it 'ライセンスモデルにjson一覧出力オプションを問い合わせている' do
47 License.should_receive(:list_json_opt).exactly(1)
48 get :index, :format => :json
50 it 'データがリスト構造になっている' do
51 get :index, :format => :json
52 json = JSON.parse response.body
53 json.should have_at_least(3).items
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
64 context '作家権限がないとき' do
68 it 'ステータスコード200 okを返す' do
70 response.status.should eq 200
75 describe '単体表示に於いて' do
78 @l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
79 License.stub(:show).and_return(@l)
81 context 'つつがなく終わるとき' do
82 it 'ステータスコード200 OKを返す' do
83 get :show, :id => @l.id
84 response.should be_success
86 it 'ライセンスモデルに単体取得を問い合わせている' do
87 License.should_receive(:show).exactly(1)
90 it '@licenseにアレを取得している' do
91 get :show, :id => @l.id
92 assigns(:license).id.should eq(@l.id)
95 it 'showテンプレートを描画する' do
96 get :show, :id => @l.id
97 response.should render_template("show")
102 get :show, :id => @l.id, :format => :json
103 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
105 it 'ライセンスモデルにjson単体出力オプションを問い合わせている' do
106 License.should_receive(:show_json_opt).exactly(1)
107 get :show, :id => @l.id, :format => :json
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
118 context '作家権限がないとき' do
122 it 'ステータスコード200 okを返す' do
123 get :show, :id => @l.id
124 response.status.should eq 200
129 describe '管理名検索の一覧に於いて' do
131 @l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
133 License.stub(:list_by_name).with(any_args).and_return([@l])
135 context 'つつがなく終わるとき' do
136 it 'ライセンスモデルに管理名検索を問い合わせている' do
137 License.should_receive(:list_by_name).exactly(1)
138 get :search, :name => @l.name
140 it '@licensesにリストを取得している' do
141 get :search, :name => @l.name
142 assigns(:licenses).should have_at_least(1).items
145 it 'ステータスコード200 OKを返す' do
146 get :search, :name => @l.name
147 response.should be_success
149 it 'searchテンプレートを描画する' do
150 get :search, :name => @l.name
151 response.should render_template("search")
155 it 'ステータスコード200 OKを返す' do
156 get :search, :name => @l.name, :format => :json
157 response.should be_success
160 get :search, :name => @l.name, :format => :json
161 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
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
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
177 context 'ユーザ権限がないとき' do
181 it 'ステータスコード200 okを返す' do
183 response.status.should eq 200
189 describe '一覧表示に於いて' do
191 @l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
193 License.stub(:list).and_return([@l, @l, @l])
195 context 'つつがなく終わるとき' do
196 it 'ステータスコード200 OKを返す' do
198 response.should be_success
201 it 'indexテンプレートを描画する' do
203 response.should render_template("index")
208 get :index, :format => :json
209 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
213 context '作家権限がないとき' do
217 it 'ステータスコード200 okを返す' do
219 response.status.should eq 200
222 it 'indexテンプレートを描画する' do
224 response.should render_template("index")
229 get :index, :format => :json
230 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
236 describe '単体表示に於いて' do
239 @l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
240 License.stub(:show).and_return(@l)
242 context 'つつがなく終わるとき' do
243 it 'ステータスコード200 OKを返す' do
244 get :show, :id => @l.id
245 response.should be_success
248 it 'showテンプレートを描画する' do
249 get :show, :id => @l.id
250 response.should render_template("show")
255 get :show, :id => @l.id, :format => :json
256 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
260 context '作家権限がないとき' do
264 it 'ステータスコード200 okを返す' do
265 get :show, :id => @l.id
266 response.status.should eq 200
269 it 'showテンプレートを描画する' do
270 get :show, :id => @l.id
271 response.should render_template("show")
276 get :show, :id => @l.id, :format => :json
277 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)