cohort_scope 0.1.1 → 0.1.2

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
data/cohort_scope.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cohort_scope}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Seamus Abshere", "Andy Rossmeissl", "Derek Kastner"]
12
- s.date = %q{2010-10-29}
12
+ s.date = %q{2011-02-01}
13
13
  s.description = %q{Provides big_cohort, which widens by finding the constraint that eliminates the most records and removing it. Also provides strict_cohort, which widens by eliminating constraints in order.}
14
14
  s.email = %q{seamus@abshere.net}
15
15
  s.extra_rdoc_files = [
@@ -38,9 +38,9 @@ Gem::Specification.new do |s|
38
38
  s.rubygems_version = %q{1.3.7}
39
39
  s.summary = %q{Provides cohorts (in the form of ActiveRecord scopes) that dynamically widen until they contain a certain number of records.}
40
40
  s.test_files = [
41
- "test/test_cohort.rb",
42
- "test/test_cohort_scope.rb",
43
- "test/helper.rb"
41
+ "test/helper.rb",
42
+ "test/test_cohort.rb",
43
+ "test/test_cohort_scope.rb"
44
44
  ]
45
45
 
46
46
  if s.respond_to? :specification_version then
@@ -50,16 +50,16 @@ module CohortScope
50
50
  #
51
51
  # For example, :car => <#Car> might get translated into :car_id => 44 or :car_type => 44 if :foreign_key option is given.
52
52
  def association_foreign_key(model, name)
53
- @_cohort_association_foreign_keys ||= {}
54
- return @_cohort_association_foreign_keys[name] if @_cohort_association_foreign_keys.has_key? name
53
+ @association_foreign_key ||= {}
54
+ return @association_foreign_key[name] if @association_foreign_key.has_key? name
55
55
  association = model.reflect_on_association name
56
56
  raise "there is no association #{name.inspect} on #{model}" if association.nil?
57
57
  raise "can't use cohort scope on :through associations (#{self.name} #{name})" if association.options.has_key? :through
58
58
  foreign_key = association.instance_variable_get(:@options)[:foreign_key]
59
59
  if !foreign_key.blank?
60
- @_cohort_association_foreign_keys[name] = foreign_key
60
+ @association_foreign_key[name] = foreign_key
61
61
  else
62
- @_cohort_association_foreign_keys[name] = association.primary_key_name
62
+ @association_foreign_key[name] = association.primary_key_name
63
63
  end
64
64
  end
65
65
 
@@ -80,14 +80,25 @@ module CohortScope
80
80
  end
81
81
 
82
82
  def initialize(obj)
83
+ super
83
84
  @_ch_obj = obj
84
85
  end
85
86
  def __getobj__
86
87
  @_ch_obj
87
88
  end
88
89
 
89
- def as_json(*)
90
- { :members => count }
90
+ # sabshere 2/1/11 overriding as_json per usual doesn't seem to work
91
+ def to_json(*)
92
+ { :members => count }.to_json
93
+ end
94
+
95
+ # sabshere 2/1/11 ActiveRecord does this for #any? but not for #none?
96
+ def none?(&blk)
97
+ if block_given?
98
+ to_a.none? &blk
99
+ else
100
+ super
101
+ end
91
102
  end
92
103
 
93
104
  def inspect
@@ -6,6 +6,25 @@ class TestCohortScope < Test::Unit::TestCase
6
6
  @date_range = (Date.parse('1980-01-01')..Date.parse('1990-01-01'))
7
7
  end
8
8
 
9
+ should "properly use blocks" do
10
+ cohort = Citizen.big_cohort(:birthdate => @date_range)
11
+ assert cohort.all? { |c| true }
12
+ assert cohort.any? { |c| true }
13
+ assert !cohort.none? { |c| true }
14
+ end
15
+
16
+ should "actually run blocks" do
17
+ assert_raises(RuntimeError, 'A') do
18
+ Citizen.big_cohort(:birthdate => @date_range).all? { |c| raise 'A' }
19
+ end
20
+ assert_raises(RuntimeError, 'B') do
21
+ Citizen.big_cohort(:birthdate => @date_range).any? { |c| raise 'B' }
22
+ end
23
+ assert_raises(RuntimeError, 'C') do
24
+ Citizen.big_cohort(:birthdate => @date_range).none? { |c| raise 'C' }
25
+ end
26
+ end
27
+
9
28
  should "only show the count in the json representation" do
10
29
  cohort = Citizen.big_cohort :birthdate => @date_range, :favorite_color => 'heliotrope'
11
30
  assert_equal({ :members => 9 }.to_json, cohort.to_json)
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cohort_scope
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 31
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 1
8
- - 1
9
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
10
11
  platform: ruby
11
12
  authors:
12
13
  - Seamus Abshere
@@ -16,7 +17,7 @@ autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
18
19
 
19
- date: 2010-10-29 00:00:00 -04:00
20
+ date: 2011-02-01 00:00:00 -06:00
20
21
  default_executable:
21
22
  dependencies:
22
23
  - !ruby/object:Gem::Dependency
@@ -27,6 +28,7 @@ dependencies:
27
28
  requirements:
28
29
  - - ">="
29
30
  - !ruby/object:Gem::Version
31
+ hash: 299253624
30
32
  segments:
31
33
  - 3
32
34
  - 0
@@ -43,6 +45,7 @@ dependencies:
43
45
  requirements:
44
46
  - - ">="
45
47
  - !ruby/object:Gem::Version
48
+ hash: 299253624
46
49
  segments:
47
50
  - 3
48
51
  - 0
@@ -59,6 +62,7 @@ dependencies:
59
62
  requirements:
60
63
  - - ">="
61
64
  - !ruby/object:Gem::Version
65
+ hash: 33
62
66
  segments:
63
67
  - 2
64
68
  - 10
@@ -74,6 +78,7 @@ dependencies:
74
78
  requirements:
75
79
  - - ">="
76
80
  - !ruby/object:Gem::Version
81
+ hash: 3
77
82
  segments:
78
83
  - 0
79
84
  version: "0"
@@ -117,6 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
117
122
  requirements:
118
123
  - - ">="
119
124
  - !ruby/object:Gem::Version
125
+ hash: 3
120
126
  segments:
121
127
  - 0
122
128
  version: "0"
@@ -125,6 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
131
  requirements:
126
132
  - - ">="
127
133
  - !ruby/object:Gem::Version
134
+ hash: 3
128
135
  segments:
129
136
  - 0
130
137
  version: "0"
@@ -136,6 +143,6 @@ signing_key:
136
143
  specification_version: 3
137
144
  summary: Provides cohorts (in the form of ActiveRecord scopes) that dynamically widen until they contain a certain number of records.
138
145
  test_files:
146
+ - test/helper.rb
139
147
  - test/test_cohort.rb
140
148
  - test/test_cohort_scope.rb
141
- - test/helper.rb