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 describe '一覧表示に於いて' do
18 LicenseGroup.stub(:list).and_return([@lg, @lg, @lg])
20 context 'つつがなく終わるとき' do
21 it 'ステータスコード200 OKを返す' do
23 response.should be_success
25 it 'ライセンスグループモデルに一覧を問い合わせている' do
26 LicenseGroup.should_receive(:list).exactly(1)
29 it '@license_groupsにリストを取得している' do
31 assigns(:license_groups).should have_at_least(3).items
34 it 'indexテンプレートを描画する' do
36 response.should render_template("index")
41 get :index, :format => :json
42 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
44 it 'ライセンスグループモデルにjson一覧出力オプションを問い合わせている' do
45 LicenseGroup.should_receive(:list_json_opt).exactly(1)
46 get :index, :format => :json
48 it 'データがリスト構造になっている' do
49 get :index, :format => :json
50 json = JSON.parse response.body
51 json.should have_at_least(3).items
53 it 'リストの先頭くらいはライセンスグループっぽいものであって欲しい' do
54 get :index, :format => :json
55 json = JSON.parse response.body
56 json.first.has_key?("name").should be_true
57 json.first.has_key?("classname").should be_true
58 json.first.has_key?("caption").should be_true
59 json.first.has_key?("url").should be_true
63 context '作家権限がないとき' do
67 it 'ステータスコード200 okを返す' do
69 response.status.should eq 200
74 describe '単体表示に於いて' do
77 LicenseGroup.stub(:show).and_return(@lg)
79 context 'つつがなく終わるとき' do
80 it 'ステータスコード200 OKを返す' do
81 get :show, :id => @lg.id
82 response.should be_success
84 it 'ライセンスモデルに単体取得を問い合わせている' do
85 LicenseGroup.should_receive(:show).exactly(1)
88 it '@license_groupにアレを取得している' do
89 get :show, :id => @lg.id
90 assigns(:license_group).id.should eq(@lg.id)
93 it 'showテンプレートを描画する' do
94 get :show, :id => @lg.id
95 response.should render_template("show")
100 get :show, :id => @lg.id, :format => :json
101 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
103 it 'ライセンスグループモデルにjson単体出力オプションを問い合わせている' do
104 LicenseGroup.should_receive(:show_json_opt).exactly(1)
105 get :show, :id => @lg.id, :format => :json
108 get :show, :id => @lg.id, :format => :json
109 json = JSON.parse response.body
110 json["name"].should match(/peta/)
111 json["classname"].should_not be_nil
112 json["caption"].should_not be_nil
113 json["url"].should_not be_nil
117 context '作家権限がないとき' do
121 it 'ステータスコード200 okを返す' do
122 get :show, :id => @lg.id
123 response.status.should eq 200