aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2015-02-13 16:17:00 +0000
committerLouise Crow <louise.crow@gmail.com>2015-02-23 11:22:36 +0000
commit5e4db173eb7891f0bbfb9f5895e5bb36a99a7424 (patch)
tree4a22ea2b5df3be4f7356e28958c0b4a1e8faeb2f
parent0c3dd55f8d50f6d61212f4ee06ad39ba06db83a0 (diff)
Create bodies in before call.
-rw-r--r--spec/models/public_body_spec.rb44
1 files changed, 25 insertions, 19 deletions
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index dd6bc100d..27ebb54e6 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -681,90 +681,96 @@ describe PublicBody, " when loading CSV files" do
end
- context 'with an existing body' do
+ context 'with an existing body without tags' do
+
+ before do
+ @body = FactoryGirl.create(:public_body)
+ end
it 'appends when no tag_string is specified' do
- body = FactoryGirl.create(:public_body)
csv = <<-CSV.strip_heredoc
#id,request_email,name,tag_string,home_page
- #{ body.id },#{ body.request_email },"#{ body.name }",,#{ body.home_page }
+ #{ @body.id },#{ @body.request_email },"#{ @body.name }",,#{ @body.home_page }
CSV
# csv, tag, tag_behaviour, dry_run, editor
PublicBody.import_csv(csv, '', 'add', false, 'someadmin')
expected = []
- expect(PublicBody.find(body.id).tag_array_for_search).to eq(expected)
+ expect(PublicBody.find(@body.id).tag_array_for_search).to eq(expected)
end
it 'appends when a tag_string is specified' do
- body = FactoryGirl.create(:public_body)
csv = <<-CSV.strip_heredoc
#id,request_email,name,tag_string,home_page
- #{ body.id },#{ body.request_email },"#{ body.name }",new_tag,#{ body.home_page }
+ #{ @body.id },#{ @body.request_email },"#{ @body.name }",new_tag,#{ @body.home_page }
CSV
# csv, tag, tag_behaviour, dry_run, editor
PublicBody.import_csv(csv, '', 'add', false, 'someadmin')
expected = %W(new_tag)
- expect(PublicBody.find(body.id).tag_array_for_search).to eq(expected)
+ expect(PublicBody.find(@body.id).tag_array_for_search).to eq(expected)
end
it 'replaces when no tag_string is specified' do
- body = FactoryGirl.create(:public_body)
csv = <<-CSV.strip_heredoc
#id,request_email,name,tag_string,home_page
- #{ body.id },#{ body.request_email },"#{ body.name }",,#{ body.home_page }
+ #{ @body.id },#{ @body.request_email },"#{ @body.name }",,#{ @body.home_page }
CSV
# csv, tag, tag_behaviour, dry_run, editor
PublicBody.import_csv(csv, '', 'replace', false, 'someadmin')
expected = []
- expect(PublicBody.find(body.id).tag_array_for_search).to eq(expected)
+ expect(PublicBody.find(@body.id).tag_array_for_search).to eq(expected)
end
it 'replaces when a tag_string is specified' do
- body = FactoryGirl.create(:public_body)
csv = <<-CSV.strip_heredoc
#id,request_email,name,tag_string,home_page
- #{ body.id },#{ body.request_email },"#{ body.name }",new_tag,#{ body.home_page }
+ #{ @body.id },#{ @body.request_email },"#{ @body.name }",new_tag,#{ @body.home_page }
CSV
# csv, tag, tag_behaviour, dry_run, editor
PublicBody.import_csv(csv, '', 'replace', false, 'someadmin')
expected = %W(new_tag)
- expect(PublicBody.find(body.id).tag_array_for_search).to eq(expected)
+ expect(PublicBody.find(@body.id).tag_array_for_search).to eq(expected)
+ end
+
+ end
+
+ describe 'with an existing body with tags' do
+
+ before do
+ @body = FactoryGirl.create(:public_body, :tag_string => 'first_tag second_tag')
end
it 'created with tags, different tags in csv, add tags' do
- body = FactoryGirl.create(:public_body, :tag_string => 'first_tag second_tag')
csv = <<-CSV.strip_heredoc
#id,request_email,name,tag_string,home_page
- #{ body.id },#{ body.request_email },"#{ body.name }","first_tag new_tag",#{ body.home_page }
+ #{ @body.id },#{ @body.request_email },"#{ @body.name }","first_tag new_tag",#{ @body.home_page }
CSV
# csv, tag, tag_behaviour, dry_run, editor
PublicBody.import_csv(csv, '', 'add', false, 'someadmin')
expected = %W(first_tag new_tag second_tag)
- expect(PublicBody.find(body.id).tag_array_for_search).to eq(expected)
+ expect(PublicBody.find(@body.id).tag_array_for_search).to eq(expected)
end
it 'created with tags, different tags in csv, replace' do
- body = FactoryGirl.create(:public_body, :tag_string => 'first_tag second_tag')
csv = <<-CSV.strip_heredoc
#id,request_email,name,tag_string,home_page
- #{ body.id },#{ body.request_email },"#{ body.name }","first_tag new_tag",#{ body.home_page }
+ #{ @body.id },#{ @body.request_email },"#{ @body.name }","first_tag new_tag",#{ @body.home_page }
CSV
# csv, tag, tag_behaviour, dry_run, editor
PublicBody.import_csv(csv, '', 'replace', false, 'someadmin')
expected = %W(first_tag new_tag)
- expect(PublicBody.find(body.id).tag_array_for_search).to eq(expected)
+ expect(PublicBody.find(@body.id).tag_array_for_search).to eq(expected)
end
end