meta_search 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -322,6 +322,10 @@ your controller. The other required parameter is the attribute name itself. Opti
322
322
  you can provide a string as a 3rd parameter to override the default link name, and then
323
323
  additional hashed for the +options+ and +html_options+ hashes for link_to.
324
324
 
325
+ By default, the link that is created will sort by the given column in ascending order when first clicked. If you'd like to reverse this (so the first click sorts the results in descending order), you can pass +:default_order => :desc+ in the options hash, like so:
326
+
327
+ <%= sort_link @search, :ratings, "Highest Rated", :default_order => :desc %>
328
+
325
329
  You can sort by more than one column as well, by creating a link like:
326
330
 
327
331
  <%= sort_link :name_and_salary %>
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.5
1
+ 1.0.6
data/lib/meta_search.rb CHANGED
@@ -15,7 +15,7 @@ module MetaSearch
15
15
  ['contains', 'like', 'matches', {:types => STRINGS, :predicate => :matches, :formatter => '"%#{param}%"'}],
16
16
  ['does_not_contain', 'nlike', 'not_matches', {:types => STRINGS, :predicate => :does_not_match, :formatter => '"%#{param}%"'}],
17
17
  ['starts_with', 'sw', {:types => STRINGS, :predicate => :matches, :formatter => '"#{param}%"'}],
18
- ['does_not_start_with', 'dnsw', {:types => STRINGS, :predicate => :does_not_match, :formatter => '"%#{param}%"'}],
18
+ ['does_not_start_with', 'dnsw', {:types => STRINGS, :predicate => :does_not_match, :formatter => '"#{param}%"'}],
19
19
  ['ends_with', 'ew', {:types => STRINGS, :predicate => :matches, :formatter => '"%#{param}"'}],
20
20
  ['does_not_end_with', 'dnew', {:types => STRINGS, :predicate => :does_not_match, :formatter => '"%#{param}"'}],
21
21
  ['greater_than', 'gt', {:types => (NUMBERS + DATES + TIMES), :predicate => :gt}],
@@ -16,14 +16,27 @@ module MetaSearch
16
16
  # <%= sort_link @search, :name, 'Company Name' %>
17
17
  # <%= sort_link @search, :name, :class => 'name_sort' %>
18
18
  # <%= sort_link @search, :name, 'Company Name', :class => 'company_name_sort' %>
19
+ # <%= sort_link @search, :name, :default_order => :desc %>
20
+ # <%= sort_link @search, :name, 'Company Name', :default_order => :desc %>
21
+ # <%= sort_link @search, :name, :class => 'name_sort', :default_order => :desc %>
22
+ # <%= sort_link @search, :name, 'Company Name', :class => 'company_name_sort', :default_order => :desc %>
23
+
19
24
  def sort_link(builder, attribute, *args)
20
25
  raise ArgumentError, "Need a MetaSearch::Builder search object as first param!" unless builder.is_a?(MetaSearch::Builder)
21
26
  attr_name = attribute.to_s
22
27
  name = (args.size > 0 && !args.first.is_a?(Hash)) ? args.shift.to_s : builder.base.human_attribute_name(attr_name)
23
28
  prev_attr, prev_order = builder.search_attributes['meta_sort'].to_s.split('.')
24
- current_order = prev_attr == attr_name ? prev_order : nil
25
- new_order = current_order == 'asc' ? 'desc' : 'asc'
29
+
26
30
  options = args.first.is_a?(Hash) ? args.shift : {}
31
+ current_order = prev_attr == attr_name ? prev_order : nil
32
+
33
+ if options[:default_order] == :desc
34
+ new_order = current_order == 'desc' ? 'asc' : 'desc'
35
+ else
36
+ new_order = current_order == 'asc' ? 'desc' : 'asc'
37
+ end
38
+ options.delete(:default_order)
39
+
27
40
  html_options = args.first.is_a?(Hash) ? args.shift : {}
28
41
  css = ['sort_link', current_order].compact.join(' ')
29
42
  html_options[:class] = [css, html_options[:class]].compact.join(' ')
@@ -50,4 +63,4 @@ module MetaSearch
50
63
  end
51
64
  end
52
65
  end
53
- end
66
+ end
@@ -6,9 +6,9 @@ dt_<%= n %>:
6
6
  int : <%= n ** 3 %>
7
7
  flt : <%= n.to_f / 2.0 %>
8
8
  dec : <%= n.to_f ** (n + 0.1) %>
9
- dtm : <%= (Time.utc(2009, 12, 24) + 86400 * n).to_s(:db) %>
10
- tms : <%= (Time.utc(2009, 12, 24) + 86400 * n).to_s(:db) %>
11
- tim : <%= Time.utc(2000, 01, 01, n+8, n).to_s(:db) %>
9
+ dtm : <%= (Time.local(2009, 12, 24) + 86400 * n).in_time_zone.to_s(:db) %>
10
+ tms : <%= (Time.local(2009, 12, 24) + 86400 * n).in_time_zone.to_s(:db) %>
11
+ tim : <%= Time.local(2000, 01, 01, n+8, n).in_time_zone.to_s(:db) %>
12
12
  dat : <%= (Date.new(2009, 12, 24) + n).strftime("%Y-%m-%d") %>
13
13
  bin : <%= "BLOB#{n}" * n %>
14
14
  bln : <%= n % 2 > 0 ? true : false %>
data/test/helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
3
  require 'shoulda'
4
+ require 'active_support/time'
4
5
  require 'active_record'
5
6
  require 'active_record/fixtures'
6
7
  require 'action_view'
@@ -305,6 +305,21 @@ class TestViewHelpers < ActionView::TestCase
305
305
  @s = Company.search
306
306
  end
307
307
 
308
+ should "generate a sort link for descending order if set as the default order" do
309
+ assert_match /name.desc/,
310
+ sort_link(@s, :name, :controller => 'companies', :default_order => :desc)
311
+ end
312
+
313
+ should "generate a sort link for ascending order if set as the default order" do
314
+ assert_match /name.asc/,
315
+ sort_link(@s, :name, :controller => 'companies', :default_order => :asc)
316
+ end
317
+
318
+ should "generate a sort link for ascending order if default is specified incorectly" do
319
+ assert_match /name.asc/,
320
+ sort_link(@s, :name, :controller => 'companies', :default_order => :something_else)
321
+ end
322
+
308
323
  context "sorted by name ascending" do
309
324
  setup do
310
325
  @s.meta_sort = 'name.asc'
@@ -320,6 +335,21 @@ class TestViewHelpers < ActionView::TestCase
320
335
  sort_link(@s, :created_at, :controller => 'companies')
321
336
  end
322
337
 
338
+ should "generate a sort link for descending order if ascending order is the default" do
339
+ assert_match /name.desc/,
340
+ sort_link(@s, :name, :controller => 'companies', :default_order => :asc)
341
+ end
342
+
343
+ should "generate a sort link for descending order if descending order is the default" do
344
+ assert_match /name.desc/,
345
+ sort_link(@s, :name, :controller => 'companies', :default_order => :desc)
346
+ end
347
+
348
+ should "generate a sort link for descending order if default is specified incorrectly" do
349
+ assert_match /name.desc/,
350
+ sort_link(@s, :name, :controller => 'companies', :default_order => :something_else)
351
+ end
352
+
323
353
  context "with existing search options" do
324
354
  setup do
325
355
  @s.name_contains = 'a'
@@ -331,6 +361,27 @@ class TestViewHelpers < ActionView::TestCase
331
361
  end
332
362
  end
333
363
  end
364
+
365
+ context "sorted by name descending" do
366
+ setup do
367
+ @s.meta_sort = 'name.desc'
368
+ end
369
+
370
+ should "generate a sort link for ascending order if descending order is the default" do
371
+ assert_match /name.asc/,
372
+ sort_link(@s, :name, :controller => 'companies', :default_order => :desc)
373
+ end
374
+
375
+ should "generate a sort link for ascending order if ascending order is the default" do
376
+ assert_match /name.asc/,
377
+ sort_link(@s, :name, :controller => 'companies', :default_order => :asc)
378
+ end
379
+
380
+ should "generate a sort link for ascending order if default is specified incorrectly" do
381
+ assert_match /name.asc/,
382
+ sort_link(@s, :name, :controller => 'companies', :default_order => :desc)
383
+ end
384
+ end
334
385
  end
335
386
 
336
387
  context "A developer search" do
@@ -365,4 +416,4 @@ class TestViewHelpers < ActionView::TestCase
365
416
  end
366
417
  end
367
418
  end
368
- end
419
+ end
metadata CHANGED
@@ -1,82 +1,81 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: meta_search
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.6
4
5
  prerelease:
5
- version: 1.0.5
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Ernie Miller
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-05-05 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2011-07-07 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: shoulda
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2158558880 !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
24
22
  type: :development
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: activerecord
28
23
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *2158558880
25
+ - !ruby/object:Gem::Dependency
26
+ name: activerecord
27
+ requirement: &2158558360 !ruby/object:Gem::Requirement
30
28
  none: false
31
- requirements:
29
+ requirements:
32
30
  - - ~>
33
- - !ruby/object:Gem::Version
31
+ - !ruby/object:Gem::Version
34
32
  version: 3.0.2
35
33
  type: :runtime
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
38
- name: activesupport
39
34
  prerelease: false
40
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *2158558360
36
+ - !ruby/object:Gem::Dependency
37
+ name: activesupport
38
+ requirement: &2158557760 !ruby/object:Gem::Requirement
41
39
  none: false
42
- requirements:
40
+ requirements:
43
41
  - - ~>
44
- - !ruby/object:Gem::Version
42
+ - !ruby/object:Gem::Version
45
43
  version: 3.0.2
46
44
  type: :runtime
47
- version_requirements: *id003
48
- - !ruby/object:Gem::Dependency
49
- name: actionpack
50
45
  prerelease: false
51
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *2158557760
47
+ - !ruby/object:Gem::Dependency
48
+ name: actionpack
49
+ requirement: &2158557160 !ruby/object:Gem::Requirement
52
50
  none: false
53
- requirements:
51
+ requirements:
54
52
  - - ~>
55
- - !ruby/object:Gem::Version
53
+ - !ruby/object:Gem::Version
56
54
  version: 3.0.2
57
55
  type: :runtime
58
- version_requirements: *id004
59
- - !ruby/object:Gem::Dependency
60
- name: arel
61
56
  prerelease: false
62
- requirement: &id005 !ruby/object:Gem::Requirement
57
+ version_requirements: *2158557160
58
+ - !ruby/object:Gem::Dependency
59
+ name: arel
60
+ requirement: &2158556560 !ruby/object:Gem::Requirement
63
61
  none: false
64
- requirements:
62
+ requirements:
65
63
  - - ~>
66
- - !ruby/object:Gem::Version
64
+ - !ruby/object:Gem::Version
67
65
  version: 2.0.2
68
66
  type: :runtime
69
- version_requirements: *id005
70
- description: "\n Allows simple search forms to be created against an AR3 model\n and its associations, has useful view helpers for sort links\n and multiparameter fields as well.\n "
67
+ prerelease: false
68
+ version_requirements: *2158556560
69
+ description: ! "\n Allows simple search forms to be created against an AR3 model\n
70
+ \ and its associations, has useful view helpers for sort links\n and multiparameter
71
+ fields as well.\n "
71
72
  email: ernie@metautonomo.us
72
73
  executables: []
73
-
74
74
  extensions: []
75
-
76
- extra_rdoc_files:
75
+ extra_rdoc_files:
77
76
  - LICENSE
78
77
  - README.rdoc
79
- files:
78
+ files:
80
79
  - .document
81
80
  - .gitmodules
82
81
  - CHANGELOG
@@ -118,35 +117,39 @@ files:
118
117
  - test/test_view_helpers.rb
119
118
  homepage: http://metautonomo.us/projects/metasearch/
120
119
  licenses: []
120
+ post_install_message: ! '
121
121
 
122
- post_install_message: "\n\
123
- *** Thanks for installing MetaSearch! ***\n\
124
- Be sure to check out http://metautonomo.us/projects/metasearch/ for a\n\
125
- walkthrough of MetaSearch's features, and click the donate button if\n\
126
- you're feeling especially appreciative. It'd help me justify this\n\
127
- \"open source\" stuff to my lovely wife. :)\n\n"
128
- rdoc_options: []
122
+ *** Thanks for installing MetaSearch! ***
123
+
124
+ Be sure to check out http://metautonomo.us/projects/metasearch/ for a
125
+
126
+ walkthrough of MetaSearch''s features, and click the donate button if
127
+
128
+ you''re feeling especially appreciative. It''d help me justify this
129
129
 
130
- require_paths:
130
+ "open source" stuff to my lovely wife. :)
131
+
132
+
133
+ '
134
+ rdoc_options: []
135
+ require_paths:
131
136
  - lib
132
- required_ruby_version: !ruby/object:Gem::Requirement
137
+ required_ruby_version: !ruby/object:Gem::Requirement
133
138
  none: false
134
- requirements:
135
- - - ">="
136
- - !ruby/object:Gem::Version
137
- version: "0"
138
- required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
144
  none: false
140
- requirements:
141
- - - ">="
142
- - !ruby/object:Gem::Version
143
- version: "0"
145
+ requirements:
146
+ - - ! '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
144
149
  requirements: []
145
-
146
150
  rubyforge_project:
147
- rubygems_version: 1.8.0
151
+ rubygems_version: 1.8.5
148
152
  signing_key:
149
153
  specification_version: 3
150
154
  summary: Object-based searching (and more) for simply creating search forms.
151
155
  test_files: []
152
-