judge 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -5,4 +5,5 @@ pkg/*
5
5
  docs
6
6
  doc
7
7
  rdoc
8
- gem_graph.png
8
+ gem_graph.png
9
+ .rvmrc
data/.travis.yml CHANGED
@@ -2,7 +2,7 @@ rvm:
2
2
  - 1.9.2
3
3
  - 1.9.3
4
4
 
5
- script: "bundle exec rake test:ruby"
5
+ script: "bundle exec rake spec"
6
6
 
7
7
  notifications:
8
8
  recipients:
data/README.md CHANGED
@@ -6,7 +6,7 @@ Client-side form validation in Rails 3.
6
6
  Usage
7
7
  -----
8
8
 
9
- See http://joecorcoran.github.com/judge for documentation.
9
+ See http://judge.joecorcoran.co.uk for documentation.
10
10
 
11
11
  License
12
12
  -------
data/Rakefile CHANGED
@@ -1,17 +1,11 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "jasmine"
3
- require "rake/testtask"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new("spec")
4
6
 
5
7
  load "jasmine/tasks/jasmine.rake"
6
8
  load "lib/tasks/js_tests.rake"
7
9
 
8
- namespace :test do
9
- Rake::TestTask.new(:ruby) do |test|
10
- test.libs << "lib" << "test"
11
- test.pattern = "test/**/test_*.rb"
12
- test.verbose = true
13
- end
14
- end
15
-
16
10
  desc "Run all tests"
17
- task :test => ["test:ruby", "jasmine:phantom"]
11
+ task :default => ["spec", "jasmine:phantom"]
data/judge.gemspec CHANGED
@@ -16,9 +16,9 @@ Gem::Specification.new do |s|
16
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
17
  s.require_paths = ["lib"]
18
18
 
19
- s.add_development_dependency "jasmine", "~> 1.0.2"
20
- s.add_development_dependency "rails", "~> 3.0.10"
21
- s.add_development_dependency "shoulda", "~> 2.11.3"
22
- s.add_development_dependency "sqlite3-ruby", "~> 1.3.2"
23
- s.add_development_dependency "factory_girl", "~> 2.2.0"
19
+ s.add_development_dependency "jasmine", "~> 1.0.2"
20
+ s.add_development_dependency "rails", "~> 3.0.10"
21
+ s.add_development_dependency "rspec", "~> 2.8.0"
22
+ s.add_development_dependency "sqlite3-ruby", "~> 1.3.2"
23
+ s.add_development_dependency "factory_girl_rails", "~> 1.7.0"
24
24
  end
@@ -1,16 +1,14 @@
1
1
  module Judge
2
2
 
3
3
  class FormBuilder < ActionView::Helpers::FormBuilder
4
-
5
- #include ActionView::Helpers::TagHelper
6
4
 
7
5
  %w{text_field text_area password_field}.each do |type|
8
6
  helper = <<-END
9
7
  def #{type}(method, options = {})
10
8
  if options.delete(:validate).present?
11
- options = { "data-validate" => Judge::ValidatorCollection.new(self.object, method).to_json }.merge(options)
9
+ options = Judge::HTML.attrs_for(self.object, method).merge(options)
12
10
  end
13
- @template.#{type}(self.object_name, method, options)
11
+ super
14
12
  end
15
13
  END
16
14
  class_eval helper, __FILE__, __LINE__
@@ -18,46 +16,46 @@ module Judge
18
16
 
19
17
  def radio_button(method, tag_value, options = {})
20
18
  if options.delete(:validate).present?
21
- options = { "data-validate" => Judge::ValidatorCollection.new(self.object, method).to_json }.merge(options)
19
+ options = Judge::HTML.attrs_for(self.object, method).merge(options)
22
20
  end
23
- @template.radio_button(@object_name, method, tag_value, objectify_options(options))
21
+ super
24
22
  end
25
23
 
26
24
  def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
27
25
  if options.delete(:validate).present?
28
- options = { "data-validate" => Judge::ValidatorCollection.new(self.object, method).to_json }.merge(options)
26
+ options = Judge::HTML.attrs_for(self.object, method).merge(options)
29
27
  end
30
- @template.check_box(self.object_name, method, objectify_options(options), checked_value, unchecked_value)
28
+ super
31
29
  end
32
30
 
33
31
  def select(method, choices, options = {}, html_options = {})
34
32
  if options.delete(:validate).present?
35
- html_options = { "data-validate" => Judge::ValidatorCollection.new(self.object, method).to_json }.merge(html_options)
33
+ html_options = Judge::HTML.attrs_for(self.object, method).merge(html_options)
36
34
  end
37
- @template.select(self.object_name, method, choices, objectify_options(options), @default_options.merge(html_options))
35
+ super
38
36
  end
39
37
 
40
38
  def collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
41
39
  if options.delete(:validate).present?
42
- html_options = { "data-validate" => Judge::ValidatorCollection.new(self.object, method).to_json }.merge(html_options)
40
+ html_options = Judge::HTML.attrs_for(self.object, method).merge(html_options)
43
41
  end
44
- @template.collection_select(self.object_name, method, collection, value_method, text_method, objectify_options(options), @default_options.merge(html_options))
42
+ super
45
43
  end
46
44
 
47
45
  def grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {})
48
46
  if options.delete(:validate).present?
49
- html_options = { "data-validate" => Judge::ValidatorCollection.new(self.object, method).to_json }.merge(html_options)
47
+ html_options = Judge::HTML.attrs_for(self.object, method).merge(html_options)
50
48
  end
51
- @template.grouped_collection_select(self.object_name, method, collection, group_method, group_label_method, option_key_method, option_value_method, objectify_options(options), @default_options.merge(html_options))
49
+ super
52
50
  end
53
51
 
54
52
  %w{date_select datetime_select time_select}.each do |type|
55
53
  helper = <<-END
56
54
  def #{type}(method, options = {}, html_options = {})
57
55
  if options.delete(:validate).present?
58
- html_options = { "data-validate" => Judge::ValidatorCollection.new(self.object, method).to_json }.merge(html_options)
56
+ html_options = Judge::HTML.attrs_for(self.object, method).merge(html_options)
59
57
  end
60
- @template.#{type}(self.object_name, method, objectify_options(options), html_options)
58
+ super
61
59
  end
62
60
  END
63
61
  class_eval helper, __FILE__, __LINE__
@@ -65,9 +63,9 @@ module Judge
65
63
 
66
64
  def time_zone_select(method, priority_zones = nil, options = {}, html_options = {})
67
65
  if options.delete(:validate).present?
68
- html_options = { "data-validate" => Judge::ValidatorCollection.new(self.object, method).to_json }.merge(html_options)
66
+ html_options = Judge::HTML.attrs_for(self.object, method).merge(html_options)
69
67
  end
70
- @template.time_zone_select(@object_name, method, priority_zones, objectify_options(options), @default_options.merge(html_options))
68
+ super
71
69
  end
72
70
 
73
71
  end
data/lib/judge/html.rb ADDED
@@ -0,0 +1,13 @@
1
+ module Judge
2
+
3
+ module HTML
4
+
5
+ extend self
6
+
7
+ def attrs_for(object, method)
8
+ { "data-validate" => Judge::ValidatorCollection.new(object, method).to_json }
9
+ end
10
+
11
+ end
12
+
13
+ end
@@ -13,9 +13,9 @@ module Judge
13
13
  end
14
14
  end
15
15
 
16
- def each
16
+ def each(&block)
17
17
  validators.each do |v|
18
- yield v
18
+ block.call(v)
19
19
  end
20
20
  end
21
21
 
data/lib/judge/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Judge
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/judge.rb CHANGED
@@ -3,4 +3,5 @@ require "version"
3
3
  require "validator"
4
4
  require "validator_collection"
5
5
  require "message_collection"
6
- require "form_builder"
6
+ require "form_builder"
7
+ require "html"
File without changes
@@ -0,0 +1,68 @@
1
+ require "spec_helper"
2
+
3
+ describe Judge::FormBuilder do
4
+
5
+ let(:builder) { Judge::FormBuilder.new(:user, FactoryGirl.build(:user), ActionView::Base.new, {}, nil) }
6
+ let(:categories) do
7
+ category = FactoryGirl.build(:category)
8
+ sport = FactoryGirl.build(:sport)
9
+ sport.disciplines << FactoryGirl.build_list(:discipline, 3)
10
+ category.sports << sport
11
+ [category]
12
+ end
13
+ let(:expected) do
14
+ /data\-validate=\"\[.+\]\"/
15
+ end
16
+
17
+ specify "#text_field" do
18
+ builder.text_field(:name, :validate => true).should match expected
19
+ end
20
+
21
+ specify "#text_area" do
22
+ builder.text_area(:bio, :validate => true).should match expected
23
+ end
24
+
25
+ specify "#password_field" do
26
+ builder.password_field(:password, :validate => true).should match expected
27
+ end
28
+
29
+ specify "#check_box" do
30
+ builder.check_box(:accepted, :validate => true).should match expected
31
+ end
32
+
33
+ specify "#radio_button" do
34
+ builder.radio_button(:gender, "female", :validate => true).should match expected
35
+ end
36
+
37
+ specify "#select" do
38
+ builder.select(:country, [["US", "US"], ["GB", "GB"]], :validate => true).should match expected
39
+ end
40
+
41
+ specify "#collection_select" do
42
+ cs = builder.collection_select(:team_id, FactoryGirl.create_list(:team, 5), :id, :name, :validate => true)
43
+ cs.should match expected
44
+ end
45
+
46
+ specify "#grouped_collection_select" do
47
+ gcs = builder.grouped_collection_select(:discipline_id, categories, :sports, :name, :id, :name, :validate => true)
48
+ gcs.should match expected
49
+ end
50
+
51
+ specify "#date_select" do
52
+ builder.date_select(:dob, :validate => true, :minute_step => 30).should match expected
53
+ end
54
+
55
+ specify "#datetime_select" do
56
+ builder.datetime_select(:dob, :validate => true, :minute_step => 30).should match expected
57
+ end
58
+
59
+ specify "#time_select" do
60
+ builder.time_select(:dob, :validate => true, :minute_step => 30).should match expected
61
+ end
62
+
63
+ specify "#time_zone_select" do
64
+ tzs = builder.time_zone_select(:time_zone, ActiveSupport::TimeZone.us_zones, :include_blank => true, :validate => true)
65
+ tzs.should match expected
66
+ end
67
+
68
+ end
data/spec/html_spec.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "spec_helper"
2
+
3
+ describe Judge::HTML do
4
+
5
+ let(:object) { FactoryGirl.build(:user) }
6
+ let(:method) { :name }
7
+
8
+ specify "#attrs_for" do
9
+ attrs = Judge::HTML.attrs_for(object, method)
10
+ attrs.should be_a Hash
11
+ attrs["data-validate"].should be_a String
12
+ end
13
+
14
+ end
@@ -0,0 +1,84 @@
1
+ require "spec_helper"
2
+
3
+ describe Judge::MessageCollection do
4
+
5
+ before(:each) do
6
+ @user = FactoryGirl.build(:user)
7
+ end
8
+
9
+ it "has hash of messages in messages attr" do
10
+ amv = User.validators_on(:name).first
11
+ message_collection = Judge::MessageCollection.new(@user, :name, amv)
12
+ message_collection.messages.should be_a Hash
13
+ end
14
+
15
+ it "has to_hash method which returns messages hash" do
16
+ amv = User.validators_on(:name).first
17
+ message_collection = Judge::MessageCollection.new(@user, :name, amv)
18
+ message_collection.should respond_to :to_hash
19
+ message_collection.to_hash.should be_a Hash
20
+ end
21
+
22
+ describe "#generate_base!" do
23
+ it "adds correct base message to messages hash" do
24
+ amv = User.validators_on(:name).first
25
+ message_collection = Judge::MessageCollection.new(@user, :name, amv, :generate => false)
26
+ message_collection.to_hash.should be_empty
27
+ message_collection.send(:generate_base!)
28
+ message_collection.to_hash[:blank].should be_a String
29
+ end
30
+ end
31
+
32
+ describe "#generate_options!" do
33
+ it "adds correct optional messages to messages hash when present (length)" do
34
+ amv = User.validators_on(:username).first
35
+ message_collection = Judge::MessageCollection.new(@user, :username, amv, :generate => false)
36
+ message_collection.to_hash.should be_empty
37
+ message_collection.send(:generate_options!)
38
+ message_collection.to_hash[:too_long].should be_a String
39
+ end
40
+
41
+ it "adds correct optional messages to messages hash when present (numericality)" do
42
+ amv = User.validators_on(:age).first
43
+ message_collection = Judge::MessageCollection.new(@user, :age, amv, :generate => false)
44
+ message_collection.to_hash.should be_empty
45
+ message_collection.send(:generate_options!)
46
+ message_collection.to_hash[:greater_than].should be_a String
47
+ end
48
+
49
+ it "adds nothing to messages hash when optional messages not present" do
50
+ amv = User.validators_on(:name).first
51
+ message_collection = Judge::MessageCollection.new(@user, :name, amv, :generate => false)
52
+ message_collection.send(:generate_options!)
53
+ message_collection.to_hash.should be_empty
54
+ end
55
+ end
56
+
57
+ describe "#generate_blank!" do
58
+ it "adds blank message to messages hash if applicable" do
59
+ amv = User.validators_on(:username).first
60
+ message_collection = Judge::MessageCollection.new(@user, :username, amv, :generate => false)
61
+ message_collection.to_hash.should be_empty
62
+ message_collection.send(:generate_blank!)
63
+ message_collection.to_hash[:blank].should be_a String
64
+ end
65
+
66
+ it "does not add blank message to messages hash if allow_blank is true" do
67
+ amv = User.validators_on(:country).first
68
+ message_collection = Judge::MessageCollection.new(@user, :country, amv, :generate => false)
69
+ message_collection.send(:generate_blank!)
70
+ message_collection.to_hash.should be_empty
71
+ end
72
+ end
73
+
74
+ describe "#generate_integer!" do
75
+ it "adds not_an_integer message to messages hash if only_integer is true" do
76
+ amv = User.validators_on(:age).first
77
+ message_collection = Judge::MessageCollection.new(@user, :age, amv, :generate => false)
78
+ message_collection.to_hash.should be_empty
79
+ message_collection.send(:generate_integer!)
80
+ message_collection.to_hash[:not_an_integer].should be_a String
81
+ end
82
+ end
83
+
84
+ end
File without changes
@@ -0,0 +1,13 @@
1
+ require "bundler/setup"
2
+ require "active_record"
3
+ require "action_view"
4
+ require "judge"
5
+ require "rspec"
6
+ require "factory_girl"
7
+ require "setup"
8
+
9
+ require_relative "factories"
10
+
11
+ RSpec.configure do |config|
12
+ config.color_enabled = true
13
+ end
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ describe Judge::ValidatorCollection do
4
+
5
+ let(:vc) { Judge::ValidatorCollection.new(FactoryGirl.build(:user), :name) }
6
+
7
+ it "contains validators" do
8
+ vc.validators.should be_an Array
9
+ vc.validators.first.should be_a Judge::Validator
10
+ end
11
+
12
+ it "converts to json correctly" do
13
+ vc.to_json.should be_a String
14
+ end
15
+
16
+ it "is enumerable" do
17
+ vc.should be_an Enumerable
18
+ vc.should respond_to :each
19
+ end
20
+
21
+ end
@@ -0,0 +1,37 @@
1
+ require "spec_helper"
2
+
3
+ describe Judge::Validator do
4
+
5
+ before(:each) do
6
+ user = FactoryGirl.build(:user)
7
+ amv = User.validators_on(:name).first
8
+ @validator = Judge::Validator.new(amv, :name, Judge::MessageCollection.new(user, :name, amv))
9
+ end
10
+
11
+ it "has an original validator in validator attr" do
12
+ @validator.active_model_validator.should be_a ActiveModel::Validations::PresenceValidator
13
+ end
14
+
15
+ it "has correct kind attr" do
16
+ @validator.kind.should eql :presence
17
+ end
18
+
19
+ it "has hash in options attr" do
20
+ @validator.options.should be_a Hash
21
+ end
22
+
23
+ it "has Judge::MessageCollection in messages attr" do
24
+ @validator.messages.should be_a Judge::MessageCollection
25
+ end
26
+
27
+ describe "#to_hash" do
28
+ it "converts to hash with correct properties" do
29
+ hash = @validator.to_hash
30
+ hash.should be_a Hash
31
+ hash[:kind].should be_a Symbol
32
+ hash[:options].should be_a Hash
33
+ hash[:messages].should be_a Hash
34
+ end
35
+ end
36
+
37
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: judge
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-14 00:00:00.000000000 +00:00
13
- default_executable:
12
+ date: 2012-02-25 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: jasmine
17
- requirement: &2157289920 !ruby/object:Gem::Requirement
16
+ requirement: &2153185740 !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ~>
@@ -22,10 +21,10 @@ dependencies:
22
21
  version: 1.0.2
23
22
  type: :development
24
23
  prerelease: false
25
- version_requirements: *2157289920
24
+ version_requirements: *2153185740
26
25
  - !ruby/object:Gem::Dependency
27
26
  name: rails
28
- requirement: &2157289420 !ruby/object:Gem::Requirement
27
+ requirement: &2153185040 !ruby/object:Gem::Requirement
29
28
  none: false
30
29
  requirements:
31
30
  - - ~>
@@ -33,21 +32,21 @@ dependencies:
33
32
  version: 3.0.10
34
33
  type: :development
35
34
  prerelease: false
36
- version_requirements: *2157289420
35
+ version_requirements: *2153185040
37
36
  - !ruby/object:Gem::Dependency
38
- name: shoulda
39
- requirement: &2157288960 !ruby/object:Gem::Requirement
37
+ name: rspec
38
+ requirement: &2153184480 !ruby/object:Gem::Requirement
40
39
  none: false
41
40
  requirements:
42
41
  - - ~>
43
42
  - !ruby/object:Gem::Version
44
- version: 2.11.3
43
+ version: 2.8.0
45
44
  type: :development
46
45
  prerelease: false
47
- version_requirements: *2157288960
46
+ version_requirements: *2153184480
48
47
  - !ruby/object:Gem::Dependency
49
48
  name: sqlite3-ruby
50
- requirement: &2157288500 !ruby/object:Gem::Requirement
49
+ requirement: &2153183920 !ruby/object:Gem::Requirement
51
50
  none: false
52
51
  requirements:
53
52
  - - ~>
@@ -55,18 +54,18 @@ dependencies:
55
54
  version: 1.3.2
56
55
  type: :development
57
56
  prerelease: false
58
- version_requirements: *2157288500
57
+ version_requirements: *2153183920
59
58
  - !ruby/object:Gem::Dependency
60
- name: factory_girl
61
- requirement: &2157309780 !ruby/object:Gem::Requirement
59
+ name: factory_girl_rails
60
+ requirement: &2153183360 !ruby/object:Gem::Requirement
62
61
  none: false
63
62
  requirements:
64
63
  - - ~>
65
64
  - !ruby/object:Gem::Version
66
- version: 2.2.0
65
+ version: 1.7.0
67
66
  type: :development
68
67
  prerelease: false
69
- version_requirements: *2157309780
68
+ version_requirements: *2153183360
70
69
  description: Validate forms on the client side, cleanly
71
70
  email: joe@tribesports.com
72
71
  executables: []
@@ -86,11 +85,15 @@ files:
86
85
  - lib/generators/judge/templates/underscore.js
87
86
  - lib/judge.rb
88
87
  - lib/judge/form_builder.rb
88
+ - lib/judge/html.rb
89
89
  - lib/judge/message_collection.rb
90
90
  - lib/judge/validator.rb
91
91
  - lib/judge/validator_collection.rb
92
92
  - lib/judge/version.rb
93
93
  - lib/tasks/js_tests.rake
94
+ - spec/factories.rb
95
+ - spec/form_builder_spec.rb
96
+ - spec/html_spec.rb
94
97
  - spec/javascripts/JudgeSpec.js
95
98
  - spec/javascripts/fixtures/form.html
96
99
  - spec/javascripts/helpers/customMatchers.js
@@ -102,15 +105,11 @@ files:
102
105
  - spec/javascripts/support/jasmine_config.rb
103
106
  - spec/javascripts/support/jasmine_runner.rb
104
107
  - spec/javascripts/support/phantomRunner.js
105
- - test/expected_elements.rb
106
- - test/factories.rb
107
- - test/setup.rb
108
- - test/test_form_builder.rb
109
- - test/test_helper.rb
110
- - test/test_message_collection.rb
111
- - test/test_validator.rb
112
- - test/test_validator_collection.rb
113
- has_rdoc: true
108
+ - spec/message_collection_spec.rb
109
+ - spec/setup.rb
110
+ - spec/spec_helper.rb
111
+ - spec/validator_collection_spec.rb
112
+ - spec/validator_spec.rb
114
113
  homepage: http://github.com/joecorcoran/judge
115
114
  licenses:
116
115
  - MIT
@@ -124,19 +123,28 @@ required_ruby_version: !ruby/object:Gem::Requirement
124
123
  - - ! '>='
125
124
  - !ruby/object:Gem::Version
126
125
  version: '0'
126
+ segments:
127
+ - 0
128
+ hash: -448425403214790540
127
129
  required_rubygems_version: !ruby/object:Gem::Requirement
128
130
  none: false
129
131
  requirements:
130
132
  - - ! '>='
131
133
  - !ruby/object:Gem::Version
132
134
  version: '0'
135
+ segments:
136
+ - 0
137
+ hash: -448425403214790540
133
138
  requirements: []
134
139
  rubyforge_project:
135
- rubygems_version: 1.6.2
140
+ rubygems_version: 1.8.15
136
141
  signing_key:
137
142
  specification_version: 3
138
143
  summary: Simple client side ActiveModel::Validators
139
144
  test_files:
145
+ - spec/factories.rb
146
+ - spec/form_builder_spec.rb
147
+ - spec/html_spec.rb
140
148
  - spec/javascripts/JudgeSpec.js
141
149
  - spec/javascripts/fixtures/form.html
142
150
  - spec/javascripts/helpers/customMatchers.js
@@ -148,11 +156,8 @@ test_files:
148
156
  - spec/javascripts/support/jasmine_config.rb
149
157
  - spec/javascripts/support/jasmine_runner.rb
150
158
  - spec/javascripts/support/phantomRunner.js
151
- - test/expected_elements.rb
152
- - test/factories.rb
153
- - test/setup.rb
154
- - test/test_form_builder.rb
155
- - test/test_helper.rb
156
- - test/test_message_collection.rb
157
- - test/test_validator.rb
158
- - test/test_validator_collection.rb
159
+ - spec/message_collection_spec.rb
160
+ - spec/setup.rb
161
+ - spec/spec_helper.rb
162
+ - spec/validator_collection_spec.rb
163
+ - spec/validator_spec.rb
@@ -1,235 +0,0 @@
1
- module ExpectedElements
2
-
3
- def expected_text_field
4
- %Q{<input data-validate="[{&quot;kind&quot;:&quot;presence&quot;,&quot;options&quot;:{},&quot;messages&quot;:{&quot;blank&quot;:&quot;can't be blank&quot;}}]" id="user_name" name="user[name]" size="30" type="text" />}
5
- end
6
-
7
- def expected_text_area
8
- %Q{<textarea cols="40" data-validate="[{&quot;kind&quot;:&quot;presence&quot;,&quot;options&quot;:{},&quot;messages&quot;:{&quot;blank&quot;:&quot;can't be blank&quot;}}]" id="user_bio" name="user[bio]" rows="20"></textarea>}
9
- end
10
-
11
- def expected_password_field
12
- %Q{<input data-validate="[{&quot;kind&quot;:&quot;format&quot;,&quot;options&quot;:{&quot;with&quot;:&quot;(?-mix:.+)&quot;},&quot;messages&quot;:{&quot;invalid&quot;:&quot;is invalid&quot;,&quot;blank&quot;:&quot;can't be blank&quot;}},{&quot;kind&quot;:&quot;confirmation&quot;,&quot;options&quot;:{},&quot;messages&quot;:{&quot;confirmation&quot;:&quot;doesn't match confirmation&quot;}}]" id="user_password" name="user[password]" size="30" type="password" />}
13
- end
14
-
15
- def expected_check_box
16
- %Q{<input data-validate="[{&quot;kind&quot;:&quot;acceptance&quot;,&quot;options&quot;:{&quot;allow_nil&quot;:true,&quot;accept&quot;:&quot;1&quot;},&quot;messages&quot;:{&quot;accepted&quot;:&quot;must be accepted&quot;}}]" id="user_accepted" name="user[accepted]" size="30" type="password" />}
17
- end
18
-
19
- def expected_radio_button
20
- %Q{<input data-validate="[{&quot;kind&quot;:&quot;inclusion&quot;,&quot;options&quot;:{&quot;in&quot;:[&quot;male&quot;,&quot;female&quot;,&quot;other&quot;,&quot;withheld&quot;]},&quot;messages&quot;:{&quot;inclusion&quot;:&quot;is not included in the list&quot;,&quot;blank&quot;:&quot;can't be blank&quot;}}]" id="user_gender_female" name="user[gender]" type="radio" value="female" />}
21
- end
22
-
23
- def expected_select
24
- %Q{<select data-validate="[{&quot;kind&quot;:&quot;format&quot;,&quot;options&quot;:{&quot;with&quot;:&quot;(?-mix:[A-Za-z])&quot;,&quot;allow_blank&quot;:true},&quot;messages&quot;:{&quot;invalid&quot;:&quot;is invalid&quot;}}]" id="user_country" name="user[country]"><option value="US">US</option>
25
- <option value="GB">GB</option></select>}
26
- end
27
-
28
- def expected_collection_select
29
- %Q{<select data-validate="[{&quot;kind&quot;:&quot;presence&quot;,&quot;options&quot;:{},&quot;messages&quot;:{&quot;blank&quot;:&quot;can't be blank&quot;}}]" id="user_team_id" name="user[team_id]"><option value="1">Team 1</option>
30
- <option value="2">Team 2</option>
31
- <option value="3">Team 3</option>
32
- <option value="4">Team 4</option>
33
- <option value="5">Team 5</option></select>}
34
- end
35
-
36
- def expected_grouped_collection_select
37
- %Q{<select data-validate="[{&quot;kind&quot;:&quot;presence&quot;,&quot;options&quot;:{},&quot;messages&quot;:{&quot;blank&quot;:&quot;can't be blank&quot;}}]" id="user_discipline_id" name="user[discipline_id]"><optgroup label="Category 1"><option value="">Sport 1</option></optgroup></select>}
38
- end
39
-
40
- def expected_date_select
41
- %Q{<select data-validate="[{&quot;kind&quot;:&quot;presence&quot;,&quot;options&quot;:{},&quot;messages&quot;:{&quot;blank&quot;:&quot;can't be blank&quot;}}]" id="user_dob_1i" name="user[dob(1i)]">
42
- <option value="2006">2006</option>
43
- <option value="2007">2007</option>
44
- <option value="2008">2008</option>
45
- <option value="2009">2009</option>
46
- <option value="2010">2010</option>
47
- <option selected="selected" value="2011">2011</option>
48
- <option value="2012">2012</option>
49
- <option value="2013">2013</option>
50
- <option value="2014">2014</option>
51
- <option value="2015">2015</option>
52
- <option value="2016">2016</option>
53
- </select>
54
- <select data-validate="[{&quot;kind&quot;:&quot;presence&quot;,&quot;options&quot;:{},&quot;messages&quot;:{&quot;blank&quot;:&quot;can't be blank&quot;}}]" id="user_dob_2i" name="user[dob(2i)]">
55
- <option value="1">January</option>
56
- <option value="2">February</option>
57
- <option value="3">March</option>
58
- <option value="4">April</option>
59
- <option value="5">May</option>
60
- <option value="6">June</option>
61
- <option value="7">July</option>
62
- <option value="8">August</option>
63
- <option value="9">September</option>
64
- <option value="10">October</option>
65
- <option selected="selected" value="11">November</option>
66
- <option value="12">December</option>
67
- </select>
68
- <select data-validate="[{&quot;kind&quot;:&quot;presence&quot;,&quot;options&quot;:{},&quot;messages&quot;:{&quot;blank&quot;:&quot;can't be blank&quot;}}]" id="user_dob_3i" name="user[dob(3i)]">
69
- <option value="1">1</option>
70
- <option value="2">2</option>
71
- <option value="3">3</option>
72
- <option value="4">4</option>
73
- <option selected="selected" value="5">5</option>
74
- <option value="6">6</option>
75
- <option value="7">7</option>
76
- <option value="8">8</option>
77
- <option value="9">9</option>
78
- <option value="10">10</option>
79
- <option value="11">11</option>
80
- <option value="12">12</option>
81
- <option value="13">13</option>
82
- <option value="14">14</option>
83
- <option value="15">15</option>
84
- <option value="16">16</option>
85
- <option value="17">17</option>
86
- <option value="18">18</option>
87
- <option value="19">19</option>
88
- <option value="20">20</option>
89
- <option value="21">21</option>
90
- <option value="22">22</option>
91
- <option value="23">23</option>
92
- <option value="24">24</option>
93
- <option value="25">25</option>
94
- <option value="26">26</option>
95
- <option value="27">27</option>
96
- <option value="28">28</option>
97
- <option value="29">29</option>
98
- <option value="30">30</option>
99
- <option value="31">31</option>
100
- </select>
101
- }
102
- end
103
-
104
- def expected_datetime_select
105
- %Q{<select data-validate="[{&quot;kind&quot;:&quot;presence&quot;,&quot;options&quot;:{},&quot;messages&quot;:{&quot;blank&quot;:&quot;can't be blank&quot;}}]" id="user_dob_1i" name="user[dob(1i)]">
106
- <option value="2006">2006</option>
107
- <option value="2007">2007</option>
108
- <option value="2008">2008</option>
109
- <option value="2009">2009</option>
110
- <option value="2010">2010</option>
111
- <option selected="selected" value="2011">2011</option>
112
- <option value="2012">2012</option>
113
- <option value="2013">2013</option>
114
- <option value="2014">2014</option>
115
- <option value="2015">2015</option>
116
- <option value="2016">2016</option>
117
- </select>
118
- <select data-validate="[{&quot;kind&quot;:&quot;presence&quot;,&quot;options&quot;:{},&quot;messages&quot;:{&quot;blank&quot;:&quot;can't be blank&quot;}}]" id="user_dob_2i" name="user[dob(2i)]">
119
- <option value="1">January</option>
120
- <option value="2">February</option>
121
- <option value="3">March</option>
122
- <option value="4">April</option>
123
- <option value="5">May</option>
124
- <option value="6">June</option>
125
- <option value="7">July</option>
126
- <option value="8">August</option>
127
- <option value="9">September</option>
128
- <option value="10">October</option>
129
- <option selected="selected" value="11">November</option>
130
- <option value="12">December</option>
131
- </select>
132
- <select data-validate="[{&quot;kind&quot;:&quot;presence&quot;,&quot;options&quot;:{},&quot;messages&quot;:{&quot;blank&quot;:&quot;can't be blank&quot;}}]" id="user_dob_3i" name="user[dob(3i)]">
133
- <option value="1">1</option>
134
- <option value="2">2</option>
135
- <option value="3">3</option>
136
- <option value="4">4</option>
137
- <option selected="selected" value="5">5</option>
138
- <option value="6">6</option>
139
- <option value="7">7</option>
140
- <option value="8">8</option>
141
- <option value="9">9</option>
142
- <option value="10">10</option>
143
- <option value="11">11</option>
144
- <option value="12">12</option>
145
- <option value="13">13</option>
146
- <option value="14">14</option>
147
- <option value="15">15</option>
148
- <option value="16">16</option>
149
- <option value="17">17</option>
150
- <option value="18">18</option>
151
- <option value="19">19</option>
152
- <option value="20">20</option>
153
- <option value="21">21</option>
154
- <option value="22">22</option>
155
- <option value="23">23</option>
156
- <option value="24">24</option>
157
- <option value="25">25</option>
158
- <option value="26">26</option>
159
- <option value="27">27</option>
160
- <option value="28">28</option>
161
- <option value="29">29</option>
162
- <option value="30">30</option>
163
- <option value="31">31</option>
164
- </select>
165
- &mdash; <select data-validate="[{&quot;kind&quot;:&quot;presence&quot;,&quot;options&quot;:{},&quot;messages&quot;:{&quot;blank&quot;:&quot;can't be blank&quot;}}]" id="user_dob_4i" name="user[dob(4i)]">
166
- <option value="00">00</option>
167
- <option value="01">01</option>
168
- <option value="02">02</option>
169
- <option value="03">03</option>
170
- <option value="04">04</option>
171
- <option value="05">05</option>
172
- <option value="06">06</option>
173
- <option value="07">07</option>
174
- <option value="08">08</option>
175
- <option value="09">09</option>
176
- <option value="10">10</option>
177
- <option value="11">11</option>
178
- <option value="12">12</option>
179
- <option value="13">13</option>
180
- <option value="14">14</option>
181
- <option value="15">15</option>
182
- <option value="16">16</option>
183
- <option selected="selected" value="17">17</option>
184
- <option value="18">18</option>
185
- <option value="19">19</option>
186
- <option value="20">20</option>
187
- <option value="21">21</option>
188
- <option value="22">22</option>
189
- <option value="23">23</option>
190
- </select>
191
- : <select data-validate="[{&quot;kind&quot;:&quot;presence&quot;,&quot;options&quot;:{},&quot;messages&quot;:{&quot;blank&quot;:&quot;can't be blank&quot;}}]" id="user_dob_5i" name="user[dob(5i)]">
192
- <option selected="selected" value="00">00</option>
193
- <option value="30">30</option>
194
- </select>
195
- }
196
- end
197
-
198
- def expected_time_select
199
- %Q{<input id="user_dob_1i" name="user[dob(1i)]" type="hidden" value="2011" />
200
- <input id="user_dob_2i" name="user[dob(2i)]" type="hidden" value="11" />
201
- <input id="user_dob_3i" name="user[dob(3i)]" type="hidden" value="5" />
202
- <select data-validate="[{&quot;kind&quot;:&quot;presence&quot;,&quot;options&quot;:{},&quot;messages&quot;:{&quot;blank&quot;:&quot;can't be blank&quot;}}]" id="user_dob_4i" name="user[dob(4i)]">
203
- <option value="00">00</option>
204
- <option value="01">01</option>
205
- <option value="02">02</option>
206
- <option value="03">03</option>
207
- <option value="04">04</option>
208
- <option value="05">05</option>
209
- <option value="06">06</option>
210
- <option value="07">07</option>
211
- <option value="08">08</option>
212
- <option value="09">09</option>
213
- <option value="10">10</option>
214
- <option value="11">11</option>
215
- <option value="12">12</option>
216
- <option value="13">13</option>
217
- <option value="14">14</option>
218
- <option value="15">15</option>
219
- <option value="16">16</option>
220
- <option selected="selected" value="17">17</option>
221
- <option value="18">18</option>
222
- <option value="19">19</option>
223
- <option value="20">20</option>
224
- <option value="21">21</option>
225
- <option value="22">22</option>
226
- <option value="23">23</option>
227
- </select>
228
- : <select data-validate="[{&quot;kind&quot;:&quot;presence&quot;,&quot;options&quot;:{},&quot;messages&quot;:{&quot;blank&quot;:&quot;can't be blank&quot;}}]" id="user_dob_5i" name="user[dob(5i)]">
229
- <option selected="selected" value="00">00</option>
230
- <option value="30">30</option>
231
- </select>
232
- }
233
- end
234
-
235
- end
@@ -1,69 +0,0 @@
1
- require "action_view/test_case"
2
- require "html/document"
3
- require "expected_elements"
4
-
5
- class JudgeFormBuilderTest < ActionView::TestCase
6
-
7
- include ExpectedElements
8
-
9
- def test_text_field
10
- assert_dom_equal expected_text_field, builder.text_field(:name, :validate => true)
11
- end
12
-
13
- def test_text_area
14
- assert_dom_equal expected_text_area, builder.text_area(:bio, :validate => true)
15
- end
16
-
17
- def test_password_field
18
- assert_dom_equal expected_password_field, builder.password_field(:password, :validate => true)
19
- end
20
-
21
- def test_check_box
22
- assert_dom_equal expected_check_box, builder.password_field(:accepted, :validate => true)
23
- end
24
-
25
- def test_radio_button
26
- assert_dom_equal expected_radio_button, builder.radio_button(:gender, "female", :validate => true)
27
- end
28
-
29
- def test_select
30
- assert_dom_equal expected_select, builder.select(:country, [["US", "US"], ["GB", "GB"]], :validate => true)
31
- end
32
-
33
- def test_collection_select
34
- assert_dom_equal expected_collection_select, builder.collection_select(:team_id, FactoryGirl.create_list(:team, 5), :id, :name, :validate => true)
35
- end
36
-
37
- def test_grouped_collection_select
38
- assert_dom_equal expected_grouped_collection_select, builder.grouped_collection_select(:discipline_id, categories, :sports, :name, :id, :name, :validate => true)
39
- end
40
-
41
- def test_date_select
42
- assert_dom_equal expected_date_select, builder.date_select(:dob, :validate => true, :minute_step => 30)
43
- end
44
-
45
- def test_datetime_select
46
- assert_dom_equal expected_datetime_select, builder.datetime_select(:dob, :validate => true, :minute_step => 30)
47
- end
48
-
49
- def test_time_select
50
- assert_dom_equal expected_time_select, builder.time_select(:dob, :validate => true, :minute_step => 30)
51
- end
52
-
53
- def test_time_zone_select
54
- assert builder.time_zone_select(:time_zone, ActiveSupport::TimeZone.us_zones, :include_blank => true, :validate => true), "time zone select not present"
55
- end
56
-
57
- def builder
58
- Judge::FormBuilder.new(:user, FactoryGirl.build(:user), self, {}, nil)
59
- end
60
-
61
- def categories
62
- category = FactoryGirl.build(:category)
63
- sport = FactoryGirl.build(:sport)
64
- sport.disciplines << FactoryGirl.build_list(:discipline, 3)
65
- category.sports << sport
66
- [category]
67
- end
68
-
69
- end
data/test/test_helper.rb DELETED
@@ -1,11 +0,0 @@
1
- require "bundler/setup"
2
-
3
- # require stuff
4
- %w{active_record action_view shoulda factory_girl}.each do |x|
5
- require x
6
- end
7
-
8
- # require judge and test setup files
9
- %w{judge setup factories}.each do |x|
10
- require x
11
- end
@@ -1,84 +0,0 @@
1
- class JudgeMessageCollectionTest < Test::Unit::TestCase
2
-
3
- context "Judge::MessageCollection" do
4
- setup do
5
- @user = FactoryGirl.build(:user)
6
- end
7
-
8
- should "have hash of messages in messages attr" do
9
- amv = User.validators_on(:name).first
10
- message_collection = Judge::MessageCollection.new(@user, :name, amv)
11
- assert_kind_of Hash, message_collection.messages
12
- end
13
-
14
- should "have to_hash method which returns messages hash" do
15
- amv = User.validators_on(:name).first
16
- message_collection = Judge::MessageCollection.new(@user, :name, amv)
17
- assert_respond_to message_collection, :to_hash
18
- assert_kind_of Hash, message_collection.to_hash
19
- end
20
-
21
- context "#generate_base!" do
22
- should "add correct base message to messages hash" do
23
- amv = User.validators_on(:name).first
24
- message_collection = Judge::MessageCollection.new(@user, :name, amv, :generate => false)
25
- assert_equal 0, message_collection.to_hash.length
26
- message_collection.send(:generate_base!)
27
- assert message_collection.to_hash[:blank]
28
- end
29
- end
30
-
31
- context "#generate_options!" do
32
- should "add correct optional messages to messages hash when present (length)" do
33
- amv = User.validators_on(:username).first
34
- message_collection = Judge::MessageCollection.new(@user, :username, amv, :generate => false)
35
- assert_equal 0, message_collection.to_hash.length
36
- message_collection.send(:generate_options!)
37
- assert message_collection.to_hash[:too_long]
38
- end
39
-
40
- should "add correct optional messages to messages hash when present (numericality)" do
41
- amv = User.validators_on(:age).first
42
- message_collection = Judge::MessageCollection.new(@user, :age, amv, :generate => false)
43
- assert_equal 0, message_collection.to_hash.length
44
- message_collection.send(:generate_options!)
45
- assert message_collection.to_hash[:greater_than]
46
- end
47
-
48
- should "add nothing to messages hash when optional messages not present" do
49
- amv = User.validators_on(:name).first
50
- message_collection = Judge::MessageCollection.new(@user, :name, amv, :generate => false)
51
- message_collection.send(:generate_options!)
52
- assert_equal 0, message_collection.to_hash.length
53
- end
54
- end
55
-
56
- context "#generate_blank!" do
57
- should "add blank message to messages hash if applicable" do
58
- amv = User.validators_on(:username).first
59
- message_collection = Judge::MessageCollection.new(@user, :username, amv, :generate => false)
60
- assert_equal 0, message_collection.to_hash.length
61
- message_collection.send(:generate_blank!)
62
- assert message_collection.to_hash[:blank]
63
- end
64
-
65
- should "not add blank message to messages hash if allow_blank is true" do
66
- amv = User.validators_on(:country).first
67
- message_collection = Judge::MessageCollection.new(@user, :country, amv, :generate => false)
68
- message_collection.send(:generate_blank!)
69
- assert_equal 0, message_collection.to_hash.length
70
- end
71
- end
72
-
73
- context "#generate_integer!" do
74
- should "add not_an_integer message to messages hash if only_integer is true" do
75
- amv = User.validators_on(:age).first
76
- message_collection = Judge::MessageCollection.new(@user, :age, amv, :generate => false)
77
- assert_equal 0, message_collection.to_hash.length
78
- message_collection.send(:generate_integer!)
79
- assert message_collection.to_hash[:not_an_integer]
80
- end
81
- end
82
- end
83
-
84
- end
@@ -1,37 +0,0 @@
1
- class JudgeValidatorTest < Test::Unit::TestCase
2
-
3
- context "Judge::Validator" do
4
- setup do
5
- user = FactoryGirl.build(:user)
6
- amv = User.validators_on(:name).first
7
- @validator = Judge::Validator.new(amv, :name, Judge::MessageCollection.new(user, :name, amv))
8
- end
9
-
10
- should "have an original validator in validator attr" do
11
- assert_instance_of ActiveModel::Validations::PresenceValidator, @validator.active_model_validator
12
- end
13
-
14
- should "have correct kind attr" do
15
- assert_equal :presence, @validator.kind
16
- end
17
-
18
- should "have hash in options attr" do
19
- assert_kind_of Hash, @validator.options
20
- end
21
-
22
- should "have Judge::MessageCollection in messages attr" do
23
- assert_instance_of Judge::MessageCollection, @validator.messages
24
- end
25
-
26
- context "to_hash" do
27
- should "convert to hash with correct properties" do
28
- hash = @validator.to_hash
29
- assert_kind_of Hash, hash
30
- assert_kind_of Symbol, hash[:kind]
31
- assert_kind_of Hash, hash[:options]
32
- assert_kind_of Hash, hash[:messages]
33
- end
34
- end
35
- end
36
-
37
- end
@@ -1,19 +0,0 @@
1
- class JudgeValidatorCollection < Test::Unit::TestCase
2
-
3
- context "Judge::ValidatorCollection" do
4
- setup do
5
- user = FactoryGirl.build(:user)
6
- @validator_collection = Judge::ValidatorCollection.new(user, :name)
7
- end
8
-
9
- should "contain validators" do
10
- assert_kind_of Array, @validator_collection.validators
11
- assert_instance_of Judge::Validator, @validator_collection.validators.first
12
- end
13
-
14
- should "convert to json correctly" do
15
- assert_kind_of String, @validator_collection.to_json
16
- end
17
- end
18
-
19
- end