1 # -*- encoding: utf-8 -*-
5 describe ArtistsController do
8 @license = Factory :license
9 @user = Factory( :user_yas)
10 @author = @user.author
11 @artist = Factory :artist_yas, :author_id => @author.id
14 describe '一覧表示に於いて' do
16 Artist.stub(:list).and_return([@artist, @artist, @artist])
20 it '与えられたpageがセットされている' do
21 get :index, :page => 5
22 assigns(:page).should eq 5
24 it '省略されると@pageに1値が入る' do
26 assigns(:page).should eq 1
28 it '与えられたpage_sizeがセットされている' do
29 get :index, :page_size => 15
30 assigns(:page_size).should eq 15
32 it '省略されると@page_sizeにデフォルト値が入る' do
34 assigns(:page_size).should eq Artist.default_page_size
36 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
37 get :index, :page_size => 1500
38 assigns(:page_size).should eq Artist.max_page_size
40 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
41 get :index, :page_size => 0
42 assigns(:page_size).should eq Artist.default_page_size
45 context 'つつがなく終わるとき' do
46 it 'ステータスコード200 OKを返す' do
48 response.should be_success
50 it '絵師モデルに一覧を問い合わせている' do
51 Artist.should_receive(:list).exactly(1)
54 it '@artistsにリストを取得している' do
56 assigns(:artists).should have_at_least(3).items
59 it 'indexテンプレートを描画する' do
61 response.should render_template("index")
66 get :index, :format => :json
67 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
69 it 'データがリスト構造になっている' do
70 get :index, :format => :json
71 json = JSON.parse response.body
72 json.should have_at_least(3).items
74 it 'リストの先頭くらいは絵師っぽいものであって欲しい' do
75 get :index, :format => :json
76 json = JSON.parse response.body
77 json.first.has_key?("name").should be_true
81 context '作家権限がないとき' do
86 it 'ステータスコード302 Foundを返す' do
88 response.status.should eq 302
92 response.should redirect_to '/users/sign_in'
96 it 'ステータスコード401 Unauthorizedを返す' do
97 get :index, :format => :json
98 response.status.should eq 401
100 it '応答メッセージにUnauthorizedを返す' do
101 get :index, :format => :json
102 response.message.should match(/Unauthorized/)
110 Artist.stub(:show).and_return(@artist)
113 context 'つつがなく終わるとき' do
114 it 'ステータスコード200 OKを返す' do
115 get :show, :id => @artist.id
116 response.should be_success
118 it '絵師モデルに単体取得を問い合わせている' do
119 Artist.should_receive(:show).exactly(1)
122 it '@artistにアレを取得している' do
123 get :show, :id => @artist.id
124 assigns(:artist).should eq(@artist)
127 it 'showテンプレートを描画する' do
128 get :show, :id => @artist.id
129 response.should render_template("show")
134 get :show, :id => @artist.id, :format => :json
135 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
138 get :show, :id => @artist.id, :format => :json
139 json = JSON.parse response.body
140 json["name"].should match(/yas/)
144 context '作家権限がないとき' do
149 it 'ステータスコード302 Foundを返す' do
150 get :show, :id => @artist.id
151 response.status.should eq 302
153 it 'サインインページへ遷移する' do
154 get :show, :id => @artist.id
155 response.body.should redirect_to '/users/sign_in'
159 it 'ステータスコード401 Unauthorizedを返す' do
160 get :show, :id => @artist.id, :format => :json
161 response.status.should eq 401
163 it '応答メッセージにUnauthorizedを返す' do
164 get :show, :id => @artist.id, :format => :json
165 response.message.should match(/Unauthorized/)
170 context '対象作家がないとき' do
172 it '例外404 not_foundを返す' do
175 }.should raise_error(ActiveRecord::RecordNotFound)
179 it '例外404 not_foundを返す' do
181 get :show, :id => 0, :format => :json
182 }.should raise_error(ActiveRecord::RecordNotFound)
189 describe '絵師数取得に於いて' do
191 Artist.should_receive(:visible_count).and_return(3)
194 context 'つつがなく終わるとき' do
195 it 'ステータスコード200 OKを返す' do
196 get :count, :format => :json
197 response.should be_success
201 get :count, :format => :json
202 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
204 it 'データがHash構造になっていてコミック数が1である' do
205 get :count, :format => :json
206 json = JSON.parse response.body
207 json["count"].should == 3