Skip to content
Browse files

Merge pull request #17 from alphagov/legacy_sources

Add legacy sources tag collection to artefacts

This will allow us to identify the source(s) from which the artefact has been drawn and so communicate clearly to users who are used to using those old sources.
  • Loading branch information...
2 parents 8c763c4 + 5081e34 commit a311a54d1b11a5ac41e3ac6dce0793a01a386ffb @jystewart jystewart committed Aug 20, 2012
View
2 Gemfile
@@ -33,7 +33,7 @@ gem 'lograge'
if ENV['CONTENT_MODELS_DEV']
gem "govuk_content_models", path: '../govuk_content_models'
else
- gem "govuk_content_models", "1.0.0"
+ gem "govuk_content_models", "1.2.0"
end
if ENV['BUNDLE_DEV']
View
4 Gemfile.lock
@@ -118,7 +118,7 @@ GEM
json
gherkin (2.11.1)
json (>= 1.4.6)
- govuk_content_models (1.0.0)
+ govuk_content_models (1.2.0)
bson_ext
differ
gds-api-adapters
@@ -302,7 +302,7 @@ DEPENDENCIES
gds-sso (~> 1.2.0)
gds-warmup-controller (= 0.1.0)
gelf
- govuk_content_models (= 1.0.0)
+ govuk_content_models (= 1.2.0)
launchy
lograge
minitest
View
2 app/controllers/artefacts_controller.rb
@@ -132,7 +132,7 @@ def extract_parameters(params)
end
# Strip out the empty submit option for sections
- ['sections'].each do |param|
+ ['sections', 'legacy_source_ids'].each do |param|
param_value = parameters_to_use[param]
param_value.reject!(&:blank?) if param_value
end
View
4 app/helpers/sections_helper.rb
@@ -14,6 +14,10 @@ def all_sections(options = {})
sections.reject { |s| s[1] == options[:except] }
end
+ def options_for_tags_of_type(tag_type)
+ Tag.where(:tag_type => tag_type).order(:title).map {|t| [t.title, t.tag_id]}
+ end
+
# Convert an array of sections into a nested array suitable for
# using with the rails form helpers' select box tools.
#
View
4 app/views/artefacts/_form.html.erb
@@ -56,6 +56,10 @@
<hr>
+ <%= f.input :legacy_source_ids, :label => "Legacy sources", :collection => options_for_tags_of_type('legacy_source'), :input_html => { :multiple => true, :class => "span6 chzn-select" } %>
+
+ <hr>
+
<%= f.inputs do %>
<%= f.input :department, :label => "Writing team", :input_html => { :disabled => f.object.persisted?, :class => "span6"} %>
View
6 db/seeds.rb
@@ -5,3 +5,9 @@
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
+
+Dir[File.join(File.dirname(__FILE__),'seeds','*.rb')].each do |f|
+ puts "Seeding from #{ File.basename f }..."
+ load f
+ puts "Done."
+end
View
8 db/seeds/tags.rb
@@ -0,0 +1,8 @@
+#######
+#
+# This file will be run on every deploy, so make sure the changes here are non-destructive
+#
+#######
+
+TagRepository.put(:tag_id => 'businesslink', :title => 'Business Link', :tag_type => 'legacy_source')
+TagRepository.put(:tag_id => 'directgov', :title => 'Directgov', :tag_type => 'legacy_source')
View
2 features/support/api.rb
@@ -8,7 +8,7 @@ def related_artefact_ids_from_api(artefact)
end
def tag_ids_from_api(artefact)
- artefact_data_from_api(artefact)[:tag_ids].map { |tag| tag['id'] }
+ artefact_data_from_api(artefact)[:tag_ids]
end
def contact_id_from_api(artefact)
View
12 lib/tasks/migrate.rake
@@ -34,4 +34,16 @@ namespace :migrate do
end
end
end
+
+ desc "Sets the businesslink legacy source on all business proposition content"
+ task :set_businesslink_tag_on_buisiness_artefacts => :environment do
+ Artefact.observers.disable :update_search_observer, :update_router_observer do
+ Artefact.where(:business_proposition => true).each do |artefact|
+ unless artefact.legacy_source_ids.include?('businesslink')
+ artefact.legacy_source_ids += %w(businesslink)
+ artefact.save!
+ end
+ end
+ end
+ end
end
View
13 test/functional/artefacts_controller_test.rb
@@ -120,6 +120,19 @@ class ArtefactsControllerTest < ActionController::TestCase
assert_equal artefact.section, parsed['section']
end
+ should "Include tag_ids" do
+ TagRepository.put :tag_id => 'crime', :tag_type => 'section', :title => 'Crime'
+ TagRepository.put :tag_id => 'businesslink', :tag_type => 'legacy_source', :title => 'Business Link'
+ artefact = Artefact.create! :slug => 'whatever', :kind => 'guide', :owning_app => 'publisher', :name => 'Whatever', :need_id => 1
+ artefact.sections = ['crime']
+ artefact.legacy_sources = ['businesslink']
+ artefact.save!
+ get :show, id: artefact.id, format: :json
+ parsed = JSON.parse(response.body)
+
+ assert_equal %w(businesslink crime), parsed['tag_ids'].sort
+ end
+
should "return 404 if the artefact's not found" do
get :show, id: 'bad-slug', format: :json
assert_equal 404, response.code.to_i
View
35 test/integration/artefacts_edit_test.rb
@@ -14,4 +14,39 @@ class ArtefactsEditTest < ActionDispatch::IntegrationTest
assert page.has_link?("View on site", :href => "http://www.test.gov.uk/alpha")
end
+
+ context "editing legacy_sources" do
+ setup do
+ @bl = FactoryGirl.create(:tag, :tag_type => 'legacy_source', :tag_id => 'businesslink', :title => 'Business Link')
+ @dg = FactoryGirl.create(:tag, :tag_type => 'legacy_source', :tag_id => 'directgov', :title => 'Directgov')
+ @dvla = FactoryGirl.create(:tag, :tag_type => 'legacy_source', :tag_id => 'dvla', :title => 'DVLA')
+ @a = FactoryGirl.create(:artefact, :name => "VAT")
+ end
+
+ should "allow adding legacy sources to artefacts" do
+ visit "/artefacts"
+ click_on "VAT"
+
+ select "Business Link", :from => "artefact[legacy_source_ids][]"
+ select "DVLA", :from => "artefact[legacy_source_ids][]"
+ click_on "Save and continue editing"
+
+ @a.reload
+ assert_equal [@bl, @dvla], @a.legacy_sources
+ end
+
+ should "allow removing legacy sources from artefacts" do
+ @a.legacy_source_ids = ['businesslink', 'directgov']
+ @a.save!
+
+ visit "/artefacts"
+ click_on "VAT"
+
+ unselect "Directgov", :from => "artefact[legacy_source_ids][]"
+ click_on "Save and continue editing"
+
+ @a.reload
+ assert_equal [@bl], @a.legacy_sources
+ end
+ end
end

0 comments on commit a311a54

Please sign in to comment.
Something went wrong with that request. Please try again.