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 'データがリスト構造になっている' do
44 get :index, :format => :json
45 json = JSON.parse response.body
46 json.should have_at_least(3).items
48 it 'リストの先頭くらいはライセンスグループっぽいものであって欲しい' do
49 get :index, :format => :json
50 json = JSON.parse response.body
51 json.first.has_key?("name").should be_true
52 json.first.has_key?("classname").should be_true
53 json.first.has_key?("caption").should be_true
54 json.first.has_key?("url").should be_true
58 context '作家権限がないとき' do
62 it 'ステータスコード200 okを返す' do
64 response.status.should eq 200
69 describe '単体表示に於いて' do
72 LicenseGroup.stub(:show).and_return(@lg)
74 context 'つつがなく終わるとき' do
75 it 'ステータスコード200 OKを返す' do
76 get :show, :id => @lg.id
77 response.should be_success
79 it 'ライセンスモデルに単体取得を問い合わせている' do
80 LicenseGroup.should_receive(:show).exactly(1)
83 it '@license_groupにアレを取得している' do
84 get :show, :id => @lg.id
85 assigns(:license_group).id.should eq(@lg.id)
88 it 'showテンプレートを描画する' do
89 get :show, :id => @lg.id
90 response.should render_template("show")
95 get :show, :id => @lg.id, :format => :json
96 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
99 get :show, :id => @lg.id, :format => :json
100 json = JSON.parse response.body
101 json["name"].should match(/peta/)
105 context '作家権限がないとき' do
109 it 'ステータスコード200 okを返す' do
110 get :show, :id => @lg.id
111 response.status.should eq 200