OSDN Git Service

t#30322:create provider license import func
[pettanr/pettanr.git] / spec / controllers / licenses_controller_spec.rb
1 # -*- encoding: utf-8 -*-
2 #ライセンス
3 require 'spec_helper'
4
5 describe LicensesController do
6   before 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
13   end
14
15   describe '一覧表示に於いて' do
16     before do
17       @l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
18       sign_in @user
19       License.stub(:list).and_return([@l, @l, @l])
20     end
21     context 'つつがなく終わるとき' do
22       it 'ステータスコード200 OKを返す' do
23         get :index
24         response.should be_success 
25       end
26       it 'ライセンスモデルに一覧を問い合わせている' do
27         License.should_receive(:list).exactly(1)
28         get :index
29       end
30       it '@licensesにリストを取得している' do
31         get :index
32         assigns(:licenses).should have_at_least(3).items
33       end
34       context 'html形式' do
35         it 'indexテンプレートを描画する' do
36           get :index
37           response.should render_template("index")
38         end
39       end
40       context 'json形式' do
41         it 'jsonデータを返す' do
42           get :index, :format => :json
43           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
44         end
45         it 'ライセンスモデルにjson一覧出力オプションを問い合わせている' do
46           License.should_receive(:list_json_opt).exactly(1)
47           get :index, :format => :json
48         end
49         it 'データがリスト構造になっている' do
50           get :index, :format => :json
51           json = JSON.parse response.body
52           json.should have_at_least(3).items
53         end
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
60         end
61       end
62     end
63     context '作家権限がないとき' do
64       before do
65         sign_out @user
66       end
67       it 'ステータスコード200 okを返す' do
68         get :index
69         response.status.should eq 200
70       end
71     end
72   end
73   
74   describe '単体表示に於いて' do
75     before do
76       sign_in @user
77       @l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
78       License.stub(:show).and_return(@l)
79     end
80     context 'つつがなく終わるとき' do
81       it 'ステータスコード200 OKを返す' do
82         get :show, :id => @l.id
83         response.should be_success
84       end
85       it 'ライセンスモデルに単体取得を問い合わせている' do
86         License.should_receive(:show).exactly(1)
87         get :show
88       end
89       it '@licenseにアレを取得している' do
90         get :show, :id => @l.id
91         assigns(:license).id.should eq(@l.id)
92       end
93       context 'html形式' do
94         it 'showテンプレートを描画する' do
95           get :show, :id => @l.id
96           response.should render_template("show")
97         end
98       end
99       context 'json形式' do
100         it 'jsonデータを返す' do
101           get :show, :id => @l.id, :format => :json
102           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
103         end
104         it 'ライセンスモデルにjson単体出力オプションを問い合わせている' do
105           License.should_receive(:show_json_opt).exactly(1)
106           get :show, :id => @l.id, :format => :json
107         end
108         it 'データがアレになっている' do
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
114         end
115       end
116     end
117     context '作家権限がないとき' do
118       before do
119         sign_out @user
120       end
121       it 'ステータスコード200 okを返す' do
122         get :show, :id => @l.id
123         response.status.should eq 200
124       end
125     end
126   end
127   
128 end