OSDN Git Service

add 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     Factory :admin
8     @user = Factory( :user_yas)
9     @author = @user.author
10     @artist = Factory :artist_yas, :author_id => @author.id
11     @other_user = Factory( :user_yas)
12     @other_author = @other_user.author
13     @other_artist = Factory :artist_yas, :author_id => @other_author.id
14     @sp = Factory :system_picture
15     @lg = Factory :license_group
16     @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
17     @op = Factory :original_picture, :artist_id => @artist.id
18   end
19   
20   describe '検証に於いて' do
21     before do
22     end
23     
24     it 'オーソドックスなデータなら通る' do
25       @sl = Factory.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 = Factory.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 = Factory.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 = Factory.build :standard_license, :license_id => @license.id
75     end
76     it 'nilを返す' do
77       r = @sl.credit 
78       r.should eq nil
79     end
80   end
81 end