govuk_content_models 6.1.0 → 6.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -45,7 +45,14 @@ class BusinessSupportEdition < Edition
45
45
  @fields_to_clone = [:body, :min_value, :max_value, :max_employees, :organiser,
46
46
  :eligibility, :evaluation, :additional_information, :continuation_link,
47
47
  :will_continue_on, :contact_details, :short_description,
48
- :business_support_identifier]
48
+ :business_support_identifier, :priority, :business_sizes,
49
+ :locations, :purposes, :sectors, :stages, :support_types,
50
+ :start_date, :end_date]
51
+
52
+ scope :for_facets, lambda { |facets|
53
+ where({ "$and" => facets_criteria(facets) }).order_by([:priority, :desc], [:title, :asc])
54
+ }
55
+
49
56
 
50
57
  def whole_body
51
58
  [short_description, body].join("\n\n")
@@ -66,4 +73,13 @@ class BusinessSupportEdition < Edition
66
73
  errors.add(:business_support_identifier, :taken)
67
74
  end
68
75
  end
76
+
77
+ def self.facets_criteria(facets)
78
+ criteria = []
79
+ facets.each do |facet_name, values|
80
+ slugs = values.split(",")
81
+ criteria << { facet_name => { "$in" => slugs } } unless slugs.empty?
82
+ end
83
+ criteria
84
+ end
69
85
  end
@@ -1,4 +1,4 @@
1
1
  module GovukContentModels
2
2
  # Changing this causes Jenkins to tag and release the gem into the wild
3
- VERSION = "6.1.0"
3
+ VERSION = "6.3.0"
4
4
  end
@@ -166,7 +166,17 @@ class BusinessSupportEditionTest < ActiveSupport::TestCase
166
166
  :additional_information => "Additional info to be cloned",
167
167
  :will_continue_on => "Continuation text to be cloned",
168
168
  :continuation_link => "http://www.gov.uk",
169
- :contact_details => "Contact details to be cloned")
169
+ :contact_details => "Contact details to be cloned",
170
+ :priority => 2,
171
+ :business_sizes => ['up-to-249'],
172
+ :locations => ['london'],
173
+ :purposes => ['start-up'],
174
+ :sectors => ['agriculture','manufacturing'],
175
+ :stages => ['grow-and-sustain'],
176
+ :support_types => ['grant','loan'],
177
+ :start_date => 1.year.ago(Date.today),
178
+ :end_date => 1.year.since(Date.today))
179
+
170
180
  new_support = support.build_clone
171
181
 
172
182
  assert_equal support.business_support_identifier, new_support.business_support_identifier
@@ -182,5 +192,52 @@ class BusinessSupportEditionTest < ActiveSupport::TestCase
182
192
  assert_equal support.will_continue_on, new_support.will_continue_on
183
193
  assert_equal support.continuation_link, new_support.continuation_link
184
194
  assert_equal support.contact_details, new_support.contact_details
195
+
196
+ assert_equal support.priority, new_support.priority
197
+ assert_equal support.business_sizes, new_support.business_sizes
198
+ assert_equal support.locations, new_support.locations
199
+ assert_equal support.purposes, new_support.purposes
200
+ assert_equal support.sectors, new_support.sectors
201
+ assert_equal support.stages, new_support.stages
202
+ assert_equal support.support_types, new_support.support_types
203
+ assert_equal support.start_date, new_support.start_date
204
+ assert_equal support.end_date, new_support.end_date
205
+ end
206
+
207
+ context "for facets" do
208
+ setup do
209
+ @e1 = FactoryGirl.create(:business_support_edition,
210
+ :business_sizes => ['1', 'up-to-1000000'],
211
+ :locations => ['narnia'], :purposes => ['world-domination'],
212
+ :sectors => ['agriculture', 'healthcare'],
213
+ :stages => ['pivoting'], :support_types => ['award', 'grant', 'loan'])
214
+ @e2 = FactoryGirl.create(:business_support_edition,
215
+ :business_sizes => ['1', 'up-to-1000000'],
216
+ :locations => ['hades', 'narnia'], :purposes => ['business-growth-and-expansion'],
217
+ :sectors => ['education', 'healthcare'],
218
+ :stages => ['start-up', 'pivoting'], :support_types => ['grant', 'loan', 'equity'])
219
+ @e3 = FactoryGirl.create(:business_support_edition,
220
+ :business_sizes => ['up-to-249', 'up-to-1000000'],
221
+ :locations => ['hades', 'chicken-town'], :purposes => ['making-the-most-of-the-internet'],
222
+ :sectors => ['utilities'], :stages => ['start-up'], :support_types => ['grant'])
223
+ end
224
+
225
+ should "only return editions matching the facet values provided" do
226
+ editions = BusinessSupportEdition.for_facets({:purposes => 'business-growth-and-expansion', :support_types => 'equity'})
227
+ assert_equal [@e2], editions
228
+ editions = BusinessSupportEdition.for_facets({:business_sizes => '1,up-to-1000000', :locations => 'narnia'})
229
+ assert_equal [@e1, @e2], editions
230
+ end
231
+ should "support searching with all the facet values" do
232
+ editions = BusinessSupportEdition.for_facets({:business_sizes => 'up-to-1000000', :locations => 'narnia,hades,chicken-town',
233
+ :purposes => 'business-growth-and-expansion,making-the-most-of-the-internet,world-domination',
234
+ :sectors => 'agriculture,healthcare,utilities', :stages => 'pivoting,start-up',
235
+ :support_types => 'award,grant,loan'})
236
+ assert_equal [@e1, @e2, @e3], editions
237
+ end
238
+ should "return nothing where no facet values match" do
239
+ editions = BusinessSupportEdition.for_facets({:business_sizes => 'up-to-a-bizillion', :locations => 'ecclefechan'})
240
+ assert_empty editions
241
+ end
185
242
  end
186
243
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_content_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.1.0
4
+ version: 6.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-29 00:00:00.000000000 Z
12
+ date: 2014-02-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bson_ext
@@ -454,7 +454,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
454
454
  version: '0'
455
455
  segments:
456
456
  - 0
457
- hash: -3811890245827365006
457
+ hash: 1683068425110248072
458
458
  required_rubygems_version: !ruby/object:Gem::Requirement
459
459
  none: false
460
460
  requirements:
@@ -463,7 +463,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
463
463
  version: '0'
464
464
  segments:
465
465
  - 0
466
- hash: -3811890245827365006
466
+ hash: 1683068425110248072
467
467
  requirements: []
468
468
  rubyforge_project:
469
469
  rubygems_version: 1.8.23