1 # -*- encoding: utf-8 -*-
5 describe ProvidersController do
7 @admin = FactoryGirl.create :admin
8 @sp = FactoryGirl.create :system_picture
9 @lg = FactoryGirl.create :license_group
10 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
11 @user = FactoryGirl.create :user_yas
12 @author = @user.author #ユーザ作成時に連動して作成される
15 describe '一覧表示に於いて' do
17 @ps = FactoryGirl.create :provider_status
18 @provider = FactoryGirl.create :provider, :provider_status_id => @ps.id
19 Provider.stub(:list).and_return([@provider, @provider, @provider])
20 Provider.stub(:available_list).and_return([@provider, @provider])
24 it '与えられたpageがセットされている' do
25 get :index, :page => 5
26 assigns(:page).should eq 5
28 it '省略されると@pageに1値が入る' do
30 assigns(:page).should eq 1
32 it '与えられたpage_sizeがセットされている' do
33 get :index, :page_size => 15
34 assigns(:page_size).should eq 15
36 it '省略されると@page_sizeにデフォルト値が入る' do
38 assigns(:page_size).should eq Provider.default_page_size
40 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
41 get :index, :page_size => 1500
42 assigns(:page_size).should eq Provider.max_page_size
44 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
45 get :index, :page_size => 0
46 assigns(:page_size).should eq Provider.default_page_size
49 context 'つつがなく終わるとき' do
50 it 'ステータスコード200 OKを返す' do
52 response.should be_success
56 assigns(:hide).should be_blank
58 it '貸手モデルに全一覧取得を問い合わせている' do
59 Provider.should_receive(:list).exactly(1)
62 it '@providersにリストを取得している' do
64 assigns(:providers).should have_at_least(3).items
67 it 'indexテンプレートを描画する' do
69 response.should render_template("index")
74 get :index, :format => :json
75 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
77 it '貸手モデルにjson一覧出力オプションを問い合わせている' do
78 Provider.should_receive(:list_json_opt).exactly(1)
79 get :index, :format => :json
81 it 'データがリスト構造になっている' do
82 get :index, :format => :json
83 json = JSON.parse response.body
84 json.should have_at_least(3).items
86 it 'リストの先頭くらいは貸手っぽいものであって欲しい' do
87 get :index, :format => :json
88 json = JSON.parse response.body
89 json.first.has_key?("name").should be_true
90 json.first.has_key?("caption").should be_true
91 json.first.has_key?("url").should be_true
92 json.first.has_key?("description").should be_true
96 context '除外フラグが除外のとき' do
98 get :index, :hide => 1
99 assigns(:hide).should_not be_blank
101 it '貸手モデルに待機中一覧取得を問い合わせている' do
102 Provider.should_receive(:available_list).exactly(1)
103 get :index, :hide => 1
105 it '@providersにリストを取得している' do
106 get :index, :hide => 1
107 assigns(:providers).should have_at_least(2).items
110 context '管理者権限がないとき' do
115 it 'ステータスコード302 Foundを返す' do
117 response.status.should eq 302
119 it 'サインインページへ遷移する' do
121 response.should redirect_to '/admins/sign_in'
125 it 'ステータスコード401 Unauthorizedを返す' do
126 get :index, :format => :json
127 response.status.should eq 401
129 it '応答メッセージにUnauthorizedを返す' do
130 get :index, :format => :json
131 response.message.should match(/Unauthorized/)
137 describe '単体表示に於いて' do
139 @ps = FactoryGirl.create :provider_status
140 @provider = FactoryGirl.create :provider, :provider_status_id => @ps.id
141 Provider.stub(:show).and_return(@provider)
144 context 'つつがなく終わるとき' do
145 it 'ステータスコード200 OKを返す' do
146 get :show, :id => @provider.id
147 response.should be_success
149 it '貸手モデルに単体取得を問い合わせている' do
150 Provider.should_receive(:show).exactly(1)
153 it '@providerにアレを取得している' do
154 get :show, :id => @provider.id
155 assigns(:provider).should eq(@provider)
158 it 'showテンプレートを描画する' do
159 get :show, :id => @provider.id
160 response.should render_template("show")
165 get :show, :id => @provider.id, :format => :json
166 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
168 it '貸手モデルにjson単体出力オプションを問い合わせている' do
169 Provider.should_receive(:show_json_opt).exactly(1)
170 get :show, :id => @provider.id, :format => :json
173 get :show, :id => @provider.id, :format => :json
174 json = JSON.parse response.body
175 json.has_key?("name").should be_true
176 json.has_key?("caption").should be_true
177 json.has_key?("url").should be_true
178 json.has_key?("description").should be_true
182 context '管理者権限がないとき' do
187 it 'ステータスコード302 Foundを返す' do
188 get :show, :id => @provider.id
189 response.status.should eq 302
191 it 'サインインページへ遷移する' do
192 get :show, :id => @provider.id
193 response.body.should redirect_to '/admins/sign_in'
197 it 'ステータスコード401 Unauthorizedを返す' do
198 get :show, :id => @provider.id, :format => :json
199 response.status.should eq 401
201 it '応答メッセージにUnauthorizedを返す' do
202 get :show, :id => @provider.id, :format => :json
203 response.message.should match(/Unauthorized/)