OSDN Git Service

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