metaskills-grouped_scope 0.5.1

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.
@@ -0,0 +1,55 @@
1
+
2
+ ActiveRecord::Associations::AssociationProxy.class_eval do
3
+ protected
4
+ def with_scope(*args, &block)
5
+ @reflection.klass.send :with_scope, *args, &block
6
+ end
7
+ end
8
+
9
+ class ActiveRecord::Base
10
+ class << self
11
+ def find(*args)
12
+ options = args.extract_options!
13
+ validate_find_options(options)
14
+ set_readonly_option!(options)
15
+ case args.first
16
+ when :first then find_initial(options)
17
+ when :last then find_last(options)
18
+ when :all then find_every(options)
19
+ else find_from_ids(args, options)
20
+ end
21
+ end
22
+ private
23
+ def attribute_condition_with_named_scope(argument)
24
+ case argument
25
+ when ActiveRecord::NamedScope::Scope then "IN (?)"
26
+ else attribute_condition_without_named_scope(argument)
27
+ end
28
+ end
29
+ alias_method_chain :attribute_condition, :named_scope
30
+ end
31
+ end
32
+
33
+ ActiveRecord::Associations::AssociationCollection.class_eval do
34
+ protected
35
+ def method_missing(method, *args)
36
+ if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method))
37
+ if block_given?
38
+ super { |*block_args| yield(*block_args) }
39
+ else
40
+ super
41
+ end
42
+ elsif @reflection.klass.scopes.include?(method)
43
+ @reflection.klass.scopes[method].call(self, *args)
44
+ else
45
+ with_scope(construct_scope) do
46
+ if block_given?
47
+ @reflection.klass.send(method, *args) { |*block_args| yield(*block_args) }
48
+ else
49
+ @reflection.klass.send(method, *args)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+
@@ -0,0 +1,7 @@
1
+ unless defined? ActiveRecord::NamedScope
2
+ require "named_scope/core_ext"
3
+ require "named_scope/named_scope"
4
+ require "named_scope/named_scope_patch_#{ActiveRecord::Base.respond_to?(:find_first) ? '1.2' : '2.0'}"
5
+ ActiveRecord::Base.send :include, ActiveRecord::NamedScope
6
+ end
7
+
@@ -0,0 +1,44 @@
1
+
2
+ ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__)+'/../debug.log')
3
+ ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
4
+ ActiveRecord::Base.connection.class.class_eval do
5
+ IGNORED_SQL = [/^PRAGMA/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/]
6
+ def execute_with_query_record(sql, name = nil, &block)
7
+ $queries_executed ||= []
8
+ $queries_executed << sql unless IGNORED_SQL.any? { |r| sql =~ r }
9
+ execute_without_query_record(sql, name, &block)
10
+ end
11
+ alias_method_chain :execute, :query_record
12
+ end
13
+
14
+ module GroupedScope
15
+ class TestCase < Test::Unit::TestCase
16
+
17
+ def test_truth ; end
18
+
19
+ protected
20
+
21
+ def assert_sql(*patterns_to_match)
22
+ $queries_executed = []
23
+ yield
24
+ ensure
25
+ failed_patterns = []
26
+ patterns_to_match.each do |pattern|
27
+ failed_patterns << pattern unless $queries_executed.any?{ |sql| pattern === sql }
28
+ end
29
+ assert failed_patterns.empty?, "Query pattern(s) #{failed_patterns.map(&:inspect).join(', ')} not found in:\n#{$queries_executed.inspect}"
30
+ end
31
+
32
+ def assert_queries(num = 1)
33
+ $queries_executed = []
34
+ yield
35
+ ensure
36
+ assert_equal num, $queries_executed.size, "#{$queries_executed.size} instead of #{num} queries were executed."
37
+ end
38
+
39
+ def assert_no_queries(&block)
40
+ assert_queries(0, &block)
41
+ end
42
+
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: metaskills-grouped_scope
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.1
5
+ platform: ruby
6
+ authors:
7
+ - Ken Collins
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-01-07 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Extends has_many associations to group scope.
17
+ email: ken@metaskills.net
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ - CHANGELOG
25
+ - MIT-LICENSE
26
+ files:
27
+ - CHANGELOG
28
+ - MIT-LICENSE
29
+ - Rakefile
30
+ - README.rdoc
31
+ - init.rb
32
+ - lib/grouped_scope.rb
33
+ - lib/grouped_scope/association_reflection.rb
34
+ - lib/grouped_scope/class_methods.rb
35
+ - lib/grouped_scope/core_ext.rb
36
+ - lib/grouped_scope/errors.rb
37
+ - lib/grouped_scope/grouping.rb
38
+ - lib/grouped_scope/has_many_association.rb
39
+ - lib/grouped_scope/has_many_through_association.rb
40
+ - lib/grouped_scope/instance_methods.rb
41
+ - lib/grouped_scope/self_grouping.rb
42
+ has_rdoc: true
43
+ homepage: http://github.com/metaskills/grouped_scope/
44
+ post_install_message:
45
+ rdoc_options:
46
+ - --main
47
+ - README.rdoc
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.2.0
66
+ signing_key:
67
+ specification_version: 2
68
+ summary: Extends has_many associations to group scope.
69
+ test_files:
70
+ - test/factories.rb
71
+ - test/grouped_scope/association_reflection_test.rb
72
+ - test/grouped_scope/class_methods_test.rb
73
+ - test/grouped_scope/has_many_association_test.rb
74
+ - test/grouped_scope/has_many_through_association_test.rb
75
+ - test/grouped_scope/self_grouping_test.rb
76
+ - test/helper.rb
77
+ - test/lib/boot.rb
78
+ - test/lib/core_ext.rb
79
+ - test/lib/named_scope.rb
80
+ - test/lib/named_scope/core_ext.rb
81
+ - test/lib/named_scope/named_scope.rb
82
+ - test/lib/named_scope/named_scope_patch_1.2.rb
83
+ - test/lib/named_scope/named_scope_patch_2.0.rb
84
+ - test/lib/test_case.rb