meta_where 0.9.0 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitmodules CHANGED
@@ -1,6 +1,6 @@
1
- [submodule "vendor/rails"]
2
- path = vendor/rails
3
- url = git://github.com/rails/rails.git
4
1
  [submodule "vendor/arel"]
5
2
  path = vendor/arel
6
3
  url = git://github.com/rails/arel.git
4
+ [submodule "vendor/rails"]
5
+ path = vendor/rails
6
+ url = git://github.com/rails/rails.git
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ Changes since 0.9.1 (2010-08-25):
2
+ * Fix missing .any? on method chain in check for mw in association macros.
3
+
4
+ Changes since 0.9.0 (2010-08-24):
5
+ * Check for use of MetaWhere in association macros. This won't work as expected
6
+ so it's better to raise a helpful error than create a potentially confusing
7
+ behavior.
8
+
1
9
  Changes since 0.5.2 (2010-07-09):
2
10
  * Removed autojoin. Inner joins have side-effects. Newbies are the ones who aremost
3
11
  likely to use autojoin, and they're also the ones least likely to understand why
@@ -10,6 +18,12 @@ Changes since 0.5.2 (2010-07-09):
10
18
  * Improved merge functonality. It shouldn't have ever required someone to do an
11
19
  autojoin to begin with. Now it just works. If you're merging two relations, you
12
20
  should expect to only get results that have a match on both sides.
21
+ * Attempt to gracefully degrade in the case where a MetaWhere::Column is expected
22
+ to be a normal symbol. Return the column name in #to_s.
23
+ * Fix order clauses when constructing a limited_ids_condition for postgresql.
24
+ * Fix problems with cache_classes == false on certain server configurations. Also
25
+ handle self-join with a merge of two identical classes and a second param.
26
+ * Drop ActiveSupport::Concern and only use alias_method_chain when needed.
13
27
 
14
28
  Changes since 0.5.1 (2010-06-22):
15
29
  * Added debug_sql method to Relations. Lets you see the actual SQL that
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.0
1
+ 0.9.2
data/lib/meta_where.rb CHANGED
@@ -21,7 +21,9 @@ require 'meta_where/compound'
21
21
  require 'core_ext/symbol'
22
22
  require 'core_ext/hash'
23
23
  require 'meta_where/builder'
24
+ require 'meta_where/association_reflection'
24
25
  require 'meta_where/relation'
25
26
  require 'meta_where/join_dependency'
26
27
  ActiveRecord::Relation.send(:include, MetaWhere::Relation)
28
+ ActiveRecord::Reflection::AssociationReflection.send(:include, MetaWhere::AssociationReflection)
27
29
  ActiveRecord::Associations::ClassMethods::JoinDependency.send(:include, MetaWhere::JoinDependency)
@@ -0,0 +1,51 @@
1
+ module MetaWhere
2
+ class MetaWhereInAssociationError < StandardError; end
3
+
4
+ module AssociationReflection
5
+
6
+ def initialize(macro, name, options, active_record)
7
+ super
8
+
9
+ if options.has_key?(:conditions)
10
+ ensure_no_metawhere_in_conditions(options[:conditions])
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def ensure_no_metawhere_in_conditions(obj)
17
+ case obj
18
+ when Hash
19
+ if obj.keys.grep(MetaWhere::Column).any?
20
+ raise MetaWhereInAssociationError, <<END
21
+ The :#{name} association has a MetaWhere::Column in its :conditions. \
22
+ If you actually needed to access conditions other than equality, then you most \
23
+ likely meant to set up a scope or method, instead. Associations only work with \
24
+ standard equality conditions, since they can be used to create records as well.
25
+ END
26
+ end
27
+
28
+ obj.values.each do |v|
29
+ case v
30
+ when MetaWhere::Condition, Array, Hash
31
+ ensure_no_metawhere_in_conditions(v)
32
+ end
33
+ end
34
+ when Array
35
+ obj.each do |v|
36
+ case v
37
+ when MetaWhere::Condition, Array, Hash
38
+ ensure_no_metawhere_in_conditions(v)
39
+ end
40
+ end
41
+ when MetaWhere::Condition
42
+ raise MetaWhereInAssociationError, <<END
43
+ The :#{name} association has a MetaWhere::Condition in its :conditions. \
44
+ If you actually needed to access conditions other than equality, then you most \
45
+ likely meant to set up a scope or method, instead. Associations only work with \
46
+ standard equality conditions, since they can be used to create records as well.
47
+ END
48
+ end
49
+ end
50
+ end
51
+ end
@@ -39,15 +39,9 @@ module MetaWhere
39
39
  [column, method].hash
40
40
  end
41
41
 
42
- # Play "nicely" with expand_hash_conditions_for_aggregates
42
+ # Play nicely with expand_hash_conditions_for_aggregates
43
43
  def to_sym
44
- self
44
+ "#{column}.#{method}".to_sym
45
45
  end
46
-
47
- # Let's degrade hracefully if someone expects us to be a symbol or something
48
- def to_s
49
- @column
50
- end
51
-
52
46
  end
53
47
  end
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.0"
8
+ s.version = "0.9.2"
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-08-24}
12
+ s.date = %q{2010-08-26}
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
@@ -38,6 +38,7 @@ Gem::Specification.new do |s|
38
38
  "lib/core_ext/symbol.rb",
39
39
  "lib/core_ext/symbol_operators.rb",
40
40
  "lib/meta_where.rb",
41
+ "lib/meta_where/association_reflection.rb",
41
42
  "lib/meta_where/builder.rb",
42
43
  "lib/meta_where/column.rb",
43
44
  "lib/meta_where/compound.rb",
@@ -53,6 +54,8 @@ Gem::Specification.new do |s|
53
54
  "test/fixtures/developer.rb",
54
55
  "test/fixtures/developers.yml",
55
56
  "test/fixtures/developers_projects.yml",
57
+ "test/fixtures/invalid_company.rb",
58
+ "test/fixtures/invalid_developer.rb",
56
59
  "test/fixtures/note.rb",
57
60
  "test/fixtures/notes.yml",
58
61
  "test/fixtures/people.yml",
@@ -61,6 +64,7 @@ Gem::Specification.new do |s|
61
64
  "test/fixtures/projects.yml",
62
65
  "test/fixtures/schema.rb",
63
66
  "test/helper.rb",
67
+ "test/test_base.rb",
64
68
  "test/test_relations.rb"
65
69
  ]
66
70
  s.homepage = %q{http://metautonomo.us/projects/metawhere/}
@@ -72,11 +76,14 @@ Gem::Specification.new do |s|
72
76
  "test/fixtures/company.rb",
73
77
  "test/fixtures/data_type.rb",
74
78
  "test/fixtures/developer.rb",
79
+ "test/fixtures/invalid_company.rb",
80
+ "test/fixtures/invalid_developer.rb",
75
81
  "test/fixtures/note.rb",
76
82
  "test/fixtures/person.rb",
77
83
  "test/fixtures/project.rb",
78
84
  "test/fixtures/schema.rb",
79
85
  "test/helper.rb",
86
+ "test/test_base.rb",
80
87
  "test/test_relations.rb"
81
88
  ]
82
89
 
@@ -0,0 +1,4 @@
1
+ class InvalidCompany < ActiveRecord::Base
2
+ set_table_name 'companies'
3
+ has_many :developers, :conditions => {:name.matches => '%Miller'}
4
+ end
@@ -0,0 +1,4 @@
1
+ class InvalidDeveloper < ActiveRecord::Base
2
+ set_table_name 'developers'
3
+ has_many :notes, :as => :notable, :conditions => [:note.eq % 'GIPE']
4
+ end
data/test/test_base.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'helper'
2
+
3
+ class TestBase < Test::Unit::TestCase
4
+ should "raise nothing when an association's conditions hash doesn't use MetaWhere" do
5
+ assert_nothing_raised do
6
+ Company.all
7
+ end
8
+ end
9
+
10
+ should "raise an exception when MetaWhere::Columns are in :conditions of an association" do
11
+ assert_raises MetaWhere::MetaWhereInAssociationError do
12
+ InvalidCompany.all
13
+ end
14
+ end
15
+
16
+ should "raise an exception when MetaWhere::Conditions are in :conditions of an association" do
17
+ assert_raises MetaWhere::MetaWhereInAssociationError do
18
+ InvalidDeveloper.all
19
+ end
20
+ end
21
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 9
8
- - 0
9
- version: 0.9.0
8
+ - 2
9
+ version: 0.9.2
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-08-24 00:00:00 -04:00
17
+ date: 2010-08-26 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -101,6 +101,7 @@ files:
101
101
  - lib/core_ext/symbol.rb
102
102
  - lib/core_ext/symbol_operators.rb
103
103
  - lib/meta_where.rb
104
+ - lib/meta_where/association_reflection.rb
104
105
  - lib/meta_where/builder.rb
105
106
  - lib/meta_where/column.rb
106
107
  - lib/meta_where/compound.rb
@@ -116,6 +117,8 @@ files:
116
117
  - test/fixtures/developer.rb
117
118
  - test/fixtures/developers.yml
118
119
  - test/fixtures/developers_projects.yml
120
+ - test/fixtures/invalid_company.rb
121
+ - test/fixtures/invalid_developer.rb
119
122
  - test/fixtures/note.rb
120
123
  - test/fixtures/notes.yml
121
124
  - test/fixtures/people.yml
@@ -124,6 +127,7 @@ files:
124
127
  - test/fixtures/projects.yml
125
128
  - test/fixtures/schema.rb
126
129
  - test/helper.rb
130
+ - test/test_base.rb
127
131
  - test/test_relations.rb
128
132
  has_rdoc: true
129
133
  homepage: http://metautonomo.us/projects/metawhere/
@@ -161,9 +165,12 @@ test_files:
161
165
  - test/fixtures/company.rb
162
166
  - test/fixtures/data_type.rb
163
167
  - test/fixtures/developer.rb
168
+ - test/fixtures/invalid_company.rb
169
+ - test/fixtures/invalid_developer.rb
164
170
  - test/fixtures/note.rb
165
171
  - test/fixtures/person.rb
166
172
  - test/fixtures/project.rb
167
173
  - test/fixtures/schema.rb
168
174
  - test/helper.rb
175
+ - test/test_base.rb
169
176
  - test/test_relations.rb