1 # -*- encoding: utf-8 -*-
5 describe LicensesController do
7 @admin = FactoryGirl.create :admin
8 @lg = FactoryGirl.create :license_group
9 @sp = FactoryGirl.create :system_picture
10 @user = FactoryGirl.create( :user_yas)
11 @author = FactoryGirl.create :author, :user_id => @user.id
12 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
15 describe '一覧表示に於いて' do
17 @l = FactoryGirl.create :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 'ライセンスモデルにjson一覧出力オプションを問い合わせている' do
46 License.should_receive(:list_json_opt).exactly(1)
47 get :index, :format => :json
49 it 'データがリスト構造になっている' do
50 get :index, :format => :json
51 json = JSON.parse response.body
52 json.should have_at_least(3).items
54 it 'リストの先頭くらいはライセンスっぽいものであって欲しい' do
55 get :index, :format => :json
56 json = JSON.parse response.body
57 json.first.has_key?("name").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 @l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
78 License.stub(:show).and_return(@l)
80 context 'つつがなく終わるとき' do
81 it 'ステータスコード200 OKを返す' do
82 get :show, :id => @l.id
83 response.should be_success
85 it 'ライセンスモデルに単体取得を問い合わせている' do
86 License.should_receive(:show).exactly(1)
89 it '@licenseにアレを取得している' do
90 get :show, :id => @l.id
91 assigns(:license).id.should eq(@l.id)
94 it 'showテンプレートを描画する' do
95 get :show, :id => @l.id
96 response.should render_template("show")
101 get :show, :id => @l.id, :format => :json
102 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
104 it 'ライセンスモデルにjson単体出力オプションを問い合わせている' do
105 License.should_receive(:show_json_opt).exactly(1)
106 get :show, :id => @l.id, :format => :json
109 get :show, :id => @l.id, :format => :json
110 json = JSON.parse response.body
111 json["name"].should match(/peta/)
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 => @l.id
123 response.status.should eq 200