1 # -*- encoding: utf-8 -*-
5 describe LicenseGroupsController 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
15 if MagicNumber['run_mode'] == 1
16 describe '一覧表示に於いて' do
19 LicenseGroup.stub(:list).and_return([@lg, @lg, @lg])
21 context 'つつがなく終わるとき' do
22 it 'ステータスコード200 OKを返す' do
24 response.should be_success
26 it 'ライセンスグループモデルに一覧を問い合わせている' do
27 LicenseGroup.should_receive(:list).exactly(1)
30 it '@license_groupsにリストを取得している' do
32 assigns(:license_groups).should have_at_least(3).items
35 it 'indexテンプレートを描画する' do
37 response.should render_template("index")
42 get :index, :format => :json
43 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
45 it 'ライセンスグループモデルにjson一覧出力オプションを問い合わせている' do
46 LicenseGroup.should_receive(:list_json_opt).exactly(1)
47 get :index, :format => :json
49 it 'データがリスト構造になっている' do
50 get :index, :format => :json
51 json = JSON.parse response.body
52 json.should have_at_least(3).items
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
64 context '作家権限がないとき' do
68 it 'ステータスコード200 okを返す' do
70 response.status.should eq 200
75 describe '単体表示に於いて' do
78 LicenseGroup.stub(:show).and_return(@lg)
80 context 'つつがなく終わるとき' do
81 it 'ステータスコード200 OKを返す' do
82 get :show, :id => @lg.id
83 response.should be_success
85 it 'ライセンスモデルに単体取得を問い合わせている' do
86 LicenseGroup.should_receive(:show).exactly(1)
89 it '@license_groupにアレを取得している' do
90 get :show, :id => @lg.id
91 assigns(:license_group).id.should eq(@lg.id)
94 it 'showテンプレートを描画する' do
95 get :show, :id => @lg.id
96 response.should render_template("show")
101 get :show, :id => @lg.id, :format => :json
102 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
104 it 'ライセンスグループモデルにjson単体出力オプションを問い合わせている' do
105 LicenseGroup.should_receive(:show_json_opt).exactly(1)
106 get :show, :id => @lg.id, :format => :json
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
118 context '作家権限がないとき' do
122 it 'ステータスコード200 okを返す' do
123 get :show, :id => @lg.id
124 response.status.should eq 200
130 describe '一覧表示に於いて' do
133 LicenseGroup.stub(:list).and_return([@lg, @lg, @lg])
135 context 'つつがなく終わるとき' do
136 it 'ステータスコード200 OKを返す' do
138 response.should be_success
141 it 'indexテンプレートを描画する' do
143 response.should render_template("index")
148 get :index, :format => :json
149 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
153 context '作家権限がないとき' do
157 it 'ステータスコード200 okを返す' do
159 response.status.should eq 200
162 it 'indexテンプレートを描画する' do
164 response.should render_template("index")
169 get :index, :format => :json
170 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
176 describe '単体表示に於いて' do
179 LicenseGroup.stub(:show).and_return(@lg)
181 context 'つつがなく終わるとき' do
182 it 'ステータスコード200 OKを返す' do
183 get :show, :id => @lg.id
184 response.should be_success
187 it 'showテンプレートを描画する' do
188 get :show, :id => @lg.id
189 response.should render_template("show")
194 get :show, :id => @lg.id, :format => :json
195 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
199 context '作家権限がないとき' do
203 it 'ステータスコード200 okを返す' do
204 get :show, :id => @lg.id
205 response.status.should eq 200
208 it 'showテンプレートを描画する' do
209 get :show, :id => @lg.id
210 response.should render_template("show")
215 get :show, :id => @lg.id, :format => :json
216 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)