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
130 describe '一覧表示に於いて' do
132 @l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
134 License.stub(:list).and_return([@l, @l, @l])
136 context 'つつがなく終わるとき' do
137 it 'ステータスコード200 OKを返す' do
139 response.should be_success
142 it 'indexテンプレートを描画する' do
144 response.should render_template("index")
149 get :index, :format => :json
150 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
154 context '作家権限がないとき' do
158 it 'ステータスコード200 okを返す' do
160 response.status.should eq 200
163 it 'indexテンプレートを描画する' do
165 response.should render_template("index")
170 get :index, :format => :json
171 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
177 describe '単体表示に於いて' do
180 @l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
181 License.stub(:show).and_return(@l)
183 context 'つつがなく終わるとき' do
184 it 'ステータスコード200 OKを返す' do
185 get :show, :id => @l.id
186 response.should be_success
189 it 'showテンプレートを描画する' do
190 get :show, :id => @l.id
191 response.should render_template("show")
196 get :show, :id => @l.id, :format => :json
197 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
201 context '作家権限がないとき' do
205 it 'ステータスコード200 okを返す' do
206 get :show, :id => @l.id
207 response.status.should eq 200
210 it 'showテンプレートを描画する' do
211 get :show, :id => @l.id
212 response.should render_template("show")
217 get :show, :id => @l.id, :format => :json
218 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)