1 # -*- encoding: utf-8 -*-
5 describe LicenseGroupsController do
7 @admin = Factory :admin
8 @user = Factory( :user_yas)
9 @lg = Factory :license_group, :name => 'peta'
12 describe '一覧表示に於いて' do
15 LicenseGroup.stub(:list).and_return([@lg, @lg, @lg])
17 context 'つつがなく終わるとき' do
18 it 'ステータスコード200 OKを返す' do
20 response.should be_success
22 it 'ライセンスモデルに一覧を問い合わせている' do
23 LicenseGroup.should_receive(:list).exactly(1)
26 it '@license_groupsにリストを取得している' do
28 assigns(:license_groups).should have_at_least(3).items
31 it 'indexテンプレートを描画する' do
33 response.should render_template("index")
38 get :index, :format => :json
39 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
41 it 'データがリスト構造になっている' do
42 get :index, :format => :json
43 json = JSON.parse response.body
44 json.should have_at_least(3).items
46 it 'リストの先頭くらいはライセンスグループっぽいものであって欲しい' do
47 get :index, :format => :json
48 json = JSON.parse response.body
49 json.first.has_key?("name").should be_true
50 json.first.has_key?("classname").should be_true
51 json.first.has_key?("caption").should be_true
52 json.first.has_key?("url").should be_true
56 context '作家権限がないとき' do
60 it 'ステータスコード200 okを返す' do
62 response.status.should eq 200
67 describe '単体表示に於いて' do
70 LicenseGroup.stub(:show).and_return(@lg)
72 context 'つつがなく終わるとき' do
73 it 'ステータスコード200 OKを返す' do
74 get :show, :id => @lg.id
75 response.should be_success
77 it 'ライセンスモデルに単体取得を問い合わせている' do
78 LicenseGroup.should_receive(:show).exactly(1)
81 it '@license_groupにアレを取得している' do
82 get :show, :id => @lg.id
83 assigns(:license_group).id.should eq(@lg.id)
86 it 'showテンプレートを描画する' do
87 get :show, :id => @lg.id
88 response.should render_template("show")
93 get :show, :id => @lg.id, :format => :json
94 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
97 get :show, :id => @lg.id, :format => :json
98 json = JSON.parse response.body
99 json["name"].should match(/peta/)
103 context '作家権限がないとき' do
107 it 'ステータスコード200 okを返す' do
108 get :show, :id => @lg.id
109 response.status.should eq 200