1 # -*- encoding: utf-8 -*-
5 describe ProviderArtist do
7 @admin = FactoryGirl.create :admin
8 @sp = FactoryGirl.create :system_picture
9 @lg = FactoryGirl.create :license_group
10 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
11 @user = FactoryGirl.create :user_yas
12 @author = FactoryGirl.create :author, :user_id => @user.id
13 @artist = FactoryGirl.create :artist, :author_id => @author.id
14 @other_user = FactoryGirl.create :user_yas
15 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
16 @provider_status = FactoryGirl.create :provider_status
17 @provider = FactoryGirl.create :provider, :provider_status_id => @provider_status.id
21 @pa = FactoryGirl.build :provider_artist, :provider_id => @provider.id, :providers_artist_id => 2, :demanders_artist_id => @artist.id
24 context 'オーソドックスなデータのとき' do
33 context 'provider_idを検証するとき' do
36 @pa.should_not be_valid
40 @pa.should_not be_valid
42 it '存在する貸手でなければ失敗する' do
44 @pa.should_not be_valid
47 context 'providers_artist_idを検証するとき' do
49 @pa.providers_artist_id = nil
50 @pa.should_not be_valid
53 @pa.providers_artist_id = 'a'
54 @pa.should_not be_valid
57 context 'demanders_artist_idを検証するとき' do
59 @pa.demanders_artist_id = nil
60 @pa.should_not be_valid
63 @pa.demanders_artist_id = 'a'
64 @pa.should_not be_valid
69 describe '対照表取得に於いて' do
71 @pa = FactoryGirl.create :provider_artist, :provider_id => @provider.id, :providers_artist_id => 2, :demanders_artist_id => @artist.id
74 r = ProviderArtist.get_one @provider.id, 2
77 it '該当する対照表が存在しなかったら、新規に興した対照表オブジェクトを返す' do
78 r = ProviderArtist.get_one @provider.id, 1
79 r.should be_a_new ProviderArtist
80 r = ProviderArtist.get_one 0, 2
81 r.should be_a_new ProviderArtist
85 describe '貸手側絵師同期に於いて' do
87 @pa = FactoryGirl.create :provider_artist, :provider_id => @provider.id, :providers_artist_id => 2, :demanders_artist_id => @artist.id
88 @newpa = ProviderArtist.new
90 context '自身に絵師がリンクしてないとき' do
93 it '絵師オブジェクトを新規に興す' do
95 r = @newpa.modify_artist @artist.attributes
96 }.should change Artist, :count
99 context '自身に絵師がリンクしているとき' do
102 r = @pa.modify_artist @artist.attributes
103 }.should_not change Artist, :count
106 it '貸手側絵師カラム値から絵師名をセットする 絵師オブジェクトを保存する' do
107 r = @pa.modify_artist :name => 'artist2'
109 @artist.name.should eq 'artist2'
111 it '作家idをクリアする。(外絵師の証明)' do
112 r = @pa.modify_artist :name => 'artist2'
114 @artist.author_id.should be_blank
117 r = @pa.modify_artist @artist.attributes
122 describe 'インポートに於いて' do
124 @artist2 = FactoryGirl.create :artist, :author_id => @other_author.id, :name => 'artist2'
126 context '事前チェックする' do
128 ProviderArtist.stub(:get_one).with(any_args).and_return(ProviderArtist.new)
129 ProviderArtist.any_instance.stub(:modify_artist).with(any_args).and_return(@artist)
130 ProviderArtist.any_instance.stub(:save).with(any_args).and_return(true)
132 it '対照表取得を問い合わせている' do
133 ProviderArtist.should_receive(:get_one).with(any_args).exactly(1)
134 r = ProviderArtist.import @provider.id, [@artist.attributes]
136 it '対照表に絵師同期を依頼してしている' do
137 ProviderArtist.any_instance.should_receive(:modify_artist).with(any_args).exactly(1)
138 r = ProviderArtist.import @provider.id, [@artist.attributes]
140 it '対照表オブジェクトを保存している' do
141 ProviderArtist.any_instance.should_receive(:save).with(any_args).exactly(1)
142 r = ProviderArtist.import @provider.id, [@artist.attributes]
145 context 'つつがなく終わるとき' do
147 r = ProviderArtist.import @provider.id, [@artist.attributes]
152 r = ProviderArtist.import @provider.id, [@artist.attributes]
153 }.should change ProviderArtist, :count
156 context '複数インポートのとき' do
158 r = ProviderArtist.import @provider.id, [@artist.attributes, @artist2.attributes]
163 r = ProviderArtist.import @provider.id, [@artist.attributes, @artist2.attributes]
164 }.should change(ProviderArtist, :count).by(2)
168 context '対照表オブジェクトの保存に失敗したとき' do
170 ProviderArtist.any_instance.stub(:save).with(any_args).and_return(false)
172 it '結果に貸手側絵師のカラム値を追加している' do
173 r = ProviderArtist.import @provider.id, [@artist.attributes]
174 r.should_not be_empty
177 context '絵師オブジェクトの保存に失敗したとき' do
179 Artist.any_instance.stub(:save).with(any_args).and_return(false)
181 it '結果に貸手側絵師のカラム値を追加している' do
182 r = ProviderArtist.import @provider.id, [@artist.attributes]
183 r.should_not be_empty