judge 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,7 @@
1
1
  rvm:
2
2
  - 1.9.2
3
3
 
4
- script: "bundle exec rake test:helpers"
5
-
6
- #before_script:
7
- # - "sudo apt-get install qt4-qmake"
8
- # - "git clone git://github.com/ariya/phantomjs.git && cd phantomjs"
9
- # - "git checkout 1.2"
10
- # - "qmake-qt4 && make"
4
+ script: "bundle exec rake test:form"
11
5
 
12
6
  notifications:
13
7
  recipients:
data/README.md CHANGED
@@ -3,8 +3,6 @@ judge
3
3
 
4
4
  Client-side form validation in Rails 3.
5
5
 
6
- [![Build status](http://travis-ci.org/joecorcoran/judge.png)](http://travis-ci.org/joecorcoran/judge)
7
-
8
6
  Usage
9
7
  -----
10
8
 
data/Rakefile CHANGED
@@ -37,7 +37,7 @@ Rake::RDocTask.new do |rdoc|
37
37
  end
38
38
 
39
39
  namespace :test do
40
- Rake::TestTask.new(:helpers) do |test|
40
+ Rake::TestTask.new(:form) do |test|
41
41
  test.libs << 'lib' << 'test'
42
42
  test.pattern = 'test/**/*_test.rb'
43
43
  test.verbose = true
@@ -47,5 +47,5 @@ namespace :test do
47
47
  task :js => ["jasmine:phantom"]
48
48
 
49
49
  desc "Run all tests"
50
- task :all => [:helpers, :js]
50
+ task :all => [:form, :js]
51
51
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{judge}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Joe Corcoran"]
12
- s.date = %q{2011-07-21}
12
+ s.date = %q{2011-07-25}
13
13
  s.description = %q{Validate forms in-place using your model validations}
14
14
  s.email = %q{joe@tribesports.com}
15
15
  s.extra_rdoc_files = [
@@ -31,7 +31,8 @@ Gem::Specification.new do |s|
31
31
  "lib/generators/judge/templates/judge.js",
32
32
  "lib/generators/judge/templates/underscore.js",
33
33
  "lib/judge.rb",
34
- "lib/judge/helpers.rb",
34
+ "lib/judge/form.rb",
35
+ "lib/judge/utils.rb",
35
36
  "lib/tasks/js_tests.rake",
36
37
  "spec/javascripts/JudgeSpec.js",
37
38
  "spec/javascripts/fixtures/form.html",
@@ -48,6 +49,10 @@ Gem::Specification.new do |s|
48
49
  "test/dummy/app/controllers/application_controller.rb",
49
50
  "test/dummy/app/controllers/foos_controller.rb",
50
51
  "test/dummy/app/helpers/application_helper.rb",
52
+ "test/dummy/app/models/city.rb",
53
+ "test/dummy/app/models/continent.rb",
54
+ "test/dummy/app/models/country.rb",
55
+ "test/dummy/app/models/fake.rb",
51
56
  "test/dummy/app/models/foo.rb",
52
57
  "test/dummy/app/views/foos/new.html.erb",
53
58
  "test/dummy/app/views/layouts/application.html.erb",
@@ -68,6 +73,9 @@ Gem::Specification.new do |s|
68
73
  "test/dummy/config/routes.rb",
69
74
  "test/dummy/db/development.sqlite3",
70
75
  "test/dummy/db/migrate/20110624115516_create_foos.rb",
76
+ "test/dummy/db/migrate/20110724201117_create_fake_collections.rb",
77
+ "test/dummy/db/migrate/20110724201548_rename_fake_collection_to_fake.rb",
78
+ "test/dummy/db/migrate/20110725082530_create_continent_country_and_city_tables.rb",
71
79
  "test/dummy/db/schema.rb",
72
80
  "test/dummy/db/test.sqlite3",
73
81
  "test/dummy/log/development.log",
@@ -99,6 +107,10 @@ Gem::Specification.new do |s|
99
107
  "test/dummy/app/controllers/application_controller.rb",
100
108
  "test/dummy/app/controllers/foos_controller.rb",
101
109
  "test/dummy/app/helpers/application_helper.rb",
110
+ "test/dummy/app/models/city.rb",
111
+ "test/dummy/app/models/continent.rb",
112
+ "test/dummy/app/models/country.rb",
113
+ "test/dummy/app/models/fake.rb",
102
114
  "test/dummy/app/models/foo.rb",
103
115
  "test/dummy/config/application.rb",
104
116
  "test/dummy/config/boot.rb",
@@ -113,6 +125,9 @@ Gem::Specification.new do |s|
113
125
  "test/dummy/config/initializers/session_store.rb",
114
126
  "test/dummy/config/routes.rb",
115
127
  "test/dummy/db/migrate/20110624115516_create_foos.rb",
128
+ "test/dummy/db/migrate/20110724201117_create_fake_collections.rb",
129
+ "test/dummy/db/migrate/20110724201548_rename_fake_collection_to_fake.rb",
130
+ "test/dummy/db/migrate/20110725082530_create_continent_country_and_city_tables.rb",
116
131
  "test/dummy/db/schema.rb",
117
132
  "test/judge_test.rb",
118
133
  "test/test_helper.rb"
@@ -23,10 +23,10 @@ judge.Watcher = function (element) {
23
23
  throw new TypeError('[judge] Cannot construct new Watcher for object of this type');
24
24
  }
25
25
  if (element.getAttribute('data-validate') === null) {
26
- throw new ReferenceError('[judge] Cannot construct new Watcher for this element, please use judge helpers in your view');
26
+ throw new ReferenceError('[judge] Cannot construct new Watcher for this element, please use judge form builder methods in your view');
27
27
  }
28
28
  if (element.form.getAttribute('data-error-messages') === null) {
29
- throw new ReferenceError('[judge] Element parent form was not created using judge helper, please amend');
29
+ throw new ReferenceError('[judge] Element parent form was not created using judge form helper, please amend');
30
30
  }
31
31
 
32
32
 
@@ -151,6 +151,25 @@ judge.Watcher.prototype.validates = function() {
151
151
  if (withoutReg.test(value)) { msgs.push(options.message || instance.defaultMessages.invalid); }
152
152
  }
153
153
  return msgs.length ? { valid:false, messages:msgs } : { valid:true };
154
+ },
155
+
156
+ acceptance: function(options) {
157
+ if (instance.element.checked === true) {
158
+ return { valid:true };
159
+ } else {
160
+ return { valid:false, messages:[options.message || instance.defaultMessages.accepted] };
161
+ }
162
+ },
163
+
164
+ confirmation: function(options) {
165
+ var id = instance.element.getAttribute('id'),
166
+ confId = id + '_confirmation',
167
+ confElem = document.getElementById(confId);
168
+ if (instance.element.value === confElem.value) {
169
+ return { valid:true };
170
+ } else {
171
+ return { valid:false, messages:[options.message || instance.defaultMessages.confirmation] };
172
+ }
154
173
  }
155
174
  };
156
175
  return _.extend(methods, extendedMethods);
@@ -1,4 +1,5 @@
1
- require File.dirname(__FILE__) + '/judge/helpers'
1
+ require File.dirname(__FILE__) + '/judge/utils'
2
+ require File.dirname(__FILE__) + '/judge/form'
2
3
 
3
- ::ActionView::Helpers::FormBuilder.send(:include, Judge::FieldHelpers)
4
- ::ActionView::Helpers::FormHelper.send(:include, Judge::FormHelpers)
4
+ ::ActionView::Helpers::FormBuilder.send(:include, Judge::FormBuilder)
5
+ ::ActionView::Helpers::FormHelper.send(:include, Judge::FormHelper)
@@ -0,0 +1,56 @@
1
+ module Judge
2
+
3
+ module FormBuilder
4
+
5
+ include ActionView::Helpers::TagHelper
6
+
7
+ %w{text_field text_area}.each do |type|
8
+ helper = <<-END
9
+ def validated_#{type}(method, options = {})
10
+ options = { "data-validate" => Judge::Utils.jsonify_validators(self.object, method) }.merge(options)
11
+ @template.#{type}(self.object_name, method, options)
12
+ end
13
+ END
14
+ class_eval helper, __FILE__, __LINE__
15
+ end
16
+
17
+ def validated_radio_button(method, tag_value, options = {})
18
+ options = { "data-validate" => Judge::Utils.jsonify_validators(self.object, method) }.merge(options)
19
+ @template.radio_button(@object_name, method, tag_value, objectify_options(options))
20
+ end
21
+
22
+
23
+ def validated_check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
24
+ options = { "data-validate" => Judge::Utils.jsonify_validators(self.object, method) }.merge(options)
25
+ @template.check_box(self.object_name, method, objectify_options(options), checked_value, unchecked_value)
26
+ end
27
+
28
+ def validated_select(method, choices, options = {}, html_options = {})
29
+ html_options = { "data-validate" => Judge::Utils.jsonify_validators(self.object, method) }.merge(html_options)
30
+ @template.select(self.object_name, method, choices, objectify_options(options), @default_options.merge(html_options))
31
+ end
32
+
33
+ def validated_collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
34
+ html_options = { "data-validate" => Judge::Utils.jsonify_validators(self.object, method) }.merge(html_options)
35
+ @template.collection_select(self.object_name, method, collection, value_method, text_method, objectify_options(options), @default_options.merge(html_options))
36
+ end
37
+
38
+ def validated_grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {})
39
+ html_options = { "data-validate" => Judge::Utils.jsonify_validators(self.object, method) }.merge(html_options)
40
+ @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))
41
+ end
42
+
43
+ end
44
+
45
+ module FormHelper
46
+
47
+ def validated_form_for(record_or_name_or_array, *args, &proc)
48
+ options = args.extract_options!
49
+ options[:html] ||= {}
50
+ options[:html]["data-error-messages"] = I18n.t("errors.messages").to_json
51
+ form_for(record_or_name_or_array, *(args << options), &proc)
52
+ end
53
+
54
+ end
55
+
56
+ end
@@ -0,0 +1,13 @@
1
+ module Judge
2
+ module Utils
3
+
4
+ def self.jsonify_validators(object, method)
5
+ object
6
+ .class
7
+ .validators_on(method)
8
+ .collect{ |v| { :kind => v.kind.to_s, :options => v.options } }
9
+ .to_json
10
+ end
11
+
12
+ end
13
+ end
@@ -504,6 +504,60 @@ describe('judge', function() {
504
504
 
505
505
  });
506
506
 
507
+ describe('acceptance', function() {
508
+
509
+ var j;
510
+
511
+ beforeEach(function() {
512
+ j = new judge.Watcher(document.getElementById('foo_six'));
513
+ });
514
+
515
+ it('validates when element is checked', function() {
516
+ j.element.checked = true;
517
+ expect(j.validate().valid).toEqual(true);
518
+ });
519
+
520
+ it('invalidates when element is not checked', function() {
521
+ expect(j.validate().valid).toEqual(false);
522
+ });
523
+
524
+ it('invalidates with custom message when present', function() {
525
+ _(j.validators).first().options.message = 'must be ticked';
526
+ expect(j.validate().messages).toContain('must be ticked');
527
+ });
528
+
529
+ });
530
+
531
+ describe('confirmation', function() {
532
+
533
+ var j, c;
534
+
535
+ beforeEach(function() {
536
+ j = new judge.Watcher(document.getElementById('foo_seven'));
537
+ c = document.getElementById('foo_seven_confirmation');
538
+ });
539
+
540
+ it('validates when confirmed', function() {
541
+ j.element.value = 'password';
542
+ c.value = 'password';
543
+ expect(j.validate().valid).toEqual(true);
544
+ });
545
+
546
+ it('invalidates when not confirmed', function() {
547
+ j.element.value = 'password';
548
+ c.value = 'wrongpassword';
549
+ expect(j.validate().valid).toEqual(false);
550
+ });
551
+
552
+ it('invalidates with custom message when present', function() {
553
+ _(j.validators).first().options.message = 'must be same';
554
+ j.element.value = 'password';
555
+ c.value = 'wrongpassword';
556
+ expect(j.validate().messages).toContain('must be same');
557
+ });
558
+
559
+ });
560
+
507
561
  });
508
562
 
509
563
  describe('utils', function() {
@@ -44,6 +44,15 @@
44
44
  <label for="foo_five_wo">Five</label><br />
45
45
  <input data-validate="[{&quot;kind&quot;:&quot;format&quot;,&quot;options&quot;:{&quot;without&quot;:&quot;(?-mix:[A-Za-z]+)&quot;}}]" id="foo_five_wo" name="foo[five_wo]" size="30" type="text" />
46
46
  </div>
47
+ <div class="field">
48
+ <label for="foo_six">Six</label><br />
49
+ <input data-validate="[{&quot;kind&quot;:&quot;acceptance&quot;,&quot;options&quot;:{&quot;accept&quot;:&quot;1&quot;,&quot;allow_nil&quot;:&quot;true&quot;}}]" id="foo_six" name="foo[six]" type="checkbox" />
50
+ </div>
51
+ <div class="field">
52
+ <label for="foo_seven">Six</label><br />
53
+ <input data-validate="[{&quot;kind&quot;:&quot;confirmation&quot;,&quot;options&quot;:{}}]" id="foo_seven" name="foo[seven]" type="text" />
54
+ </div>
55
+ <input id="foo_seven_confirmation" name="foo[seven_confirmation]" type="text" />
47
56
  <div class="actions">
48
57
  <input id="foo_submit" name="commit" type="submit" value="Create Foo" />
49
58
  </div>
@@ -1,5 +1,11 @@
1
1
  class FoosController < ApplicationController
2
2
  def new
3
3
  @foo = Foo.new
4
+
5
+ continent = Continent.new(:id => 1, :name => "Europe")
6
+ country = Country.new(:id => 1, :name => "Germany")
7
+ country.cities << City.new(:id => 1, :name => "Hamburg")
8
+ continent.countries << country
9
+ @continents = [continent]
4
10
  end
5
11
  end
@@ -0,0 +1,5 @@
1
+ class City < ActiveRecord::Base
2
+ belongs_to :country
3
+ end
4
+
5
+
@@ -0,0 +1,4 @@
1
+ class Continent < ActiveRecord::Base
2
+ has_many :countries
3
+ end
4
+
@@ -0,0 +1,6 @@
1
+ class Country < ActiveRecord::Base
2
+ belongs_to :continent
3
+ has_many :cities
4
+ end
5
+
6
+
@@ -0,0 +1,2 @@
1
+ class Fake < ActiveRecord::Base
2
+ end
@@ -6,6 +6,8 @@ class Foo < ActiveRecord::Base
6
6
  validates :four, :numericality => { :only_integer => true, :odd => true, :less_than_or_equal_to => 7 },
7
7
  :exclusion => { :in => [3,12] }
8
8
  validates :five, :format => { :without => /[A-Za-z]+/ }
9
+ validates :six, :acceptance => true
10
+ validates :seven, :confirmation => true
9
11
 
10
12
  end
11
13
 
@@ -15,15 +15,15 @@
15
15
 
16
16
  <div class="field">
17
17
  <%= f.label :one %><br />
18
- <%= f.validated_text_field :one %>
18
+ <%= f.validated_select :one, [["hello", "HELLO"],["goodbye", "GOODBYE"]] %>
19
19
  </div>
20
20
  <div class="field">
21
21
  <%= f.label :two %><br />
22
- <%= f.validated_text_field :two %>
22
+ <%= f.validated_radio_button :two, "FOOBAR" %>
23
23
  </div>
24
24
  <div class="field">
25
25
  <%= f.label :three %><br />
26
- <%= f.validated_text_field :three %>
26
+ <%= f.validated_collection_select :three, [Fake.new(:text => "Dave", :value => 24), Fake.new(:text => "Alice", :value => 30)], :value, :text %>
27
27
  </div>
28
28
  <div class="field">
29
29
  <%= f.label :four %><br />
@@ -31,7 +31,15 @@
31
31
  </div>
32
32
  <div class="field">
33
33
  <%= f.label :five %><br />
34
- <%= f.validated_text_area :five %>
34
+ <%= f.validated_grouped_collection_select :five, @continents, :countries, :name, :id, :name %>
35
+ </div>
36
+ <div class="field">
37
+ <%= f.label :six %><br />
38
+ <%= f.validated_check_box :six %>
39
+ </div>
40
+ <div class="field">
41
+ <%= f.label :seven %><br />
42
+ <%= f.validated_text_field :seven %>
35
43
  </div>
36
44
  <div class="actions">
37
45
  <%= f.submit %>
@@ -0,0 +1,14 @@
1
+ class CreateFakeCollections < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :fake_collections do |t|
4
+ t.string :value
5
+ t.string :text
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :fake_collections
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ class RenameFakeCollectionToFake < ActiveRecord::Migration
2
+ def self.up
3
+ rename_table :fake_collections, :fakes
4
+ end
5
+
6
+ def self.down
7
+ rename_table :fakes, :fake_collections
8
+ end
9
+ end
@@ -0,0 +1,24 @@
1
+ class CreateContinentCountryAndCityTables < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :continents do |t|
4
+ t.integer :id
5
+ t.string :name
6
+ end
7
+ create_table :countries do |t|
8
+ t.integer :id
9
+ t.integer :continent_id
10
+ t.string :name
11
+ end
12
+ create_table :cities do |t|
13
+ t.integer :id
14
+ t.integer :country_id
15
+ t.string :name
16
+ end
17
+ end
18
+
19
+ def self.down
20
+ drop_table :continents
21
+ drop_table :countries
22
+ drop_table :cities
23
+ end
24
+ end
@@ -10,7 +10,28 @@
10
10
  #
11
11
  # It's strongly recommended to check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema.define(:version => 20110624115516) do
13
+ ActiveRecord::Schema.define(:version => 20110725082530) do
14
+
15
+ create_table "cities", :force => true do |t|
16
+ t.integer "country_id"
17
+ t.string "name"
18
+ end
19
+
20
+ create_table "continents", :force => true do |t|
21
+ t.string "name"
22
+ end
23
+
24
+ create_table "countries", :force => true do |t|
25
+ t.integer "continent_id"
26
+ t.string "name"
27
+ end
28
+
29
+ create_table "fakes", :force => true do |t|
30
+ t.string "value"
31
+ t.string "text"
32
+ t.datetime "created_at"
33
+ t.datetime "updated_at"
34
+ end
14
35
 
15
36
  create_table "foos", :force => true do |t|
16
37
  t.string "one"
Binary file
@@ -57,3 +57,217 @@ Migrating to CreateFoos (20110624115516)
57
57
  WHERE type = 'table' AND NOT name = 'sqlite_sequence'
58
58
  SQL (0.1ms) SELECT version FROM "schema_migrations"
59
59
  SQL (1.1ms) INSERT INTO "schema_migrations" (version) VALUES ('20110624115516')
60
+ SQL (0.5ms)  SELECT name
61
+ FROM sqlite_master
62
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
63
+ 
64
+ SQL (0.1ms) SELECT name
65
+ FROM sqlite_master
66
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
67
+ SQL (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
68
+ Migrating to CreateFoos (20110624115516)
69
+ Migrating to CreateFakeCollections (20110724201117)
70
+ SQL (0.0ms) select sqlite_version(*)
71
+ SQL (0.5ms) CREATE TABLE "fake_collections" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "value" varchar(255), "text" varchar(255), "created_at" datetime, "updated_at" datetime) 
72
+ SQL (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20110724201117')
73
+ SQL (0.3ms)  SELECT name
74
+ FROM sqlite_master
75
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
76
+ 
77
+ SQL (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
78
+ SQL (0.1ms)  SELECT name
79
+ FROM sqlite_master
80
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
81
+ 
82
+ SQL (0.0ms) PRAGMA index_list("fake_collections")
83
+ SQL (0.0ms) PRAGMA index_list("foos")
84
+ SQL (0.5ms) select sqlite_version(*)
85
+ SQL (0.3ms) SELECT name
86
+ FROM sqlite_master
87
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
88
+ SQL (0.1ms)  SELECT name
89
+ FROM sqlite_master
90
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
91
+ 
92
+ SQL (0.2ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
93
+ SQL (0.1ms)  SELECT name
94
+ FROM sqlite_master
95
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
96
+ 
97
+ SQL (0.0ms) PRAGMA index_list("fake_collections")
98
+ SQL (0.0ms) PRAGMA index_list("foos")
99
+ SQL (0.2ms) select sqlite_version(*)
100
+ SQL (0.1ms)  SELECT name
101
+ FROM sqlite_master
102
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
103
+ 
104
+ SQL (1.7ms) CREATE TABLE "fake_collections" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "value" varchar(255), "text" varchar(255), "created_at" datetime, "updated_at" datetime)
105
+ SQL (0.1ms)  SELECT name
106
+ FROM sqlite_master
107
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
108
+ 
109
+ SQL (1.3ms) CREATE TABLE "foos" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "one" varchar(255), "two" varchar(255), "three" varchar(255), "four" varchar(255), "five" varchar(255), "six" varchar(255), "seven" varchar(255), "eight" varchar(255), "nine" varchar(255), "ten" varchar(255), "eleven" varchar(255), "twelve" varchar(255), "thirteen" varchar(255), "fourteen" varchar(255), "created_at" datetime, "updated_at" datetime)
110
+ SQL (0.1ms)  SELECT name
111
+ FROM sqlite_master
112
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
113
+ 
114
+ SQL (1.4ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
115
+ SQL (0.0ms) PRAGMA index_list("schema_migrations")
116
+ SQL (27.8ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
117
+ SQL (0.1ms)  SELECT name
118
+ FROM sqlite_master
119
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
120
+ 
121
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
122
+ SQL (1.1ms) INSERT INTO "schema_migrations" (version) VALUES ('20110724201117')
123
+ SQL (1.1ms) INSERT INTO "schema_migrations" (version) VALUES ('20110624115516')
124
+ SQL (0.6ms)  SELECT name
125
+ FROM sqlite_master
126
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
127
+ 
128
+ SQL (0.3ms) SELECT name
129
+ FROM sqlite_master
130
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
131
+ SQL (0.2ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
132
+ Migrating to CreateFoos (20110624115516)
133
+ Migrating to CreateFakeCollections (20110724201117)
134
+ Migrating to RenameFakeCollectionToFake (20110724201548)
135
+ SQL (0.1ms) select sqlite_version(*)
136
+ SQL (16.0ms) ALTER TABLE "fake_collections" RENAME TO "fakes"
137
+ SQL (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES ('20110724201548')
138
+ SQL (0.3ms)  SELECT name
139
+ FROM sqlite_master
140
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
141
+ 
142
+ SQL (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
143
+ SQL (0.1ms)  SELECT name
144
+ FROM sqlite_master
145
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
146
+ 
147
+ SQL (0.0ms) PRAGMA index_list("fakes")
148
+ SQL (0.1ms) PRAGMA index_list("foos")
149
+ SQL (0.4ms) select sqlite_version(*)
150
+ SQL (0.2ms) SELECT name
151
+ FROM sqlite_master
152
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
153
+ SQL (0.1ms)  SELECT name
154
+ FROM sqlite_master
155
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
156
+ 
157
+ SQL (0.2ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
158
+ SQL (0.1ms)  SELECT name
159
+ FROM sqlite_master
160
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
161
+ 
162
+ SQL (0.0ms) PRAGMA index_list("fakes")
163
+ SQL (0.0ms) PRAGMA index_list("foos")
164
+ SQL (0.2ms) select sqlite_version(*)
165
+ SQL (0.1ms)  SELECT name
166
+ FROM sqlite_master
167
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
168
+ 
169
+ SQL (1.8ms) CREATE TABLE "fakes" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "value" varchar(255), "text" varchar(255), "created_at" datetime, "updated_at" datetime)
170
+ SQL (0.1ms)  SELECT name
171
+ FROM sqlite_master
172
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
173
+ 
174
+ SQL (1.8ms) CREATE TABLE "foos" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "one" varchar(255), "two" varchar(255), "three" varchar(255), "four" varchar(255), "five" varchar(255), "six" varchar(255), "seven" varchar(255), "eight" varchar(255), "nine" varchar(255), "ten" varchar(255), "eleven" varchar(255), "twelve" varchar(255), "thirteen" varchar(255), "fourteen" varchar(255), "created_at" datetime, "updated_at" datetime)
175
+ SQL (0.2ms)  SELECT name
176
+ FROM sqlite_master
177
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
178
+ 
179
+ SQL (1.4ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
180
+ SQL (0.0ms) PRAGMA index_list("schema_migrations")
181
+ SQL (1.4ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
182
+ SQL (0.2ms)  SELECT name
183
+ FROM sqlite_master
184
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
185
+ 
186
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
187
+ SQL (1.9ms) INSERT INTO "schema_migrations" (version) VALUES ('20110724201548')
188
+ SQL (1.2ms) INSERT INTO "schema_migrations" (version) VALUES ('20110624115516')
189
+ SQL (1.2ms) INSERT INTO "schema_migrations" (version) VALUES ('20110724201117')
190
+ SQL (0.5ms)  SELECT name
191
+ FROM sqlite_master
192
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
193
+ 
194
+ SQL (0.1ms) SELECT name
195
+ FROM sqlite_master
196
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
197
+ SQL (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
198
+ Migrating to CreateFoos (20110624115516)
199
+ Migrating to CreateFakeCollections (20110724201117)
200
+ Migrating to RenameFakeCollectionToFake (20110724201548)
201
+ Migrating to CreateContinentCountryAndCityTables (20110725082530)
202
+ SQL (0.1ms) select sqlite_version(*)
203
+ SQL (0.5ms) CREATE TABLE "continents" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
204
+ SQL (0.1ms) CREATE TABLE "countries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "continent_id" integer, "name" varchar(255))
205
+ SQL (0.1ms) CREATE TABLE "cities" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "country_id" integer, "name" varchar(255)) 
206
+ SQL (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES ('20110725082530')
207
+ SQL (0.3ms)  SELECT name
208
+ FROM sqlite_master
209
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
210
+ 
211
+ SQL (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
212
+ SQL (0.1ms)  SELECT name
213
+ FROM sqlite_master
214
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
215
+ 
216
+ SQL (0.0ms) PRAGMA index_list("cities")
217
+ SQL (0.0ms) PRAGMA index_list("continents")
218
+ SQL (0.0ms) PRAGMA index_list("countries")
219
+ SQL (0.0ms) PRAGMA index_list("fakes")
220
+ SQL (0.0ms) PRAGMA index_list("foos")
221
+ SQL (0.5ms) select sqlite_version(*)
222
+ SQL (0.2ms) SELECT name
223
+ FROM sqlite_master
224
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
225
+ SQL (0.1ms)  SELECT name
226
+ FROM sqlite_master
227
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
228
+ 
229
+ SQL (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
230
+ SQL (0.1ms)  SELECT name
231
+ FROM sqlite_master
232
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
233
+ 
234
+ SQL (0.0ms) PRAGMA index_list("cities")
235
+ SQL (0.0ms) PRAGMA index_list("continents")
236
+ SQL (0.0ms) PRAGMA index_list("countries")
237
+ SQL (0.0ms) PRAGMA index_list("fakes")
238
+ SQL (0.0ms) PRAGMA index_list("foos")
239
+ SQL (0.2ms) select sqlite_version(*)
240
+ SQL (0.1ms) SELECT name
241
+ FROM sqlite_master
242
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
243
+ SQL (1.9ms) CREATE TABLE "cities" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "country_id" integer, "name" varchar(255)) 
244
+ SQL (0.1ms) SELECT name
245
+ FROM sqlite_master
246
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
247
+ SQL (1.4ms) CREATE TABLE "continents" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
248
+ SQL (0.1ms) SELECT name
249
+ FROM sqlite_master
250
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
251
+ SQL (1.7ms) CREATE TABLE "countries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "continent_id" integer, "name" varchar(255)) 
252
+ SQL (0.1ms) SELECT name
253
+ FROM sqlite_master
254
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
255
+ SQL (1.5ms) CREATE TABLE "fakes" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "value" varchar(255), "text" varchar(255), "created_at" datetime, "updated_at" datetime) 
256
+ SQL (0.2ms) SELECT name
257
+ FROM sqlite_master
258
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
259
+ SQL (1.9ms) CREATE TABLE "foos" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "one" varchar(255), "two" varchar(255), "three" varchar(255), "four" varchar(255), "five" varchar(255), "six" varchar(255), "seven" varchar(255), "eight" varchar(255), "nine" varchar(255), "ten" varchar(255), "eleven" varchar(255), "twelve" varchar(255), "thirteen" varchar(255), "fourteen" varchar(255), "created_at" datetime, "updated_at" datetime) 
260
+ SQL (0.1ms) SELECT name
261
+ FROM sqlite_master
262
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
263
+ SQL (1.7ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
264
+ SQL (0.0ms) PRAGMA index_list("schema_migrations")
265
+ SQL (1.8ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
266
+ SQL (0.1ms) SELECT name
267
+ FROM sqlite_master
268
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
269
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
270
+ SQL (1.4ms) INSERT INTO "schema_migrations" (version) VALUES ('20110725082530')
271
+ SQL (1.3ms) INSERT INTO "schema_migrations" (version) VALUES ('20110624115516')
272
+ SQL (1.2ms) INSERT INTO "schema_migrations" (version) VALUES ('20110724201117')
273
+ SQL (1.3ms) INSERT INTO "schema_migrations" (version) VALUES ('20110724201548')
@@ -15,11 +15,11 @@ class JudgeTest < ActionController::TestCase
15
15
  setup { get :new }
16
16
 
17
17
  should "include presence validation in data attribute" do
18
- assert_equal "presence", validators_from("input#foo_one").first["kind"]
18
+ assert_equal "presence", validators_from("select#foo_one").first["kind"]
19
19
  end
20
20
 
21
21
  should "include length (within range) validation in data attribute" do
22
- validators = validators_from("input#foo_two")
22
+ validators = validators_from("input#foo_two_foobar")
23
23
  assert_equal "length", validators.first["kind"]
24
24
  assert_equal Fixnum, validators.first["options"]["minimum"].class
25
25
  assert_equal Fixnum, validators.first["options"]["maximum"].class
@@ -27,12 +27,12 @@ class JudgeTest < ActionController::TestCase
27
27
  end
28
28
 
29
29
  should "include allow_blank validation in data attribute" do
30
- validators = validators_from("input#foo_two")
30
+ validators = validators_from("input#foo_two_foobar")
31
31
  assert validators.first["options"]["allow_blank"]
32
32
  end
33
33
 
34
34
  should "include exclusion validation in data atribute" do
35
- validators = validators_from("input#foo_three")
35
+ validators = validators_from("select#foo_three")
36
36
  assert_equal "exclusion", validators.first["kind"]
37
37
  assert_equal Array, validators.first["options"]["in"].class
38
38
  end
@@ -53,10 +53,21 @@ class JudgeTest < ActionController::TestCase
53
53
  end
54
54
 
55
55
  should "include format validator in data attribute" do
56
- validator = validators_from("textarea#foo_five").first
56
+ validator = validators_from("select#foo_five").first
57
57
  assert_equal "format", validator["kind"]
58
58
  assert_match /\(.+\:.+\)/, validator["options"]["without"]
59
59
  end
60
+
61
+ should "include acceptance validator in data attribute" do
62
+ validator = validators_from("input#foo_six").first
63
+ assert_equal "acceptance", validator["kind"]
64
+ assert validator["options"]["accept"]
65
+ end
66
+
67
+ should "include confirmation validator in data attribute" do
68
+ validator = validators_from("input#foo_seven").first
69
+ assert_equal "confirmation", validator["kind"]
70
+ end
60
71
  end
61
72
 
62
73
  def validators_from(input_selector)
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
7
+ - 3
8
8
  - 0
9
- version: 0.2.0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Joe Corcoran
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-07-21 00:00:00 +01:00
17
+ date: 2011-07-25 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -161,7 +161,8 @@ files:
161
161
  - lib/generators/judge/templates/judge.js
162
162
  - lib/generators/judge/templates/underscore.js
163
163
  - lib/judge.rb
164
- - lib/judge/helpers.rb
164
+ - lib/judge/form.rb
165
+ - lib/judge/utils.rb
165
166
  - lib/tasks/js_tests.rake
166
167
  - spec/javascripts/JudgeSpec.js
167
168
  - spec/javascripts/fixtures/form.html
@@ -178,6 +179,10 @@ files:
178
179
  - test/dummy/app/controllers/application_controller.rb
179
180
  - test/dummy/app/controllers/foos_controller.rb
180
181
  - test/dummy/app/helpers/application_helper.rb
182
+ - test/dummy/app/models/city.rb
183
+ - test/dummy/app/models/continent.rb
184
+ - test/dummy/app/models/country.rb
185
+ - test/dummy/app/models/fake.rb
181
186
  - test/dummy/app/models/foo.rb
182
187
  - test/dummy/app/views/foos/new.html.erb
183
188
  - test/dummy/app/views/layouts/application.html.erb
@@ -198,6 +203,9 @@ files:
198
203
  - test/dummy/config/routes.rb
199
204
  - test/dummy/db/development.sqlite3
200
205
  - test/dummy/db/migrate/20110624115516_create_foos.rb
206
+ - test/dummy/db/migrate/20110724201117_create_fake_collections.rb
207
+ - test/dummy/db/migrate/20110724201548_rename_fake_collection_to_fake.rb
208
+ - test/dummy/db/migrate/20110725082530_create_continent_country_and_city_tables.rb
201
209
  - test/dummy/db/schema.rb
202
210
  - test/dummy/db/test.sqlite3
203
211
  - test/dummy/log/development.log
@@ -231,7 +239,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
231
239
  requirements:
232
240
  - - ">="
233
241
  - !ruby/object:Gem::Version
234
- hash: -1767971986953238841
242
+ hash: 2587494504961944285
235
243
  segments:
236
244
  - 0
237
245
  version: "0"
@@ -256,6 +264,10 @@ test_files:
256
264
  - test/dummy/app/controllers/application_controller.rb
257
265
  - test/dummy/app/controllers/foos_controller.rb
258
266
  - test/dummy/app/helpers/application_helper.rb
267
+ - test/dummy/app/models/city.rb
268
+ - test/dummy/app/models/continent.rb
269
+ - test/dummy/app/models/country.rb
270
+ - test/dummy/app/models/fake.rb
259
271
  - test/dummy/app/models/foo.rb
260
272
  - test/dummy/config/application.rb
261
273
  - test/dummy/config/boot.rb
@@ -270,6 +282,9 @@ test_files:
270
282
  - test/dummy/config/initializers/session_store.rb
271
283
  - test/dummy/config/routes.rb
272
284
  - test/dummy/db/migrate/20110624115516_create_foos.rb
285
+ - test/dummy/db/migrate/20110724201117_create_fake_collections.rb
286
+ - test/dummy/db/migrate/20110724201548_rename_fake_collection_to_fake.rb
287
+ - test/dummy/db/migrate/20110725082530_create_continent_country_and_city_tables.rb
273
288
  - test/dummy/db/schema.rb
274
289
  - test/judge_test.rb
275
290
  - test/test_helper.rb
@@ -1,31 +0,0 @@
1
- module Judge
2
-
3
- module FieldHelpers
4
-
5
- include ActionView::Helpers::TagHelper
6
-
7
- %w{text_field text_area}.each do |type|
8
- helper = <<-END
9
- def validated_#{type}(method, options = {})
10
- validators = self.object.class.validators_on(method).collect{ |v| { :kind => v.kind.to_s, :options => v.options } }
11
- options = { "data-validate" => validators.to_json }.merge(options)
12
- @template.#{type}(self.object_name, method, options)
13
- end
14
- END
15
- class_eval helper, __FILE__, __LINE__
16
- end
17
-
18
- end
19
-
20
- module FormHelpers
21
-
22
- def validated_form_for(record_or_name_or_array, *args, &proc)
23
- options = args.extract_options!
24
- options[:html] ||= {}
25
- options[:html]["data-error-messages"] = I18n.t("errors.messages").to_json
26
- form_for(record_or_name_or_array, *(args << options), &proc)
27
- end
28
-
29
- end
30
-
31
- end