cohort_scope 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -10,8 +10,8 @@ begin
10
10
  gem.email = "seamus@abshere.net"
11
11
  gem.homepage = "http://github.com/seamusabshere/cohort_scope"
12
12
  gem.authors = ["Seamus Abshere", "Andy Rossmeissl", "Derek Kastner"]
13
- gem.add_dependency "activesupport", ">=3.0.0.beta2"
14
- gem.add_dependency "activerecord", ">=3.0.0.beta2"
13
+ gem.add_dependency "activesupport", ">=3.0.0.beta4"
14
+ gem.add_dependency "activerecord", ">=3.0.0.beta4"
15
15
  gem.add_development_dependency "shoulda", ">= 2.10.3"
16
16
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
17
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
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.0.5"
8
+ s.version = "0.0.6"
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-07-13}
12
+ s.date = %q{2010-07-29}
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 = [
@@ -43,17 +43,17 @@ Gem::Specification.new do |s|
43
43
  s.specification_version = 3
44
44
 
45
45
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
- s.add_runtime_dependency(%q<activesupport>, [">= 3.0.0.beta2"])
47
- s.add_runtime_dependency(%q<activerecord>, [">= 3.0.0.beta2"])
46
+ s.add_runtime_dependency(%q<activesupport>, [">= 3.0.0.beta4"])
47
+ s.add_runtime_dependency(%q<activerecord>, [">= 3.0.0.beta4"])
48
48
  s.add_development_dependency(%q<shoulda>, [">= 2.10.3"])
49
49
  else
50
- s.add_dependency(%q<activesupport>, [">= 3.0.0.beta2"])
51
- s.add_dependency(%q<activerecord>, [">= 3.0.0.beta2"])
50
+ s.add_dependency(%q<activesupport>, [">= 3.0.0.beta4"])
51
+ s.add_dependency(%q<activerecord>, [">= 3.0.0.beta4"])
52
52
  s.add_dependency(%q<shoulda>, [">= 2.10.3"])
53
53
  end
54
54
  else
55
- s.add_dependency(%q<activesupport>, [">= 3.0.0.beta2"])
56
- s.add_dependency(%q<activerecord>, [">= 3.0.0.beta2"])
55
+ s.add_dependency(%q<activesupport>, [">= 3.0.0.beta4"])
56
+ s.add_dependency(%q<activerecord>, [">= 3.0.0.beta4"])
57
57
  s.add_dependency(%q<shoulda>, [">= 2.10.3"])
58
58
  end
59
59
  end
data/lib/cohort_scope.rb CHANGED
@@ -10,25 +10,23 @@ end if ActiveSupport::VERSION::MAJOR == 3
10
10
  module ActiveRecord
11
11
  class Relation
12
12
  def inspect_count_only!
13
- @_inspect_count_only = true
13
+ @inspect_count_only = true
14
14
  end
15
15
  def inspect_count_only?
16
- @_inspect_count_only == true
16
+ @inspect_count_only == true
17
17
  end
18
- def as_json(*args)
19
- inspect_count_only? ? { :members => count }.as_json : to_a.as_json
18
+ def as_json(*)
19
+ inspect_count_only? ? { :members => count } : super
20
20
  end
21
21
  def inspect
22
- inspect_count_only? ? "<Massive ActiveRecord scope with #{count} members>" : to_a.inspect
22
+ inspect_count_only? ? "<Massive ActiveRecord scope with #{count} members>" : super
23
23
  end
24
24
  end
25
25
  end
26
26
 
27
27
  module CohortScope
28
- def self.extended(base)
29
- base.class_eval do
30
- cattr_accessor :minimum_cohort_size, :instance_writer => false
31
- end
28
+ def self.extended(klass)
29
+ klass.cattr_accessor :minimum_cohort_size, :instance_writer => false
32
30
  end
33
31
 
34
32
  # Find the biggest scope possible by removing constraints <b>in any order</b>.
@@ -66,7 +64,9 @@ module CohortScope
66
64
  raise RuntimeError, "You need to set #{name}.minimum_cohort_size = X" unless minimum_cohort_size.present?
67
65
 
68
66
  if constraints.values.none? # failing base case
69
- return scoped.where(false)
67
+ empty_cohort = scoped.where 'false'
68
+ empty_cohort.inspect_count_only!
69
+ return empty_cohort
70
70
  end
71
71
 
72
72
  this_hash = _cohort_constraints constraints
@@ -6,11 +6,19 @@ 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 "not raise on to_json" do
9
+ should "only show the count in the json representation" do
10
10
  cohort = Citizen.big_cohort :birthdate => @date_range, :favorite_color => 'heliotrope'
11
- assert_nothing_raised do
12
- cohort.to_json
13
- end
11
+ assert_equal({ :members => 9 }.to_json, cohort.to_json)
12
+ end
13
+
14
+ should "not mess with normal as_json" do
15
+ non_cohort = Citizen.all
16
+ assert_equal non_cohort.to_a.as_json, non_cohort.as_json
17
+ end
18
+
19
+ should "not mess with normal inspect" do
20
+ non_cohort = Citizen.all
21
+ assert_equal non_cohort.to_a.inspect, non_cohort.inspect
14
22
  end
15
23
 
16
24
  should "inspect to a short string" do
@@ -51,6 +59,11 @@ class TestCohortScope < Test::Unit::TestCase
51
59
  Citizen.big_cohort ActiveSupport::OrderedHash.new
52
60
  }
53
61
  end
62
+
63
+ should "result in a relation that has inspect_count_only set" do
64
+ cohort = Citizen.big_cohort :favorite_color => 'heliotrope'
65
+ assert cohort.inspect_count_only?
66
+ end
54
67
  end
55
68
 
56
69
  context "strict_cohort" do
@@ -91,5 +104,13 @@ class TestCohortScope < Test::Unit::TestCase
91
104
  cohort = Citizen.strict_cohort birthdate_matters_most
92
105
  assert_equal 9, cohort.count
93
106
  end
107
+
108
+ should "result in a relation that has inspect_count_only set" do
109
+ ordered_attributes = ActiveSupport::OrderedHash.new
110
+ ordered_attributes[:favorite_color] = 'heliotrope'
111
+
112
+ cohort = Citizen.strict_cohort ordered_attributes
113
+ assert cohort.inspect_count_only?
114
+ end
94
115
  end
95
116
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cohort_scope
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Seamus Abshere
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-07-13 00:00:00 -04:00
20
+ date: 2010-07-29 00:00:00 -05:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -28,13 +28,13 @@ dependencies:
28
28
  requirements:
29
29
  - - ">="
30
30
  - !ruby/object:Gem::Version
31
- hash: -1848230022
31
+ hash: 299253624
32
32
  segments:
33
33
  - 3
34
34
  - 0
35
35
  - 0
36
- - beta2
37
- version: 3.0.0.beta2
36
+ - beta4
37
+ version: 3.0.0.beta4
38
38
  type: :runtime
39
39
  version_requirements: *id001
40
40
  - !ruby/object:Gem::Dependency
@@ -45,13 +45,13 @@ dependencies:
45
45
  requirements:
46
46
  - - ">="
47
47
  - !ruby/object:Gem::Version
48
- hash: -1848230022
48
+ hash: 299253624
49
49
  segments:
50
50
  - 3
51
51
  - 0
52
52
  - 0
53
- - beta2
54
- version: 3.0.0.beta2
53
+ - beta4
54
+ version: 3.0.0.beta4
55
55
  type: :runtime
56
56
  version_requirements: *id002
57
57
  - !ruby/object:Gem::Dependency