OSDN Git Service

05da3adef0bf7ba62dbb7c45332355e65684cda5
[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     @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   end
13
14   describe '一覧表示に於いて' do
15     before do
16       sign_in @user
17       LicenseGroup.stub(:list).and_return([@lg, @lg, @lg])
18     end
19     context 'つつがなく終わるとき' do
20       it 'ステータスコード200 OKを返す' do
21         get :index
22         response.should be_success 
23       end
24       it 'ライセンスグループモデルに一覧を問い合わせている' do
25         LicenseGroup.should_receive(:list).exactly(1)
26         get :index
27       end
28       it '@license_groupsにリストを取得している' do
29         get :index
30         assigns(:license_groups).should have_at_least(3).items
31       end
32       context 'html形式' do
33         it 'indexテンプレートを描画する' do
34           get :index
35           response.should render_template("index")
36         end
37       end
38       context 'json形式' do
39         it 'jsonデータを返す' do
40           get :index, :format => :json
41           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
42         end
43         it 'ライセンスグループモデルにjson一覧出力オプションを問い合わせている' do
44           LicenseGroup.should_receive(:list_json_opt).exactly(1)
45           get :index, :format => :json
46         end
47         it 'データがリスト構造になっている' do
48           get :index, :format => :json
49           json = JSON.parse response.body
50           json.should have_at_least(3).items
51         end
52         it 'リストの先頭くらいはライセンスグループっぽいものであって欲しい' do
53           get :index, :format => :json
54           json = JSON.parse response.body
55           json.first.has_key?("name").should be_true
56           json.first.has_key?("classname").should be_true
57           json.first.has_key?("caption").should be_true
58           json.first.has_key?("url").should be_true
59         end
60       end
61     end
62     context '作家権限がないとき' do
63       before do
64         sign_out @user
65       end
66       it 'ステータスコード200 okを返す' do
67         get :index
68         response.status.should eq 200
69       end
70     end
71   end
72   
73   describe '単体表示に於いて' do
74     before do
75       sign_in @user
76       LicenseGroup.stub(:show).and_return(@lg)
77     end
78     context 'つつがなく終わるとき' do
79       it 'ステータスコード200 OKを返す' do
80         get :show, :id => @lg.id
81         response.should be_success
82       end
83       it 'ライセンスモデルに単体取得を問い合わせている' do
84         LicenseGroup.should_receive(:show).exactly(1)
85         get :show
86       end
87       it '@license_groupにアレを取得している' do
88         get :show, :id => @lg.id
89         assigns(:license_group).id.should eq(@lg.id)
90       end
91       context 'html形式' do
92         it 'showテンプレートを描画する' do
93           get :show, :id => @lg.id
94           response.should render_template("show")
95         end
96       end
97       context 'json形式' do
98         it 'jsonデータを返す' do
99           get :show, :id => @lg.id, :format => :json
100           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
101         end
102         it 'ライセンスグループモデルにjson単体出力オプションを問い合わせている' do
103           LicenseGroup.should_receive(:show_json_opt).exactly(1)
104           get :show, :id => @lg.id, :format => :json
105         end
106         it 'データがアレになっている' do
107           get :show, :id => @lg.id, :format => :json
108           json = JSON.parse response.body
109           json["name"].should match(/peta/)
110           json["classname"].should_not be_nil
111           json["caption"].should_not be_nil\r
112           json["url"].should_not be_nil\r
113         end
114       end
115     end
116     context '作家権限がないとき' do
117       before do
118         sign_out @user
119       end
120       it 'ステータスコード200 okを返す' do
121         get :show, :id => @lg.id
122         response.status.should eq 200
123       end
124     end
125   end
126   
127
128 end