OSDN Git Service

t#29061/t#29089/t#29076:add mylist. modify panel picture
[pettanr/pettanr.git] / spec / models / standard_license_spec.rb
1 # -*- encoding: utf-8 -*-
2 #ライセンス選択
3 require 'spec_helper'
4
5 describe StandardLicense do
6   before do
7     FactoryGirl.create :admin
8     @user = FactoryGirl.create( :user_yas)
9     @author = @user.author
10     @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
11     @other_user = FactoryGirl.create( :user_yas)
12     @other_author = @other_user.author
13     @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
14     @sp = FactoryGirl.create :system_picture
15     @lg = FactoryGirl.create :license_group
16     @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
17     @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
18   end
19   
20   describe '検証に於いて' do
21     before do
22     end
23     
24     it 'オーソドックスなデータなら通る' do
25       @sl = FactoryGirl.build :standard_license, :license_id => @license.id
26       @sl.should be_valid
27     end
28     
29     context 'license_idを検証するとき' do
30       before do
31         @sl = FactoryGirl.build :standard_license, :license_id => @license.id
32       end
33       it 'テストデータの確認' do
34         @sl.license_id = @license.id
35         @sl.should be_valid
36       end
37       it 'nullなら失敗する' do
38         @sl.license_id = nil
39         @sl.should_not be_valid
40       end
41       it '数値でなければ失敗する' do
42         @sl.license_id = 'a'
43         @sl.should_not be_valid
44       end
45       it '存在するライセンスグループでなければ失敗する' do
46         @sl.license_id = 0
47         @sl.should_not be_valid
48       end
49     end
50     context 'artist_nameを検証するとき' do
51       before do
52         @sl = FactoryGirl.build :standard_license, :license_id => @license.id
53       end
54       it 'テストデータの確認' do
55         @sl.artist_name = 'a'
56         @sl.should be_valid
57       end
58       it 'nullなら失敗する' do
59         @sl.artist_name = nil
60         @sl.should_not be_valid
61       end
62     end
63   end
64   describe '補充に於いて' do
65     it '原画idを補充している' do
66       @sl = StandardLicense.new
67       @sl.artist_name = nil
68       @sl.supply_default @artist
69       @sl.artist_name.should eq @artist.name
70     end
71   end
72   describe 'クレジットデータに於いて' do
73     before do
74       @sl = FactoryGirl.build :standard_license, :license_id => @license.id
75     end
76     it 'jsonテキストを返す' do
77       r = @sl.credit 
78       lambda{
79         JSON.parse @sl.credit
80       }.should_not raise_error
81     end
82     it 'system_picture_idを含んでいて値はライセンスに割り当てたシステム画像になっている' do
83       r = JSON.parse @sl.credit 
84       r.has_key?('system_picture_id').should be_true
85       r['system_picture_id'].should eq @sl.license.system_picture_id
86     end
87   end
88 end