meta_search 0.9.3 → 0.9.4

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.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ Changes since 0.9.3 (2010-09-08):
2
+ * Minor documentation fixes.
3
+ * Add sort_link helper to FormBuilder, to spare keystrokes if sort_links
4
+ are being added inside the context of the form_for of the search.
5
+
1
6
  Changes since 0.9.2 (2010-08-25):
2
7
  * Update dependencies for Rails 3 final.
3
8
 
data/README.rdoc CHANGED
@@ -50,8 +50,8 @@ Or, you can build up any relation you like and call the search method on that ob
50
50
 
51
51
  === Multi-level associations
52
52
 
53
- MetaSearch will allow you traverse your associations in one form, generating the necessary
54
- joins along the way. If you have the following models...
53
+ MetaSearch will allow you to traverse your associations in one form, generating the
54
+ necessary joins along the way. If you have the following models...
55
55
 
56
56
  class Company < ActiveRecord::Base
57
57
  has_many :developers
@@ -64,12 +64,12 @@ joins along the way. If you have the following models...
64
64
 
65
65
  ...you can do this in your form to search your companies by developers with certain notes:
66
66
 
67
- <%= f.text_field :developers_notes_note %>
67
+ <%= f.text_field :developers_notes_note_contains %>
68
68
 
69
69
  You can travel forward and back through the associations, so this would also work (though
70
70
  be entirely pointless in this case):
71
71
 
72
- <%= f.text_field :developers_notes_developer_company_name %>
72
+ <%= f.text_field :developers_notes_developer_company_name_contains %>
73
73
 
74
74
  However, to prevent abuse, this is limited to associations of a total "depth" of 5 levels.
75
75
  This means that while starting from a Company model, as above, you could do
@@ -202,7 +202,7 @@ All <tt>sort_link</tt>-generated links will have the CSS class sort_link, as wel
202
202
  directional class (ascending or descending) if the link is for a currently sorted column,
203
203
  for your styling enjoyment.
204
204
 
205
- This feature should hopefully help out those of you migrating from SearchLogic, and a thanks
205
+ This feature should hopefully help out those of you migrating from Searchlogic, and a thanks
206
206
  goes out to Ben Johnson for the HTML entities used for the up and down arrows, which provide
207
207
  a nice default look.
208
208
 
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "meta_search"
8
- gem.summary = %Q{ActiveRecord 3 object-based searching for your form_for enjoyment.}
8
+ gem.summary = %Q{Object-based searching (and more) for simply creating search forms.}
9
9
  gem.description = %Q{
10
10
  Allows simple search forms to be created against an AR3 model
11
11
  and its associations, has useful view helpers for sort links
@@ -19,7 +19,15 @@ begin
19
19
  gem.add_dependency "activesupport", "~> 3.0.0"
20
20
  gem.add_dependency "actionpack", "~> 3.0.0"
21
21
  gem.add_dependency "arel", "~> 1.0.1"
22
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
22
+ gem.post_install_message = <<END
23
+
24
+ *** Thanks for installing MetaSearch! ***
25
+ Be sure to check out http://metautonomo.us/projects/metasearch/ for a
26
+ walkthrough of MetaSearch's features, and click the donate button if
27
+ you're feeling especially appreciative. It'd help me justify this
28
+ "open source" stuff to my lovely wife. :)
29
+
30
+ END
23
31
  end
24
32
  Jeweler::GemcutterTasks.new
25
33
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.3
1
+ 0.9.4
@@ -85,22 +85,6 @@ module MetaSearch
85
85
  attribute
86
86
  end
87
87
 
88
- def base_includes_association?(base, assoc)
89
- if base._metasearch_include_associations.blank?
90
- base.reflect_on_association(assoc.to_sym) unless base._metasearch_exclude_associations.include?(assoc.to_s)
91
- else
92
- base.reflect_on_association(assoc.to_sym) if base._metasearch_include_associations.include?(assoc.to_s)
93
- end
94
- end
95
-
96
- def base_includes_attribute?(base, attribute)
97
- if base._metasearch_include_attributes.blank?
98
- base.column_names.detect(attribute.to_s) unless base._metasearch_exclude_attributes.include?(attribute.to_s)
99
- else
100
- base.column_names.detect(attribute.to_s) if base._metasearch_include_attributes.include?(attribute.to_s)
101
- end
102
- end
103
-
104
88
  # Build the search with the given search options. Options are in the form of a hash
105
89
  # with keys matching the names creted by the Builder's "wheres" as outlined in
106
90
  # MetaSearch::Where
@@ -135,6 +135,19 @@ module MetaSearch
135
135
  check_boxes unless block_given?
136
136
  end
137
137
 
138
+ # Creates a sort link for the MetaSearch::Builder the form is created against.
139
+ # Useful shorthand if your results happen to reside in the context of your
140
+ # form_for block.
141
+ # Sample usage:
142
+ #
143
+ # <%= f.sort_link :name %>
144
+ # <%= f.sort_link :name, 'Company Name' %>
145
+ # <%= f.sort_link :name, :class => 'name_sort' %>
146
+ # <%= f.sort_link :name, 'Company Name', :class => 'company_name_sort' %>
147
+ def sort_link(attribute, *args)
148
+ @template.sort_link @object, attribute, *args
149
+ end
150
+
138
151
  private
139
152
 
140
153
  # If the last element of the arguments to multiparameter_field has no :field_type
@@ -1,7 +1,21 @@
1
1
  module MetaSearch
2
2
  module Helpers
3
3
  module UrlHelper
4
-
4
+
5
+ # Generates a column sort link for a given attribute of a MetaSearch::Builder object.
6
+ # The link maintains existing options for the sort as parameters in the URL, and
7
+ # sets a meta_sort parameter as well. If the first parameter after the attribute name
8
+ # is not a hash, it will be used as a string for alternate link text. If a hash is
9
+ # supplied, it will be passed to link_to as an html_options hash. The link will
10
+ # be assigned two css classes: sort_link and one of "asc" or "desc", depending on
11
+ # the current sort order. Any class supplied in the options hash will be appended.
12
+ #
13
+ # Sample usage:
14
+ #
15
+ # <%= sort_link @search, :name %>
16
+ # <%= sort_link @search, :name, 'Company Name' %>
17
+ # <%= sort_link @search, :name, :class => 'name_sort' %>
18
+ # <%= sort_link @search, :name, 'Company Name', :class => 'company_name_sort' %>
5
19
  def sort_link(builder, attribute, *args)
6
20
  raise ArgumentError, "Need a MetaSearch::Builder search object as first param!" unless builder.is_a?(MetaSearch::Builder)
7
21
  attr_name = attribute.to_s
@@ -22,9 +36,9 @@ module MetaSearch
22
36
  url_for(options),
23
37
  html_options
24
38
  end
25
-
39
+
26
40
  private
27
-
41
+
28
42
  def order_indicator_for(order)
29
43
  if order == 'asc'
30
44
  '&#9650;'
data/meta_search.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{meta_search}
8
- s.version = "0.9.3"
8
+ s.version = "0.9.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ernie Miller"]
12
- s.date = %q{2010-09-08}
12
+ s.date = %q{2010-09-18}
13
13
  s.description = %q{
14
14
  Allows simple search forms to be created against an AR3 model
15
15
  and its associations, has useful view helpers for sort links
@@ -60,10 +60,18 @@ Gem::Specification.new do |s|
60
60
  "test/test_view_helpers.rb"
61
61
  ]
62
62
  s.homepage = %q{http://metautonomo.us/projects/metasearch/}
63
+ s.post_install_message = %q{
64
+ *** Thanks for installing MetaSearch! ***
65
+ Be sure to check out http://metautonomo.us/projects/metasearch/ for a
66
+ walkthrough of MetaSearch's features, and click the donate button if
67
+ you're feeling especially appreciative. It'd help me justify this
68
+ "open source" stuff to my lovely wife. :)
69
+
70
+ }
63
71
  s.rdoc_options = ["--charset=UTF-8"]
64
72
  s.require_paths = ["lib"]
65
73
  s.rubygems_version = %q{1.3.7}
66
- s.summary = %q{ActiveRecord 3 object-based searching for your form_for enjoyment.}
74
+ s.summary = %q{Object-based searching (and more) for simply creating search forms.}
67
75
  s.test_files = [
68
76
  "test/fixtures/company.rb",
69
77
  "test/fixtures/data_type.rb",
data/test/helper.rb CHANGED
@@ -4,6 +4,7 @@ require 'shoulda'
4
4
  require 'active_record'
5
5
  require 'active_record/fixtures'
6
6
  require 'action_view'
7
+ require 'meta_search'
7
8
 
8
9
  FIXTURES_PATH = File.join(File.dirname(__FILE__), 'fixtures')
9
10
 
@@ -26,7 +27,6 @@ Fixtures.create_fixtures(FIXTURES_PATH, ActiveRecord::Base.connection.tables)
26
27
 
27
28
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
28
29
  $LOAD_PATH.unshift(File.dirname(__FILE__))
29
- require 'meta_search'
30
30
 
31
31
  class Test::Unit::TestCase
32
32
  def self.context_a_search_against(name, object, &block)
@@ -152,32 +152,52 @@ class TestViewHelpers < ActionView::TestCase
152
152
  <% end -%>
153
153
  ERB
154
154
  end
155
+ end
155
156
 
156
- context "A form using collection_check_boxes with companies" do
157
- setup do
158
- @s = Company.search
159
- form_for @s do |f|
160
- @f = f
161
- end
157
+ context "A form using collection_check_boxes with companies" do
158
+ setup do
159
+ @s = Company.search
160
+ form_for @s do |f|
161
+ @f = f
162
162
  end
163
+ end
164
+
165
+ should "return an array of check boxes without a block" do
166
+ assert @f.collection_check_boxes(:id_in, Company.all, :id, :name).all?{|c| c.is_a?(MetaSearch::Check)}
167
+ end
163
168
 
164
- should "return an array of check boxes without a block" do
165
- assert @f.collection_check_boxes(:id_in, Company.all, :id, :name).all?{|c| c.is_a?(MetaSearch::Check)}
169
+ should "generate the expected HTML with a block" do
170
+ @f.collection_check_boxes(:id_in, Company.all, :id, :name) do |c|
171
+ concat render :to => :string, :inline => "<p><%= c.label %> <%= c.box %></p>", :locals => {:c => c}
166
172
  end
173
+ assert_dom_equal output_buffer,
174
+ '<p><label for="search_id_in_1">Initech</label> ' +
175
+ '<input id="search_id_in_1" name="search[id_in][]" type="checkbox" value="1" /></p>' +
176
+ '<p><label for="search_id_in_2">Advanced Optical Solutions</label> ' +
177
+ '<input id="search_id_in_2" name="search[id_in][]" type="checkbox" value="2" /></p>' +
178
+ '<p><label for="search_id_in_3">Mission Data</label> ' +
179
+ '<input id="search_id_in_3" name="search[id_in][]" type="checkbox" value="3" /></p>'
180
+ end
181
+ end
167
182
 
168
- should "generate the expected HTML with a block" do
169
- @f.collection_check_boxes(:id_in, Company.all, :id, :name) do |c|
170
- concat render :to => :string, :inline => "<p><%= c.label %> <%= c.box %></p>", :locals => {:c => c}
171
- end
172
- assert_dom_equal output_buffer,
173
- '<p><label for="search_id_in_1">Initech</label> ' +
174
- '<input id="search_id_in_1" name="search[id_in][]" type="checkbox" value="1" /></p>' +
175
- '<p><label for="search_id_in_2">Advanced Optical Solutions</label> ' +
176
- '<input id="search_id_in_2" name="search[id_in][]" type="checkbox" value="2" /></p>' +
177
- '<p><label for="search_id_in_3">Mission Data</label> ' +
178
- '<input id="search_id_in_3" name="search[id_in][]" type="checkbox" value="3" /></p>'
183
+ context "A company search form sorted by name ascending" do
184
+ setup do
185
+ @s = Company.search
186
+ @s.meta_sort = 'name.asc'
187
+ form_for @s do |f|
188
+ @f = f
179
189
  end
180
190
  end
191
+
192
+ should "generate a sort link with an up arrow for the sorted column" do
193
+ assert_match /Name &#9650;/,
194
+ @f.sort_link(:name, :controller => 'companies')
195
+ end
196
+
197
+ should "not generate a sort link with an up arrow for a non-sorted column" do
198
+ assert_no_match /Created at &#9650;/,
199
+ @f.sort_link(:created_at, :controller => 'companies')
200
+ end
181
201
  end
182
202
 
183
203
  context "A company search" do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 9
8
- - 3
9
- version: 0.9.3
8
+ - 4
9
+ version: 0.9.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ernie Miller
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-08 00:00:00 -04:00
17
+ date: 2010-09-18 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -141,7 +141,12 @@ has_rdoc: true
141
141
  homepage: http://metautonomo.us/projects/metasearch/
142
142
  licenses: []
143
143
 
144
- post_install_message:
144
+ post_install_message: "\n\
145
+ *** Thanks for installing MetaSearch! ***\n\
146
+ Be sure to check out http://metautonomo.us/projects/metasearch/ for a\n\
147
+ walkthrough of MetaSearch's features, and click the donate button if\n\
148
+ you're feeling especially appreciative. It'd help me justify this\n\
149
+ \"open source\" stuff to my lovely wife. :)\n\n"
145
150
  rdoc_options:
146
151
  - --charset=UTF-8
147
152
  require_paths:
@@ -168,7 +173,7 @@ rubyforge_project:
168
173
  rubygems_version: 1.3.7
169
174
  signing_key:
170
175
  specification_version: 3
171
- summary: ActiveRecord 3 object-based searching for your form_for enjoyment.
176
+ summary: Object-based searching (and more) for simply creating search forms.
172
177
  test_files:
173
178
  - test/fixtures/company.rb
174
179
  - test/fixtures/data_type.rb