OSDN Git Service

Merge branch 'v04' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v04
[pettanr/pettanr.git] / spec / controllers / licenses_controller_spec.rb
1 # -*- encoding: utf-8 -*-
2 #ライセンス
3 require 'spec_helper'
4
5 describe LicensesController do
6   before do
7     @admin = FactoryGirl.create :admin
8     @lg = FactoryGirl.create :license_group
9     @sp = FactoryGirl.create :system_picture
10     @user = FactoryGirl.create( :user_yas)
11     @author = @user.author
12     @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
13   end
14
15   describe '一覧表示に於いて' do
16     before do
17       @l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
18       sign_in @user
19       License.stub(:list).and_return([@l, @l, @l])
20     end
21       context 'つつがなく終わるとき' do
22       it 'ステータスコード200 OKを返す' do
23         get :index
24         response.should be_success 
25       end
26       it 'ライセンスモデルに一覧を問い合わせている' do
27         License.should_receive(:list).exactly(1)
28         get :index
29       end
30       it '@licensesにリストを取得している' do
31         get :index
32         assigns(:licenses).should have_at_least(3).items
33       end
34       context 'html形式' do
35         it 'indexテンプレートを描画する' do
36           get :index
37           response.should render_template("index")
38         end
39       end
40       context 'json形式' do
41         it 'jsonデータを返す' do
42           get :index, :format => :json
43           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
44         end
45         it 'データがリスト構造になっている' do
46           get :index, :format => :json
47           json = JSON.parse response.body
48           json.should have_at_least(3).items
49         end
50         it 'リストの先頭くらいはライセンスっぽいものであって欲しい' do
51           get :index, :format => :json
52           json = JSON.parse response.body
53           json.first.has_key?("url").should be_true
54         end
55       end
56     end
57     context '作家権限がないとき' do
58       before do
59         sign_out @user
60       end
61       it 'ステータスコード200 okを返す' do
62         get :index
63         response.status.should eq 200
64       end
65     end
66   end
67   
68   describe '単体表示に於いて' do
69     before do
70       sign_in @user
71       @l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
72       License.stub(:show).and_return(@l)
73     end
74     context 'つつがなく終わるとき' do
75       it 'ステータスコード200 OKを返す' do
76         get :show, :id => @l.id
77         response.should be_success
78       end
79       it 'ライセンスモデルに単体取得を問い合わせている' do
80         License.should_receive(:show).exactly(1)
81         get :show
82       end
83       it '@licenseにアレを取得している' do
84         get :show, :id => @l.id
85         assigns(:license).id.should eq(@l.id)
86       end
87       context 'html形式' do
88         it 'showテンプレートを描画する' do
89           get :show, :id => @l.id
90           response.should render_template("show")
91         end
92       end
93       context 'json形式' do
94         it 'jsonデータを返す' do
95           get :show, :id => @l.id, :format => :json
96           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
97         end
98         it 'データがアレになっている' do
99           get :show, :id => @l.id, :format => :json
100           json = JSON.parse response.body
101           json["name"].should match(/peta/)
102         end
103       end
104     end
105     context '作家権限がないとき' do
106       before do
107         sign_out @user
108       end
109       it 'ステータスコード200 okを返す' do
110         get :show, :id => @l.id
111         response.status.should eq 200
112       end
113     end
114   end
115   
116 end