OSDN Git Service

t#29826:up;importer replace
[pettanr/pettanr.git] / spec / controllers / ground_colors_controller_spec.rb
1 # -*- encoding: utf-8 -*-
2 require 'spec_helper'
3 #コマの間接背景
4
5 describe GroundColorsController do
6   before do
7     @admin = FactoryGirl.create :admin
8     @user = FactoryGirl.create( :user_yas)
9     @sp = FactoryGirl.create :system_picture
10     @lg = FactoryGirl.create :license_group, :name => 'peta'
11     @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
12     @author = @user.author
13     @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
14     @panel = FactoryGirl.create :panel, :author_id => @author.id
15     @color = FactoryGirl.create :color
16   end
17
18   describe '一覧表示に於いて' do
19     before do
20       sign_in @user
21       @gc = FactoryGirl.create :ground_color
22       GroundColor.stub(:list).and_return([@gc, @gc, @gc])
23     end
24     context 'パラメータpageについて' do
25       it '@pageに値が入る' do
26         get :index, :page => 5
27         assigns(:page).should eq 5
28       end
29       it '省略されると@pageに1値が入る' do
30         get :index
31         assigns(:page).should eq 1
32       end
33       it '与えられたpage_sizeがセットされている' do
34         get :index, :page_size => 15
35         assigns(:page_size).should eq 15
36       end
37       it '省略されると@page_sizeにデフォルト値が入る' do
38         get :index
39         assigns(:page_size).should eq GroundColor.default_page_size
40       end
41       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
42         get :index, :page_size => 1500
43         assigns(:page_size).should eq GroundColor.max_page_size
44       end
45       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
46         get :index, :page_size => 0
47         assigns(:page_size).should eq GroundColor.default_page_size
48       end
49     end
50     context 'つつがなく終わるとき' do
51       it 'ステータスコード200 OKを返す' do
52         get :index
53         response.should be_success 
54       end
55       it '間接背景モデルに一覧を問い合わせている' do
56         GroundColor.should_receive(:list).exactly(1)
57         get :index
58       end
59       it '@ground_colorsにリストを取得している' do
60         get :index
61         assigns(:ground_colors).should have_at_least(3).items
62       end
63       context 'html形式' do
64         it 'indexテンプレートを描画する' do
65           get :index
66           response.should render_template("index")
67         end
68       end
69       context 'json形式' do
70         it 'jsonデータを返す' do
71           get :index, :format => :json
72           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
73         end
74         it '間接背景モデルにjson一覧出力オプションを問い合わせている' do
75           GroundColor.should_receive(:list_json_opt).exactly(1)
76           get :index, :format => :json
77         end
78         it 'データがリスト構造になっている' do
79           get :index, :format => :json
80           json = JSON.parse response.body
81           json.should have_at_least(3).items
82         end
83         it 'リストの先頭くらいは間接背景っぽいものであって欲しい' do
84           get :index, :format => :json
85           json = JSON.parse response.body
86           json.first.has_key?("panel_id").should be_true
87           json.first.has_key?("color_id").should be_true
88           json.first.has_key?("z").should be_true
89         end
90       end
91     end
92     context '作家権限がないとき' do
93       before do
94         sign_out @user
95       end
96       context 'html形式' do
97         it 'ステータスコード302 Foundを返す' do
98           get :index
99           response.status.should eq 302
100         end
101         it 'サインインページへ遷移する' do
102           get :index
103           response.should redirect_to '/users/sign_in'
104         end
105       end
106       context 'json形式' do
107         it 'ステータスコード401 Unauthorizedを返す' do
108           get :index, :format => :json
109           response.status.should eq 401
110         end
111         it '応答メッセージにUnauthorizedを返す' do
112           get :index, :format => :json
113           response.message.should match(/Unauthorized/)
114         end
115       end
116     end
117   end
118   
119 end