OSDN Git Service

t#30200:update i18n devise
[pettanr/pettanr.git] / spec / controllers / license_groups_controller_spec.rb
1 # -*- encoding: utf-8 -*-
2 #ライセンスグループ
3 require 'spec_helper'
4
5 describe LicenseGroupsController 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       LicenseGroup.stub(:list).and_return([@lg, @lg, @lg])
19     end
20     context 'つつがなく終わるとき' do
21       it 'ステータスコード200 OKを返す' do
22         get :index
23         response.should be_success 
24       end
25       it 'ライセンスグループモデルに一覧を問い合わせている' do
26         LicenseGroup.should_receive(:list).exactly(1)
27         get :index
28       end
29       it '@license_groupsにリストを取得している' do
30         get :index
31         assigns(:license_groups).should have_at_least(3).items
32       end
33       context 'html形式' do
34         it 'indexテンプレートを描画する' do
35           get :index
36           response.should render_template("index")
37         end
38       end
39       context 'json形式' do
40         it 'jsonデータを返す' do
41           get :index, :format => :json
42           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
43         end
44         it 'ライセンスグループモデルにjson一覧出力オプションを問い合わせている' do
45           LicenseGroup.should_receive(:list_json_opt).exactly(1)
46           get :index, :format => :json
47         end
48         it 'データがリスト構造になっている' do
49           get :index, :format => :json
50           json = JSON.parse response.body
51           json.should have_at_least(3).items
52         end
53         it 'リストの先頭くらいはライセンスグループっぽいものであって欲しい' do
54           get :index, :format => :json
55           json = JSON.parse response.body
56           json.first.has_key?("name").should be_true
57           json.first.has_key?("classname").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       LicenseGroup.stub(:show).and_return(@lg)
78     end
79     context 'つつがなく終わるとき' do
80       it 'ステータスコード200 OKを返す' do
81         get :show, :id => @lg.id
82         response.should be_success
83       end
84       it 'ライセンスモデルに単体取得を問い合わせている' do
85         LicenseGroup.should_receive(:show).exactly(1)
86         get :show
87       end
88       it '@license_groupにアレを取得している' do
89         get :show, :id => @lg.id
90         assigns(:license_group).id.should eq(@lg.id)
91       end
92       context 'html形式' do
93         it 'showテンプレートを描画する' do
94           get :show, :id => @lg.id
95           response.should render_template("show")
96         end
97       end
98       context 'json形式' do
99         it 'jsonデータを返す' do
100           get :show, :id => @lg.id, :format => :json
101           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
102         end
103         it 'ライセンスグループモデルにjson単体出力オプションを問い合わせている' do
104           LicenseGroup.should_receive(:show_json_opt).exactly(1)
105           get :show, :id => @lg.id, :format => :json
106         end
107         it 'データがアレになっている' do
108           get :show, :id => @lg.id, :format => :json
109           json = JSON.parse response.body
110           json["name"].should match(/peta/)
111           json["classname"].should_not be_nil
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 => @lg.id
123         response.status.should eq 200
124       end
125     end
126   end
127   
128
129 end