1 # -*- encoding: utf-8 -*-
5 describe LicenseGroupsController do
7 @admin = FactoryGirl.create :admin
8 @user = FactoryGirl.create( :user_yas)
9 @sp = FactoryGirl.create :system_picture
10 @lg = FactoryGirl.create :license_group, :name => 'peta'
11 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
14 describe '一覧表示に於いて' do
17 LicenseGroup.stub(:list).and_return([@lg, @lg, @lg])
19 context 'つつがなく終わるとき' do
20 it 'ステータスコード200 OKを返す' do
22 response.should be_success
24 it 'ライセンスグループモデルに一覧を問い合わせている' do
25 LicenseGroup.should_receive(:list).exactly(1)
28 it '@license_groupsにリストを取得している' do
30 assigns(:license_groups).should have_at_least(3).items
33 it 'indexテンプレートを描画する' do
35 response.should render_template("index")
40 get :index, :format => :json
41 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
43 it 'ライセンスグループモデルにjson一覧出力オプションを問い合わせている' do
44 LicenseGroup.should_receive(:list_json_opt).exactly(1)
45 get :index, :format => :json
47 it 'データがリスト構造になっている' do
48 get :index, :format => :json
49 json = JSON.parse response.body
50 json.should have_at_least(3).items
52 it 'リストの先頭くらいはライセンスグループっぽいものであって欲しい' do
53 get :index, :format => :json
54 json = JSON.parse response.body
55 json.first.has_key?("name").should be_true
56 json.first.has_key?("classname").should be_true
57 json.first.has_key?("caption").should be_true
58 json.first.has_key?("url").should be_true
62 context '作家権限がないとき' do
66 it 'ステータスコード200 okを返す' do
68 response.status.should eq 200
73 describe '単体表示に於いて' do
76 LicenseGroup.stub(:show).and_return(@lg)
78 context 'つつがなく終わるとき' do
79 it 'ステータスコード200 OKを返す' do
80 get :show, :id => @lg.id
81 response.should be_success
83 it 'ライセンスモデルに単体取得を問い合わせている' do
84 LicenseGroup.should_receive(:show).exactly(1)
87 it '@license_groupにアレを取得している' do
88 get :show, :id => @lg.id
89 assigns(:license_group).id.should eq(@lg.id)
92 it 'showテンプレートを描画する' do
93 get :show, :id => @lg.id
94 response.should render_template("show")
99 get :show, :id => @lg.id, :format => :json
100 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
102 it 'ライセンスグループモデルにjson単体出力オプションを問い合わせている' do
103 LicenseGroup.should_receive(:show_json_opt).exactly(1)
104 get :show, :id => @lg.id, :format => :json
107 get :show, :id => @lg.id, :format => :json
108 json = JSON.parse response.body
109 json["name"].should match(/peta/)
110 json["classname"].should_not be_nil
111 json["caption"].should_not be_nil
\r
112 json["url"].should_not be_nil
\r
116 context '作家権限がないとき' do
120 it 'ステータスコード200 okを返す' do
121 get :show, :id => @lg.id
122 response.status.should eq 200