1 # -*- encoding: utf-8 -*-
5 describe LicensesController do
7 @admin = Factory :admin
8 @lg = Factory :license_group
9 @sp = Factory :system_picture
10 @user = Factory( :user_yas)
11 @author = @user.author
12 @artist = Factory :artist_yas, :author_id => @author.id
15 describe '一覧表示に於いて' do
17 @l = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
19 License.stub(:list).and_return([@l, @l, @l])
21 context 'つつがなく終わるとき' do
22 it 'ステータスコード200 OKを返す' do
24 response.should be_success
26 it 'ライセンスモデルに一覧を問い合わせている' do
27 License.should_receive(:list).exactly(1)
30 it '@licensesにリストを取得している' do
32 assigns(:licenses).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 'データがリスト構造になっている' do
46 get :index, :format => :json
47 json = JSON.parse response.body
48 json.should have_at_least(3).items
50 it 'リストの先頭くらいはライセンスっぽいものであって欲しい' do
51 get :index, :format => :json
52 json = JSON.parse response.body
53 json.first.has_key?("url").should be_true
57 context '作家権限がないとき' do
61 it 'ステータスコード200 okを返す' do
63 response.status.should eq 200
68 describe '単体表示に於いて' do
71 @l = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
72 License.stub(:show).and_return(@l)
74 context 'つつがなく終わるとき' do
75 it 'ステータスコード200 OKを返す' do
76 get :show, :id => @l.id
77 response.should be_success
79 it 'ライセンスモデルに単体取得を問い合わせている' do
80 License.should_receive(:show).exactly(1)
83 it '@licenseにアレを取得している' do
84 get :show, :id => @l.id
85 assigns(:license).id.should eq(@l.id)
88 it 'showテンプレートを描画する' do
89 get :show, :id => @l.id
90 response.should render_template("show")
95 get :show, :id => @l.id, :format => :json
96 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
99 get :show, :id => @l.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 => @l.id
111 response.status.should eq 200