ohio_state_person 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,6 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ .project
6
+ *.swp
7
+ spec/debug.log
data/.rvmrc ADDED
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
7
+ environment_id="ree@ohio_state_person"
8
+
9
+ #
10
+ # Uncomment the following lines if you want to verify rvm version per project
11
+ #
12
+ # rvmrc_rvm_version="1.10.2" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+ #
18
+
19
+ #
20
+ # Uncomment following line if you want options to be set only for given project.
21
+ #
22
+ # PROJECT_JRUBY_OPTS=( --1.9 )
23
+ #
24
+ # The variable PROJECT_JRUBY_OPTS requires the following to be run in shell:
25
+ #
26
+ # chmod +x ${rvm_path}/hooks/after_use_jruby_opts
27
+ #
28
+
29
+ #
30
+ # First we attempt to load the desired environment directly from the environment
31
+ # file. This is very fast and efficient compared to running through the entire
32
+ # CLI and selector. If you want feedback on which environment was used then
33
+ # insert the word 'use' after --create as this triggers verbose mode.
34
+ #
35
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
36
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
37
+ then
38
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
39
+
40
+ if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
41
+ then
42
+ . "${rvm_path:-$HOME/.rvm}/hooks/after_use"
43
+ fi
44
+ else
45
+ # If the environment file has not yet been created, use the RVM CLI to select.
46
+ if ! rvm --create use "$environment_id"
47
+ then
48
+ echo "Failed to create RVM environment '${environment_id}'."
49
+ return 1
50
+ fi
51
+ fi
52
+
53
+ #
54
+ # If you use an RVM gemset file to install a list of gems (*.gems), you can have
55
+ # it be automatically loaded. Uncomment the following and adjust the filename if
56
+ # necessary.
57
+ #
58
+ # filename=".gems"
59
+ # if [[ -s "$filename" ]]
60
+ # then
61
+ # rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
62
+ # fi
63
+
64
+ # If you use bundler, this might be useful to you:
65
+ # if [[ -s Gemfile ]] && ! command -v bundle >/dev/null
66
+ # then
67
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
68
+ # gem install bundler
69
+ # fi
70
+ # if [[ -s Gemfile ]] && command -v bundle
71
+ # then
72
+ # bundle install
73
+ # fi
74
+
75
+ if [[ $- == *i* ]] # check for interactive shells
76
+ then
77
+ echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
78
+ else
79
+ echo "Using: $GEM_HOME" # don't use colors in interactive shells
80
+ fi
81
+
data/Rakefile CHANGED
@@ -1 +1,5 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new('spec')
4
+
5
+ task :default => :spec
@@ -1,3 +1,3 @@
1
1
  module OhioStatePerson
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -21,15 +21,20 @@ module OhioStatePerson
21
21
  end
22
22
 
23
23
  module ClassMethods
24
- def search(q)
25
- q = q.to_s.strip
24
+ def search(q, options={})
25
+ q = q.to_s
26
26
  h = ActiveSupport::OrderedHash.new
27
- h[/\A\d+\z/] = lambda { where(:emplid => q) }
28
- h[/\A\D+\.\d+\z/] = lambda { where(:name_n => q) } if column_names.include? 'name_n'
29
- h[/(\S+),\s*(\S+)/] = lambda { where('last_name LIKE ? AND first_name LIKE ?', $1, "#{$2}%") }
30
- h[/(\S+)\s+(\S+)/] = lambda { where('first_name LIKE ? AND last_name LIKE ?', $1, "#{$2}%") }
31
- h[/\S/] = lambda { where('last_name LIKE ?', "#{q}%") }
32
- h[//] = lambda { where('1=2') }
27
+ if options[:fuzzy]
28
+ h[/\A\s*\d+\s*\z/] = lambda { where('emplid LIKE ?', "#{q.strip}%") }
29
+ h[/\A\s*\D+\.\d*\s*\z/] = lambda { where('name_n LIKE ?', "#{q.strip}%") } if column_names.include? 'name_n'
30
+ else
31
+ h[/\A\s*\d+\s*\z/] = lambda { where(:emplid => q.strip) }
32
+ h[/\A\s*\D+\.\d*\s*\z/] = lambda { where(:name_n => q.strip) } if column_names.include? 'name_n'
33
+ end
34
+ h[/(\S+),\s*(\S*)/] = lambda { where('last_name LIKE ? AND first_name LIKE ?', $1, "#{$2}%") }
35
+ h[/(\S+)\s+(\S*)/] = lambda { where('first_name LIKE ? AND last_name LIKE ?', $1, "#{$2}%") }
36
+ h[/\S/] = lambda { where('last_name LIKE ?', "#{q}%") }
37
+ h[//] = lambda { where('1=2') }
33
38
 
34
39
  h.each do |regex, where_clause|
35
40
  return where_clause.call if q =~ regex
@@ -18,8 +18,12 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
- # specify any dependencies here; for example:
22
- # s.add_development_dependency "rspec"
23
- # s.add_runtime_dependency "rest-client"
24
21
  s.add_runtime_dependency "activerecord", '~> 3.0'
22
+
23
+ s.add_development_dependency "rake"
24
+ s.add_development_dependency "rspec"
25
+ s.add_development_dependency "activesupport", '~> 3.0'
26
+ s.add_development_dependency "sqlite3"
27
+ s.add_development_dependency "shoulda-matchers"
28
+ s.add_development_dependency "factory_girl"
25
29
  end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'callbacks' do
4
+ let(:student) { create :student, :emplid => 87654321 }
5
+
6
+ it 'should set id to emplid.to_i' do
7
+ student.id.should == 87654321
8
+ end
9
+ end
data/spec/database.yml ADDED
@@ -0,0 +1,4 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: ":memory:"
4
+
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'email helper method' do
4
+
5
+ context 'a model with neither email nor name_n fileds' do
6
+ subject { build :luddite }
7
+ its(:email) { should be_nil }
8
+ end
9
+
10
+ context 'a model with an email field' do
11
+ subject { build :applicant, :email => 'email@address' }
12
+ its(:email) { should == 'email@address' }
13
+ end
14
+
15
+ context 'a model with a name_n field' do
16
+ subject { build :student, :name_n => 'student.1' }
17
+ its(:email) { should == 'student.1@osu.edu' }
18
+ end
19
+ end
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'the search method' do
4
+
5
+ before(:all) do
6
+ Student.delete_all
7
+ @student = create :student,
8
+ :first_name => 'Brutus',
9
+ :last_name => 'Buckeye',
10
+ :name_n => 'buckeye.11',
11
+ :emplid => '18181818'
12
+ end
13
+
14
+ it "should return no results given a blank search" do
15
+ Student.search(nil).should == []
16
+ Student.search('').should == []
17
+ end
18
+
19
+ it "should return exact matches on emplid" do
20
+ Student.search(18181818).should == [@student]
21
+ Student.search(1818).should == []
22
+ end
23
+
24
+ it "should return exact matches on name_n" do
25
+ Student.search('buckeye.11').should == [@student]
26
+ Student.search('buckeye.1').should == []
27
+ end
28
+
29
+ it "should return fuzzy matches on emplid" do
30
+ Student.search(18181818, :fuzzy => true).should == [@student]
31
+ Student.search(1818, :fuzzy => true).should == [@student]
32
+ end
33
+
34
+ it "should return fuzzy matches on name_n" do
35
+ Student.search('buckeye.11', :fuzzy => true).should == [@student]
36
+ Student.search('buckeye.1', :fuzzy => true).should == [@student]
37
+ end
38
+
39
+ it "should not give results on first name only" do
40
+ Student.search('Brutus').should == []
41
+ Student.search('Brut').should == []
42
+ end
43
+
44
+ it "should give results on last name only" do
45
+ Student.search('Buckeye').should == [@student]
46
+ Student.search('Buck').should == [@student]
47
+ end
48
+
49
+ it "should give results for full name" do
50
+ Student.search('Brutus Buckeye').should == [@student]
51
+ Student.search('Brutus Bu').should == [@student]
52
+ end
53
+
54
+ it "should ignore case" do
55
+ Student.search('BUCKEYE').should == [@student]
56
+ Student.search('buckeye').should == [@student]
57
+ end
58
+
59
+ it "should return multiple results sorted by name_n" do
60
+ other_buckeye = create :student,
61
+ :first_name => 'Derpina',
62
+ :last_name => 'Buckeye',
63
+ :name_n => 'buckeye.99'
64
+ Student.search('buckeye').order('name_n').should == [@student, other_buckeye]
65
+ other_buckeye.destroy
66
+ end
67
+
68
+ it "should match on last name, first name" do
69
+ Student.search('Buckeye, Brutus').should == [@student]
70
+ end
71
+
72
+ it "should ignore case on last name, first name" do
73
+ Student.search('BUCKEYE, BRUTUS').should == [@student]
74
+ end
75
+
76
+ it "should partially match on last name, first name" do
77
+ Student.search('Buckeye, Brut').should == [@student]
78
+ end
79
+
80
+ it "should ignore beginning and trailing whitespace" do
81
+ Student.search('18181818 ').should == [@student]
82
+ Student.search(' 18181818').should == [@student]
83
+ end
84
+
85
+ end
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'rspec'
4
+ require 'active_record'
5
+ require 'active_support'
6
+ require 'ohio_state_person'
7
+ require 'shoulda-matchers'
8
+ require 'factory_girl'
9
+
10
+ ActiveRecord::Base.logger = ActiveSupport::BufferedLogger.new(File.dirname(__FILE__) + "/debug.log")
11
+
12
+ config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
13
+ ActiveRecord::Base.establish_connection(config['test'])
14
+
15
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
16
+
17
+ RSpec.configure do |config|
18
+ config.include FactoryGirl::Syntax::Methods
19
+ config.color_enabled = true
20
+ end
@@ -0,0 +1,27 @@
1
+ FactoryGirl.define do
2
+ sequence :emplid do |n|
3
+ '%08d' % n
4
+ end
5
+ sequence :name_n do |n|
6
+ "buckeye.#{n}"
7
+ end
8
+
9
+ factory :student do
10
+ first_name 'Brutus'
11
+ last_name 'Buckeye'
12
+ name_n
13
+ emplid
14
+ end
15
+
16
+ factory :applicant do
17
+ first_name 'Brutus'
18
+ last_name 'Buckeye'
19
+ email 'brutus_buckeye@gmail.com'
20
+ emplid
21
+ end
22
+
23
+ factory :luddite do
24
+ first_name 'Some'
25
+ last_name 'Guy'
26
+ end
27
+ end
@@ -0,0 +1,10 @@
1
+ ActiveRecord::Base.connection.create_table :applicants, :force => true do |table|
2
+ table.column :emplid, :string
3
+ table.column :email, :string
4
+ table.column :first_name, :string
5
+ table.column :last_name, :string
6
+ end
7
+
8
+ class Applicant < ActiveRecord::Base
9
+ is_a_buckeye
10
+ end
@@ -0,0 +1,8 @@
1
+ ActiveRecord::Base.connection.create_table :luddites, :force => true do |table|
2
+ table.column :first_name, :string
3
+ table.column :last_name, :string
4
+ end
5
+
6
+ class Luddite < ActiveRecord::Base
7
+ is_a_buckeye
8
+ end
@@ -0,0 +1,10 @@
1
+ ActiveRecord::Base.connection.create_table :students, :force => true do |table|
2
+ table.column :emplid, :string
3
+ table.column :name_n, :string
4
+ table.column :first_name, :string
5
+ table.column :last_name, :string
6
+ end
7
+
8
+ class Student < ActiveRecord::Base
9
+ is_a_buckeye
10
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'validations' do
4
+
5
+ specify { build(:student).should be_valid }
6
+ specify { build(:applicant).should be_valid }
7
+
8
+ let(:student) { create :student }
9
+ let(:applicant) { create :applicant }
10
+
11
+ describe 'the name_n field' do
12
+ subject { student }
13
+
14
+ it { should validate_uniqueness_of :name_n }
15
+ it { should validate_format_of(:name_n).not_with('gee2').
16
+ with_message(/must be in format: name.#/) }
17
+ it { should validate_format_of(:name_n).with('gee.2').
18
+ with_message(/must be in format: name.#/) }
19
+ end
20
+
21
+ describe 'the emplid field' do
22
+ subject { applicant }
23
+
24
+ it { should validate_uniqueness_of :emplid }
25
+ it { should validate_format_of(:emplid).not_with('54321').
26
+ with_message(/must be 8 or 9 digits/) }
27
+ it { should validate_format_of(:emplid).with('987654321').
28
+ with_message(/must be 8 or 9 digits/) }
29
+ end
30
+
31
+ describe 'the id field' do
32
+ subject { student }
33
+
34
+ specify { subject.id.should == subject.emplid.to_i }
35
+
36
+ context 'with a different emplid' do
37
+ before { subject.emplid = subject.id + 1 }
38
+ specify do
39
+ subject.should_not be_valid
40
+ subject.errors[:id].should == ['must be the same as the emplid']
41
+ end
42
+ end
43
+ end
44
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ohio_state_person
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - mikegee
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-02-06 00:00:00 Z
18
+ date: 2012-02-20 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: activerecord
@@ -32,6 +32,91 @@ dependencies:
32
32
  version: "3.0"
33
33
  type: :runtime
34
34
  version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rake
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: rspec
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :development
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: activesupport
65
+ prerelease: false
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ~>
70
+ - !ruby/object:Gem::Version
71
+ hash: 7
72
+ segments:
73
+ - 3
74
+ - 0
75
+ version: "3.0"
76
+ type: :development
77
+ version_requirements: *id004
78
+ - !ruby/object:Gem::Dependency
79
+ name: sqlite3
80
+ prerelease: false
81
+ requirement: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ type: :development
91
+ version_requirements: *id005
92
+ - !ruby/object:Gem::Dependency
93
+ name: shoulda-matchers
94
+ prerelease: false
95
+ requirement: &id006 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ type: :development
105
+ version_requirements: *id006
106
+ - !ruby/object:Gem::Dependency
107
+ name: factory_girl
108
+ prerelease: false
109
+ requirement: &id007 !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ type: :development
119
+ version_requirements: *id007
35
120
  description: "requires fields: name_n, emplid; sets id to emplid.to_i; provides a search method; etc."
36
121
  email:
37
122
  - gee.24@osu.edu
@@ -43,12 +128,23 @@ extra_rdoc_files: []
43
128
 
44
129
  files:
45
130
  - .gitignore
131
+ - .rvmrc
46
132
  - Gemfile
47
133
  - README.md
48
134
  - Rakefile
49
135
  - lib/ohio_state_person.rb
50
136
  - lib/ohio_state_person/version.rb
51
137
  - ohio_state_person.gemspec
138
+ - spec/callbacks_spec.rb
139
+ - spec/database.yml
140
+ - spec/email_helper_spec.rb
141
+ - spec/search_spec.rb
142
+ - spec/spec_helper.rb
143
+ - spec/support/factories.rb
144
+ - spec/support/models/applicant.rb
145
+ - spec/support/models/luddite.rb
146
+ - spec/support/models/student.rb
147
+ - spec/validations_spec.rb
52
148
  homepage: https://github.com/ASCTech/ohio_state_person
53
149
  licenses: []
54
150
 
@@ -82,5 +178,14 @@ rubygems_version: 1.8.15
82
178
  signing_key:
83
179
  specification_version: 3
84
180
  summary: ActiveRecord mixin for people at Ohio State University
85
- test_files: []
86
-
181
+ test_files:
182
+ - spec/callbacks_spec.rb
183
+ - spec/database.yml
184
+ - spec/email_helper_spec.rb
185
+ - spec/search_spec.rb
186
+ - spec/spec_helper.rb
187
+ - spec/support/factories.rb
188
+ - spec/support/models/applicant.rb
189
+ - spec/support/models/luddite.rb
190
+ - spec/support/models/student.rb
191
+ - spec/validations_spec.rb