census 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.3.0
@@ -0,0 +1,16 @@
1
+ module Census
2
+ class Search
3
+ def initialize(options)
4
+ @options = options
5
+ end
6
+
7
+ def perform
8
+ results = []
9
+ @options.each_pair do |question, value|
10
+ users = question.find_answers_matching(value).map(&:user)
11
+ results = results.empty? ? users : results & users
12
+ end
13
+ results
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,39 @@
1
+ require 'test_helper'
2
+
3
+ class SearchTest < ActiveSupport::TestCase
4
+
5
+ context "Performing a search" do
6
+
7
+ setup do
8
+ @question1 = Factory(:question, :prompt => 'Hair Color')
9
+ @question2 = Factory(:question, :prompt => 'Weight')
10
+
11
+ @matching_user = Factory(:user)
12
+ Factory(:answer, :user => @matching_user, :question => @question1, :data => 'Brown')
13
+ Factory(:answer, :user => @matching_user, :question => @question2, :data => '150')
14
+
15
+ @partial_match_user = Factory(:user)
16
+ Factory(:answer, :user => @partial_match_user, :question => @question1, :data => 'Black')
17
+ Factory(:answer, :user => @partial_match_user, :question => @question2, :data => '160')
18
+
19
+ @non_matching_user = Factory(:user)
20
+ Factory(:answer, :user => @non_matching_user, :question => @question1, :data => 'Blond')
21
+ Factory(:answer, :user => @non_matching_user, :question => @question2, :data => '200')
22
+
23
+ @search = Census::Search.new(@question1 => 'Brown', @question2 => 145..165)
24
+ end
25
+
26
+ should "find the matching user" do
27
+ results = @search.perform
28
+ assert results.include?(@matching_user)
29
+ end
30
+
31
+ should "not find the other users" do
32
+ results = @search.perform
33
+ assert !results.include?(@non_matching_user)
34
+ assert !results.include?(@partial_match_user)
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -9,7 +9,7 @@
9
9
  #
10
10
  # It's strongly recommended to check this file into your version control system.
11
11
 
12
- ActiveRecord::Schema.define(:version => 20100406184714) do
12
+ ActiveRecord::Schema.define(:version => 20100408132452) do
13
13
 
14
14
  create_table "answers", :force => true do |t|
15
15
  t.integer "question_id"
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
8
- - 1
9
- version: 0.2.1
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mark Kendall
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-06 00:00:00 -04:00
17
+ date: 2010-04-08 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -112,6 +112,7 @@ files:
112
112
  - generators/census/templates/user.rb
113
113
  - lib/census.rb
114
114
  - lib/census/data_type.rb
115
+ - lib/census/search.rb
115
116
  - lib/census/user.rb
116
117
  - rails/init.rb
117
118
  - shoulda_macros/census.rb
@@ -151,6 +152,7 @@ test_files:
151
152
  - test/models/choice_test.rb
152
153
  - test/models/data_group_test.rb
153
154
  - test/models/question_test.rb
155
+ - test/models/search_test.rb
154
156
  - test/models/user_test.rb
155
157
  - test/rails_root/app/controllers/application_controller.rb
156
158
  - test/rails_root/app/helpers/application_helper.rb
@@ -167,7 +169,7 @@ test_files:
167
169
  - test/rails_root/config/initializers/new_rails_defaults.rb
168
170
  - test/rails_root/config/initializers/session_store.rb
169
171
  - test/rails_root/config/routes.rb
170
- - test/rails_root/db/migrate/20100406184714_create_census_tables.rb
172
+ - test/rails_root/db/migrate/20100408132452_create_census_tables.rb
171
173
  - test/rails_root/db/schema.rb
172
174
  - test/rails_root/test/factories/census.rb
173
175
  - test/rails_root/test/performance/browsing_test.rb