1 # -*- encoding: utf-8 -*-
5 describe LicenseGroup do
8 @f = Rails.root + 'spec/json/license_group.json'
9 @t = File.open(@f, 'r').read
11 @fs = Rails.root + 'spec/json/license_groups.json'
12 @fes = Rails.root + 'spec/json/invalid_license_groups.json'
18 it 'オーソドックスなデータなら通る' do
19 @lg = Factory.build :license_group
23 context 'nameを検証するとき' do
25 @lg = Factory.build :license_group
33 @lg.should_not be_valid
37 @lg.should_not be_valid
40 l = Factory :license_group
41 @lg.should_not be_valid
44 context 'classnameを検証するとき' do
46 @lg = Factory.build :license_group
49 @lg.classname = 'a'*50
54 @lg.should_not be_valid
57 @lg.classname = 'a'*51
58 @lg.should_not be_valid
61 context 'captionを検証するとき' do
63 @lg = Factory.build :license_group
71 @lg.should_not be_valid
75 @lg.should_not be_valid
78 context 'urlを検証するとき' do
80 @lg = Factory.build :license_group
83 @lg.url = 'http://test.com/'
88 @lg.should_not be_valid
92 @lg.should_not be_valid
94 it 'url形式でないなら失敗する' do
96 @lg.should_not be_valid
106 context 'つつがなく終わるとき' do
108 LicenseGroup.stub(:modify_object).with(any_args).and_return(LicenseGroup.new)
109 LicenseGroup.should_receive(:modify_object).with(any_args).exactly(1)
110 LicenseGroup.any_instance.stub(:save).with(any_args).and_return(true)
111 r = LicenseGroup.store(@n, @a)
114 LicenseGroup.stub(:modify_object).with(any_args).and_return(LicenseGroup.new)
115 LicenseGroup.any_instance.stub(:save).with(any_args).and_return(true)
116 LicenseGroup.any_instance.should_receive(:save).with(any_args).exactly(1)
117 r = LicenseGroup.store(@n, @a)
120 r = LicenseGroup.store(@n, @a)
121 r.is_a?(LicenseGroup).should be_true
123 r.url.should eq @a["url"]
128 describe 'インポートに於いて' do
131 context 'つつがなく終わるとき' do
132 it 'ファイルインポートを依頼する' do
133 LicenseGroup.should_receive(:import_file).with(any_args).exactly(1)
134 LicenseGroup.stub(:import_file).with(any_args).and_return([])
135 LicenseGroup.import(@f)
137 it 'ライセンスグループ更新を一回依頼する' do
138 LicenseGroup.stub(:store).with(any_args).and_return(LicenseGroup.new)
139 LicenseGroup.should_receive(:store).with(any_args).exactly(1)
140 LicenseGroup.import(@f)
142 it 'ライセンスグループが追加される' do
144 LicenseGroup.import(@f)
145 }.should change LicenseGroup, :count
148 r = LicenseGroup.import(@f)
152 context '複数データがつつがなく終わるとき' do
153 it 'ライセンスグループ更新を二回依頼する' do
154 LicenseGroup.stub(:store).with(any_args).and_return(LicenseGroup.new)
155 LicenseGroup.should_receive(:store).with(any_args).exactly(2)
156 LicenseGroup.import(@fs)
158 it 'ライセンスグループが二個追加される' do
160 r = LicenseGroup.import(@fs)
161 }.should change(LicenseGroup, :count).by 2
164 r = LicenseGroup.import(@fs)
168 context 'ライセンスグループ作成に失敗したとき' do
170 LicenseGroup.any_instance.stub(:save).with(any_args).and_return(false)
171 LicenseGroup.any_instance.stub(:valid?).with(any_args).and_return(false)
173 it 'ライセンスグループの数に変化がない' do
175 LicenseGroup.import(@f)
176 }.should_not change LicenseGroup, :count
179 r = LicenseGroup.import(@f)
180 r.is_a?(Array).should be_true
183 r = LicenseGroup.import(@f)
184 r.should have(1).items
186 it 'ライセンスグループオブジェクトが入っている' do
187 r = LicenseGroup.import(@f)
188 r.first.is_a?(LicenseGroup).should be_true
191 context '複数のライセンスグループ作成に失敗したとき' do
192 #三件中、二件の失敗、一件を成功させ、成功データは戻り値に含まないことを確認する
193 it 'ライセンスグループの数に変化がない' do
195 LicenseGroup.import(@fes)
196 }.should_not change LicenseGroup, :count
198 it '途中で保存に失敗しても全件更新依頼する' do
199 LicenseGroup.stub(:store).with(any_args).and_return(LicenseGroup.new)
200 LicenseGroup.should_receive(:store).with(any_args).exactly(3)
201 LicenseGroup.import(@fes)
204 r = LicenseGroup.import(@fes)
205 r.is_a?(Array).should be_true
208 r = LicenseGroup.import(@fes)
209 r.should have(2).items
211 it '配列の中身は失敗したライセンスグループオブジェクトが入っている' do
212 r = LicenseGroup.import(@fes)
213 r[0].is_a?(LicenseGroup).should be_true
214 r[0]["name"].should eq 'UnknownUrl'
215 r[1].is_a?(LicenseGroup).should be_true
216 r[1]["name"].should eq 'UnknownClassname'