meta_where 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,7 @@
1
+ Changes since 0.9.3 (2010-09-08):
2
+ * alias :& to :merge in singleton to work properly with Ruby 1.8.7.
3
+ * Fix merge to only use associations if not against the same base class. (STI)
4
+
1
5
  Changes since 0.9.2 (2010-08-26):
2
6
  * Updated gemspec to require Rails 3.0.0 final.
3
7
 
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "meta_where"
8
- gem.summary = %Q{Add a dash of Arel awesomeness to your condition hashes.}
8
+ gem.summary = %Q{ActiveRecord 3 query syntax on steroids.}
9
9
  gem.description = %Q{
10
10
  MetaWhere offers the ability to call any Arel predicate methods
11
11
  (with a few convenient aliases) on your Model's attributes instead
@@ -22,7 +22,15 @@ begin
22
22
  gem.add_dependency "activerecord", "~> 3.0.0"
23
23
  gem.add_dependency "activesupport", "~> 3.0.0"
24
24
  gem.add_dependency "arel", "~> 1.0.1"
25
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
25
+ gem.post_install_message = <<END
26
+
27
+ *** Thanks for installing MetaWhere! ***
28
+ Be sure to check out http://metautonomo.us/projects/metawhere/ for a
29
+ walkthrough of MetaWhere's features, and click the donate button if
30
+ you're feeling especially appreciative. It'd help me justify this
31
+ "open source" stuff to my lovely wife. :)
32
+
33
+ END
26
34
  end
27
35
  Jeweler::GemcutterTasks.new
28
36
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.3
1
+ 0.9.4
@@ -6,10 +6,15 @@ module MetaWhere
6
6
  alias_method_chain :reset, :metawhere
7
7
  alias_method_chain :scope_for_create, :metawhere
8
8
  end
9
+
10
+ # We have to do this on the singleton to work with Ruby 1.8.7. Not sure why.
11
+ base.instance_eval do
12
+ alias_method :&, :merge
13
+ end
9
14
  end
10
15
 
11
16
  def merge(r, association_name = nil)
12
- if (r && (association_name || klass.name != r.klass.name)) # Merging relations with different base.
17
+ if (r && (association_name || base_class != r.klass.base_class)) # Merging relations with different base.
13
18
  association_name ||= (default_association = reflect_on_all_associations.detect {|a| a.klass.name == r.klass.name}) ?
14
19
  default_association.name : r.table_name.to_sym
15
20
  r = r.clone
@@ -17,11 +22,10 @@ module MetaWhere
17
22
  r.joins_values.map! {|j| [Symbol, Hash].include?(j.class) ? {association_name => j} : j}
18
23
  self.joins_values += [association_name]
19
24
  end
25
+
20
26
  super(r)
21
27
  end
22
28
 
23
- alias_method :&, :merge
24
-
25
29
  def reset_with_metawhere
26
30
  @mw_unique_joins = @mw_association_joins = @mw_non_association_joins =
27
31
  @mw_stashed_association_joins = @mw_custom_joins = nil
@@ -42,7 +46,7 @@ module MetaWhere
42
46
 
43
47
  def build_where(opts, other = [])
44
48
  if opts.is_a?(String)
45
- @klass.send(:sanitize_sql, other.empty? ? opts : ([opts] + other))
49
+ [@klass.send(:sanitize_sql, other.empty? ? opts : ([opts] + other))]
46
50
  else
47
51
  predicates = []
48
52
  [opts, *other].each do |arg|
data/meta_where.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{meta_where}
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-23}
13
13
  s.description = %q{
14
14
  MetaWhere offers the ability to call any Arel predicate methods
15
15
  (with a few convenient aliases) on your Model's attributes instead
@@ -54,6 +54,7 @@ Gem::Specification.new do |s|
54
54
  "test/fixtures/developer.rb",
55
55
  "test/fixtures/developers.yml",
56
56
  "test/fixtures/developers_projects.yml",
57
+ "test/fixtures/fixed_bid_project.rb",
57
58
  "test/fixtures/invalid_company.rb",
58
59
  "test/fixtures/invalid_developer.rb",
59
60
  "test/fixtures/note.rb",
@@ -63,25 +64,36 @@ Gem::Specification.new do |s|
63
64
  "test/fixtures/project.rb",
64
65
  "test/fixtures/projects.yml",
65
66
  "test/fixtures/schema.rb",
67
+ "test/fixtures/time_and_materials_project.rb",
66
68
  "test/helper.rb",
67
69
  "test/test_base.rb",
68
70
  "test/test_relations.rb"
69
71
  ]
70
72
  s.homepage = %q{http://metautonomo.us/projects/metawhere/}
73
+ s.post_install_message = %q{
74
+ *** Thanks for installing MetaWhere! ***
75
+ Be sure to check out http://metautonomo.us/projects/metawhere/ for a
76
+ walkthrough of MetaWhere's features, and click the donate button if
77
+ you're feeling especially appreciative. It'd help me justify this
78
+ "open source" stuff to my lovely wife. :)
79
+
80
+ }
71
81
  s.rdoc_options = ["--charset=UTF-8"]
72
82
  s.require_paths = ["lib"]
73
83
  s.rubygems_version = %q{1.3.7}
74
- s.summary = %q{Add a dash of Arel awesomeness to your condition hashes.}
84
+ s.summary = %q{ActiveRecord 3 query syntax on steroids.}
75
85
  s.test_files = [
76
86
  "test/fixtures/company.rb",
77
87
  "test/fixtures/data_type.rb",
78
88
  "test/fixtures/developer.rb",
89
+ "test/fixtures/fixed_bid_project.rb",
79
90
  "test/fixtures/invalid_company.rb",
80
91
  "test/fixtures/invalid_developer.rb",
81
92
  "test/fixtures/note.rb",
82
93
  "test/fixtures/person.rb",
83
94
  "test/fixtures/project.rb",
84
95
  "test/fixtures/schema.rb",
96
+ "test/fixtures/time_and_materials_project.rb",
85
97
  "test/helper.rb",
86
98
  "test/test_base.rb",
87
99
  "test/test_relations.rb"
@@ -0,0 +1,2 @@
1
+ class FixedBidProject < Project
2
+ end
@@ -1,4 +1,7 @@
1
1
  class Project < ActiveRecord::Base
2
2
  has_and_belongs_to_many :developers
3
3
  has_many :notes, :as => :notable
4
+
5
+ default_scope where(:name.not_eq => nil)
6
+ scope :hours_lte_100, where(:estimated_hours.lte => 100)
4
7
  end
@@ -2,23 +2,28 @@ y2k:
2
2
  estimated_hours: 1000
3
3
  name : Y2K Software Updates
4
4
  id : 1
5
+ type : FixedBidProject
5
6
 
6
7
  virus:
7
8
  estimated_hours: 80
8
9
  name : Virus
9
10
  id : 2
10
-
11
+ type : FixedBidProject
12
+
11
13
  awesome:
12
14
  estimated_hours: 100
13
15
  name : Do something awesome
14
16
  id : 3
15
-
17
+ type : FixedBidProject
18
+
16
19
  metasearch:
17
20
  estimated_hours: 100
18
21
  name : MetaSearch Development
19
22
  id : 4
20
-
23
+ type : TimeAndMaterialsProject
24
+
21
25
  another:
22
26
  estimated_hours: 120
23
27
  name : Another Project
24
- id : 5
28
+ id : 5
29
+ type : TimeAndMaterialsProject
@@ -5,24 +5,25 @@ ActiveRecord::Schema.define do
5
5
  t.datetime "created_at"
6
6
  t.datetime "updated_at"
7
7
  end
8
-
8
+
9
9
  create_table "developers", :force => true do |t|
10
10
  t.integer "company_id"
11
11
  t.string "name"
12
12
  t.integer "salary"
13
13
  t.boolean "slacker"
14
14
  end
15
-
15
+
16
16
  create_table "projects", :force => true do |t|
17
17
  t.string "name"
18
+ t.string "type"
18
19
  t.float "estimated_hours"
19
20
  end
20
-
21
+
21
22
  create_table "developers_projects", :id => false, :force => true do |t|
22
23
  t.integer "developer_id"
23
24
  t.integer "project_id"
24
25
  end
25
-
26
+
26
27
  create_table "notes", :force => true do |t|
27
28
  t.string "notable_type"
28
29
  t.integer "notable_id"
@@ -43,7 +44,7 @@ ActiveRecord::Schema.define do
43
44
  t.binary "bin"
44
45
  t.boolean "bln"
45
46
  end
46
-
47
+
47
48
  create_table "people", :force => true do |t|
48
49
  t.integer "parent_id"
49
50
  t.string "name"
@@ -0,0 +1,2 @@
1
+ class TimeAndMaterialsProject < Project
2
+ end
data/test/helper.rb CHANGED
@@ -4,6 +4,9 @@ require 'shoulda'
4
4
  require 'active_record'
5
5
  require 'active_record/fixtures'
6
6
  require 'active_support/time'
7
+ require 'meta_where'
8
+
9
+ MetaWhere.operator_overload!
7
10
 
8
11
  FIXTURES_PATH = File.join(File.dirname(__FILE__), 'fixtures')
9
12
 
@@ -26,8 +29,6 @@ Fixtures.create_fixtures(FIXTURES_PATH, ActiveRecord::Base.connection.tables)
26
29
 
27
30
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
28
31
  $LOAD_PATH.unshift(File.dirname(__FILE__))
29
- require 'meta_where'
30
- MetaWhere.operator_overload!
31
32
 
32
33
  class Test::Unit::TestCase
33
34
  end
@@ -145,6 +145,26 @@ class TestRelations < Test::Unit::TestCase
145
145
  end
146
146
  end
147
147
 
148
+ context "A relation from an STI class" do
149
+ setup do
150
+ @r = TimeAndMaterialsProject.scoped
151
+ end
152
+
153
+ should "return results from the designated class only" do
154
+ assert_equal 2, @r.size
155
+ assert @r.all? {|r| r.is_a?(TimeAndMaterialsProject)}
156
+ end
157
+
158
+ should "inherit the default scope of the parent class" do
159
+ assert_match /IS NOT NULL/, @r.to_sql
160
+ end
161
+
162
+ should "allow use of scopes in the parent class" do
163
+ assert_equal 1, @r.hours_lte_100.size
164
+ assert_equal 'MetaSearch Development', @r.hours_lte_100.first.name
165
+ end
166
+ end
167
+
148
168
  context "A merged relation" do
149
169
  setup do
150
170
  @r = Developer.where(:salary.gteq % 70000) & Company.where(:name.matches % 'Initech')
@@ -201,8 +221,8 @@ class TestRelations < Test::Unit::TestCase
201
221
 
202
222
  context "with self-referencing joins on parent and children" do
203
223
  setup do
204
- @r = @r.where(:children => {:children => {:parent => {:parent => {:name => 'Abraham'}}}})
205
- .joins(:children => {:children => {:parent => :parent}})
224
+ @r = @r.where(:children => {:children => {:parent => {:parent => {:name => 'Abraham'}}}}).
225
+ joins(:children => {:children => {:parent => :parent}})
206
226
  end
207
227
 
208
228
  should "join the table multiple times with aliases" 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-23 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -114,6 +114,7 @@ files:
114
114
  - test/fixtures/developer.rb
115
115
  - test/fixtures/developers.yml
116
116
  - test/fixtures/developers_projects.yml
117
+ - test/fixtures/fixed_bid_project.rb
117
118
  - test/fixtures/invalid_company.rb
118
119
  - test/fixtures/invalid_developer.rb
119
120
  - test/fixtures/note.rb
@@ -123,6 +124,7 @@ files:
123
124
  - test/fixtures/project.rb
124
125
  - test/fixtures/projects.yml
125
126
  - test/fixtures/schema.rb
127
+ - test/fixtures/time_and_materials_project.rb
126
128
  - test/helper.rb
127
129
  - test/test_base.rb
128
130
  - test/test_relations.rb
@@ -130,7 +132,12 @@ has_rdoc: true
130
132
  homepage: http://metautonomo.us/projects/metawhere/
131
133
  licenses: []
132
134
 
133
- post_install_message:
135
+ post_install_message: "\n\
136
+ *** Thanks for installing MetaWhere! ***\n\
137
+ Be sure to check out http://metautonomo.us/projects/metawhere/ for a\n\
138
+ walkthrough of MetaWhere's features, and click the donate button if\n\
139
+ you're feeling especially appreciative. It'd help me justify this\n\
140
+ \"open source\" stuff to my lovely wife. :)\n\n"
134
141
  rdoc_options:
135
142
  - --charset=UTF-8
136
143
  require_paths:
@@ -157,17 +164,19 @@ rubyforge_project:
157
164
  rubygems_version: 1.3.7
158
165
  signing_key:
159
166
  specification_version: 3
160
- summary: Add a dash of Arel awesomeness to your condition hashes.
167
+ summary: ActiveRecord 3 query syntax on steroids.
161
168
  test_files:
162
169
  - test/fixtures/company.rb
163
170
  - test/fixtures/data_type.rb
164
171
  - test/fixtures/developer.rb
172
+ - test/fixtures/fixed_bid_project.rb
165
173
  - test/fixtures/invalid_company.rb
166
174
  - test/fixtures/invalid_developer.rb
167
175
  - test/fixtures/note.rb
168
176
  - test/fixtures/person.rb
169
177
  - test/fixtures/project.rb
170
178
  - test/fixtures/schema.rb
179
+ - test/fixtures/time_and_materials_project.rb
171
180
  - test/helper.rb
172
181
  - test/test_base.rb
173
182
  - test/test_relations.rb