1 # -*- encoding: utf-8 -*-
5 describe LicenseGroup do
8 @f = Rails.root + 'spec/json/license_group.json'
9 @t = File.open(@f, 'r').read
16 it 'オーソドックスなデータなら通る' do
17 @lg = Factory.build :license_group
21 context 'nameを検証するとき' do
23 @lg = Factory.build :license_group
31 @lg.should_not be_valid
35 @lg.should_not be_valid
38 l = Factory :license_group
39 @lg.should_not be_valid
42 context 'classnameを検証するとき' do
44 @lg = Factory.build :license_group
47 @lg.classname = 'a'*50
52 @lg.should_not be_valid
55 @lg.classname = 'a'*51
56 @lg.should_not be_valid
59 context 'captionを検証するとき' do
61 @lg = Factory.build :license_group
69 @lg.should_not be_valid
73 @lg.should_not be_valid
76 context 'urlを検証するとき' do
78 @lg = Factory.build :license_group
81 @lg.url = 'http://test.com/'
86 @lg.should_not be_valid
90 @lg.should_not be_valid
92 it 'url形式でないなら失敗する' do
94 @lg.should_not be_valid
99 describe 'インポートに於いて' do
102 context 'つつがなく終わるとき' do
103 it 'テキストインポートを依頼する' do
104 CommonLicense.should_receive(:parse).with(any_args).exactly(1)
105 CommonLicense.stub(:parse).with(any_args).and_return(@j)
106 CommonLicense.import(@t)
108 it 'ライセンスグループ更新を一回依頼する' do
109 CommonLicense.stub(:store).with(any_args).and_return(CommonLicense.new)
110 CommonLicense.any_instance.stub(:valid?).with(any_args).and_return(true)
111 CommonLicense.should_receive(:store).with(any_args).exactly(1)
112 CommonLicense.import(@t)
114 it 'ライセンスグループが追加される' do
116 CommonLicense.import(@t)
117 }.should change CommonLicense, :count
120 CommonLicense.import(@t).should eq []
123 context '複数データがつつがなく終わるとき' do
124 it 'ライセンスグループ更新を二回依頼する' do
125 CommonLicense.stub(:store).with(any_args).and_return(CommonLicense.new)
126 CommonLicense.any_instance.stub(:valid?).with(any_args).and_return(true)
127 CommonLicense.should_receive(:store).with(any_args).exactly(2)
128 CommonLicense.import(@ts)
130 it 'ライセンスグループが二個追加される' do
132 CommonLicense.import(@ts)
133 }.should change(CommonLicense, :count).by 2
136 CommonLicense.import(@ts).should eq []
139 context 'コモンライセンス作成に失敗したとき' do
141 CommonLicense.any_instance.stub(:save).with(any_args).and_return(false)
142 CommonLicense.any_instance.stub(:valid?).with(any_args).and_return(false)
144 it 'コモンライセンスの数に変化がない' do
146 CommonLicense.import(@t)
147 }.should_not change CommonLicense, :count
150 r = CommonLicense.import(@t)
151 r.is_a?(Array).should be_true
154 r = CommonLicense.import(@t)
155 r.should have(1).items
157 it 'コモンライセンスオブジェクトが入っている' do
158 r = CommonLicense.import(@t)
159 r.first.is_a?(CommonLicense).should be_true
162 context '複数のコモンライセンス作成に失敗したとき' do
163 #三件中、二件の失敗、一件を成功させ、成功データは戻り値に含まないことを確認する
164 it 'コモンライセンスの数に変化がない' do
166 CommonLicense.import(@tes)
167 }.should_not change CommonLicense, :count
169 it '途中で保存に失敗しても全件更新依頼する' do
170 CommonLicense.stub(:store).with(any_args).and_return(CommonLicense.new)
171 CommonLicense.should_receive(:store).with(any_args).exactly(3)
172 CommonLicense.import(@tes)
175 r = CommonLicense.import(@tes)
176 r.is_a?(Array).should be_true
179 r = CommonLicense.import(@tes)
180 r.should have(2).items
182 it '配列の中身は失敗したコモンライセンスオブジェクトが入っている' do
183 r = CommonLicense.import(@tes)
184 r[0].is_a?(CommonLicense).should be_true
185 r[0]["name"].should eq 'fail1'
186 r[1].is_a?(CommonLicense).should be_true
187 r[1]["name"].should eq 'fail2'