judge 1.5.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +273 -14
- data/app/assets/javascripts/judge.js +391 -0
- data/app/controllers/judge/validations_controller.rb +9 -0
- data/app/models/judge/validation.rb +53 -0
- data/config/routes.rb +3 -0
- data/lib/generators/judge/install/install_generator.rb +42 -0
- data/lib/judge.rb +13 -8
- data/lib/judge/config.rb +39 -0
- data/lib/judge/controller.rb +35 -0
- data/lib/judge/each_validator.rb +5 -4
- data/lib/judge/engine.rb +5 -0
- data/lib/judge/form_builder.rb +19 -24
- data/lib/judge/html.rb +5 -7
- data/lib/judge/message_collection.rb +2 -1
- data/lib/judge/message_config.rb +2 -1
- data/lib/judge/validator.rb +3 -1
- data/lib/judge/validator_collection.rb +1 -1
- data/lib/judge/version.rb +2 -2
- data/lib/tasks/judge_tasks.rake +4 -0
- data/{lib/generators/judge/templates → vendor/assets/javascripts}/json2.js +4 -5
- data/{lib/generators/judge/templates → vendor/assets/javascripts}/underscore.js +451 -285
- metadata +94 -87
- data/.gitignore +0 -9
- data/.travis.yml +0 -21
- data/Gemfile +0 -3
- data/Rakefile +0 -11
- data/judge.gemspec +0 -23
- data/lib/generators/judge/judge_generator.rb +0 -21
- data/lib/generators/judge/templates/judge.js +0 -330
- data/spec/each_validator_spec.rb +0 -17
- data/spec/form_builder_spec.rb +0 -68
- data/spec/html_spec.rb +0 -14
- data/spec/javascripts/JudgeSpec.js +0 -509
- data/spec/javascripts/fixtures/form.html +0 -538
- data/spec/javascripts/helpers/customMatchers.js +0 -20
- data/spec/javascripts/helpers/jasmine-jquery.js +0 -204
- data/spec/javascripts/helpers/jquery-1.5.1.min.js +0 -18
- data/spec/javascripts/helpers/json2.js +0 -487
- data/spec/javascripts/helpers/underscore.js +0 -1060
- data/spec/javascripts/support/jasmine.yml +0 -79
- data/spec/javascripts/support/jasmine_config.rb +0 -6
- data/spec/javascripts/support/jasmine_runner.rb +0 -21
- data/spec/javascripts/support/runner.js +0 -51
- data/spec/message_collection_spec.rb +0 -73
- data/spec/setup.rb +0 -75
- data/spec/support/factories.rb +0 -23
- data/spec/support/locale/en.yml +0 -18
- data/spec/support/setup.rb +0 -72
- data/spec/support/spec_helper.rb +0 -13
- data/spec/support/validators/city_validator.rb +0 -9
- data/spec/validator_collection_spec.rb +0 -21
- data/spec/validator_spec.rb +0 -33
@@ -1,79 +0,0 @@
|
|
1
|
-
# src_files
|
2
|
-
#
|
3
|
-
# Return an array of filepaths relative to src_dir to include before jasmine specs.
|
4
|
-
# Default: []
|
5
|
-
#
|
6
|
-
# EXAMPLE:
|
7
|
-
#
|
8
|
-
# src_files:
|
9
|
-
# - lib/source1.js
|
10
|
-
# - lib/source2.js
|
11
|
-
# - dist/**/*.js
|
12
|
-
#
|
13
|
-
src_files:
|
14
|
-
- spec/javascripts/helpers/jquery-1.5.1.min.js
|
15
|
-
- spec/javascripts/helpers/json2.js
|
16
|
-
- spec/javascripts/helpers/underscore.js
|
17
|
-
- lib/generators/judge/templates/judge.js
|
18
|
-
|
19
|
-
# stylesheets
|
20
|
-
#
|
21
|
-
# Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.
|
22
|
-
# Default: []
|
23
|
-
#
|
24
|
-
# EXAMPLE:
|
25
|
-
#
|
26
|
-
# stylesheets:
|
27
|
-
# - css/style.css
|
28
|
-
# - stylesheets/*.css
|
29
|
-
#
|
30
|
-
stylesheets:
|
31
|
-
|
32
|
-
# helpers
|
33
|
-
#
|
34
|
-
# Return an array of filepaths relative to spec_dir to include before jasmine specs.
|
35
|
-
# Default: ["helpers/**/*.js"]
|
36
|
-
#
|
37
|
-
# EXAMPLE:
|
38
|
-
#
|
39
|
-
# helpers:
|
40
|
-
# - helpers/**/*.js
|
41
|
-
#
|
42
|
-
helpers:
|
43
|
-
- helpers/jasmine-jquery.js
|
44
|
-
- helpers/customMatchers.js
|
45
|
-
|
46
|
-
# spec_files
|
47
|
-
#
|
48
|
-
# Return an array of filepaths relative to spec_dir to include.
|
49
|
-
# Default: ["**/*[sS]pec.js"]
|
50
|
-
#
|
51
|
-
# EXAMPLE:
|
52
|
-
#
|
53
|
-
# spec_files:
|
54
|
-
# - **/*[sS]pec.js
|
55
|
-
#
|
56
|
-
spec_files:
|
57
|
-
- JudgeSpec.js
|
58
|
-
|
59
|
-
# src_dir
|
60
|
-
#
|
61
|
-
# Source directory path. Your src_files must be returned relative to this path. Will use root if left blank.
|
62
|
-
# Default: project root
|
63
|
-
#
|
64
|
-
# EXAMPLE:
|
65
|
-
#
|
66
|
-
# src_dir: public
|
67
|
-
#
|
68
|
-
src_dir:
|
69
|
-
|
70
|
-
# spec_dir
|
71
|
-
#
|
72
|
-
# Spec directory path. Your spec_files must be returned relative to this path.
|
73
|
-
# Default: spec/javascripts
|
74
|
-
#
|
75
|
-
# EXAMPLE:
|
76
|
-
#
|
77
|
-
# spec_dir: spec/javascripts
|
78
|
-
#
|
79
|
-
spec_dir:
|
@@ -1,21 +0,0 @@
|
|
1
|
-
$:.unshift(ENV['JASMINE_GEM_PATH']) if ENV['JASMINE_GEM_PATH'] # for gem testing purposes
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'jasmine'
|
5
|
-
jasmine_config_overrides = File.expand_path(File.join(File.dirname(__FILE__), 'jasmine_config.rb'))
|
6
|
-
require jasmine_config_overrides if File.exist?(jasmine_config_overrides)
|
7
|
-
require 'rspec'
|
8
|
-
|
9
|
-
|
10
|
-
jasmine_config = Jasmine::Config.new
|
11
|
-
spec_builder = Jasmine::SpecBuilder.new(jasmine_config)
|
12
|
-
|
13
|
-
should_stop = false
|
14
|
-
|
15
|
-
RSpec.configuration.after(:suite) do
|
16
|
-
spec_builder.stop if should_stop
|
17
|
-
end
|
18
|
-
|
19
|
-
spec_builder.start
|
20
|
-
should_stop = true
|
21
|
-
spec_builder.declare_suites
|
@@ -1,51 +0,0 @@
|
|
1
|
-
var casper = require('casper').create(),
|
2
|
-
path = casper.cli.args[0],
|
3
|
-
colorizer = require('colorizer').create(),
|
4
|
-
data;
|
5
|
-
|
6
|
-
casper
|
7
|
-
.start(path)
|
8
|
-
.then(function() {
|
9
|
-
this.waitForSelector('.finished-at', function() {
|
10
|
-
data = this.evaluate(readResults);
|
11
|
-
});
|
12
|
-
})
|
13
|
-
.run(function() {
|
14
|
-
this.echo(fmtTitle(data.desc, data.status));
|
15
|
-
if (data.messages.length > 0) {
|
16
|
-
this.echo(data.messages.join('\n\n') + '\n', colorType(data.status));
|
17
|
-
}
|
18
|
-
this.exit(data.status);
|
19
|
-
});
|
20
|
-
|
21
|
-
var readResults = function() {
|
22
|
-
var desc = document.querySelector('.runner .description').innerHTML,
|
23
|
-
msgs = [],
|
24
|
-
status = 0;
|
25
|
-
if (document.querySelector('.runner.failed')) {
|
26
|
-
var f = document.querySelectorAll('.spec.failed');
|
27
|
-
for (var i = 0, l = f.length; i < l; i += 1) {
|
28
|
-
var msg = ' ' + (i + 1) + '. '
|
29
|
-
+ f[i].querySelector('.description').title
|
30
|
-
+ ' (' + f[i].querySelector('.messages .resultMessage').innerHTML + ')';
|
31
|
-
msgs.push(msg);
|
32
|
-
};
|
33
|
-
status = 1;
|
34
|
-
};
|
35
|
-
return { desc: desc, messages: msgs, status: status };
|
36
|
-
};
|
37
|
-
|
38
|
-
var fmtTitle = function(string, status) {
|
39
|
-
var fail = (status === 1);
|
40
|
-
string = colorizer.format(string, {
|
41
|
-
fg: (fail ? 'red' : 'green'),
|
42
|
-
bold: true,
|
43
|
-
underscore: !!fail
|
44
|
-
});
|
45
|
-
string = '\n' + string + '\n';
|
46
|
-
return string;
|
47
|
-
};
|
48
|
-
|
49
|
-
var colorType = function(status) {
|
50
|
-
return (status === 1) ? 'WARNING' : 'INFO';
|
51
|
-
};
|
@@ -1,73 +0,0 @@
|
|
1
|
-
require "support/spec_helper"
|
2
|
-
|
3
|
-
describe Judge::MessageCollection do
|
4
|
-
|
5
|
-
let(:user) { FactoryGirl.build(:user) }
|
6
|
-
|
7
|
-
it "has to_hash method which returns messages hash" do
|
8
|
-
amv = User.validators_on(:name).first
|
9
|
-
message_collection = Judge::MessageCollection.new(user, :name, amv)
|
10
|
-
message_collection.should respond_to :to_hash
|
11
|
-
message_collection.to_hash.should be_a Hash
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "base messages" do
|
15
|
-
it "adds correct base message to messages hash" do
|
16
|
-
amv = User.validators_on(:name).first
|
17
|
-
messages = Judge::MessageCollection.new(user, :name, amv).to_hash
|
18
|
-
messages[:blank].should eql "Name must not be blank"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe "options messages" do
|
23
|
-
it "adds correct optional messages to messages hash when present (length)" do
|
24
|
-
amv = User.validators_on(:username).first
|
25
|
-
messages = Judge::MessageCollection.new(user, :username, amv).to_hash
|
26
|
-
messages[:too_long].should eql "Username is too long (must be less than 10 characters)"
|
27
|
-
end
|
28
|
-
|
29
|
-
it "adds correct optional messages to messages hash when present (numericality)" do
|
30
|
-
amv = User.validators_on(:age).first
|
31
|
-
messages = Judge::MessageCollection.new(user, :age, amv).to_hash
|
32
|
-
messages[:greater_than].should eql "Age must be greater than 13"
|
33
|
-
end
|
34
|
-
|
35
|
-
it "adds nothing to messages hash when optional messages not present" do
|
36
|
-
amv = User.validators_on(:name).first
|
37
|
-
messages = Judge::MessageCollection.new(user, :name, amv).to_hash
|
38
|
-
messages[:too_long].should be_nil
|
39
|
-
messages[:greater_than].should be_nil
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "blank messages" do
|
44
|
-
it "adds blank message to messages hash if applicable" do
|
45
|
-
amv = User.validators_on(:username).first
|
46
|
-
messages = Judge::MessageCollection.new(user, :username, amv).to_hash
|
47
|
-
messages[:blank].should eql "Username must not be blank"
|
48
|
-
end
|
49
|
-
|
50
|
-
it "does not add blank message to messages hash if allow_blank is true" do
|
51
|
-
amv = User.validators_on(:country).first
|
52
|
-
messages = Judge::MessageCollection.new(user, :country, amv).to_hash
|
53
|
-
messages[:blank].should be_nil
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe "integer messages" do
|
58
|
-
it "adds not_an_integer message to messages hash if only_integer is true" do
|
59
|
-
amv = User.validators_on(:age).first
|
60
|
-
messages = Judge::MessageCollection.new(user, :age, amv).to_hash
|
61
|
-
messages[:not_an_integer].should eql "Age must be an integer"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe "custom messages" do
|
66
|
-
it "adds custom messages to messages hash if declared inside EachValidator" do
|
67
|
-
amv = User.validators_on(:city).first
|
68
|
-
messages = Judge::MessageCollection.new(user, :city, amv).to_hash
|
69
|
-
messages[:not_valid_city].should eql "City must be an approved city"
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
data/spec/setup.rb
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
# setup ActiveRecord classes for tests
|
2
|
-
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
3
|
-
ActiveRecord::Schema.define(:version => 1) do
|
4
|
-
create_table :users do |t|
|
5
|
-
t.string :name
|
6
|
-
t.string :username
|
7
|
-
t.string :country
|
8
|
-
t.integer :age
|
9
|
-
t.text :bio
|
10
|
-
t.string :password
|
11
|
-
t.boolean :accepted
|
12
|
-
t.text :gender
|
13
|
-
t.date :dob
|
14
|
-
t.integer :team_id
|
15
|
-
t.string :time_zone
|
16
|
-
t.integer :discipline_id
|
17
|
-
t.string :city
|
18
|
-
end
|
19
|
-
create_table :teams do |t|
|
20
|
-
t.string :name
|
21
|
-
end
|
22
|
-
create_table :categories do |t|
|
23
|
-
t.string :name
|
24
|
-
end
|
25
|
-
create_table :sports do |t|
|
26
|
-
t.string :name
|
27
|
-
t.integer :category_id
|
28
|
-
end
|
29
|
-
create_table :disciplines do |t|
|
30
|
-
t.string :name
|
31
|
-
t.integer :sport_id
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
class User < ActiveRecord::Base
|
36
|
-
belongs_to :team
|
37
|
-
|
38
|
-
validates :name, :presence => true
|
39
|
-
validates :username, :length => { :maximum => 10 }
|
40
|
-
validates :country, :format => { :with => /[A-Za-z]/, :allow_blank => true }
|
41
|
-
validates :age, :numericality => { :only_integer => true, :greater_than => 13 }
|
42
|
-
validates :bio, :presence => true
|
43
|
-
validates :password, :format => { :with => /.+/ }, :confirmation => true
|
44
|
-
validates :accepted, :acceptance => true
|
45
|
-
validates :gender, :inclusion => { :in => ["male", "female", "other", "withheld"] }
|
46
|
-
validates :dob, :presence => true
|
47
|
-
validates :team_id, :presence => true
|
48
|
-
validates :time_zone, :presence => true
|
49
|
-
validates :discipline_id, :presence => true
|
50
|
-
validates :city, :city => true
|
51
|
-
end
|
52
|
-
|
53
|
-
class Team < ActiveRecord::Base; end
|
54
|
-
|
55
|
-
class Category < ActiveRecord::Base
|
56
|
-
has_many :sports
|
57
|
-
end
|
58
|
-
class Sport < ActiveRecord::Base
|
59
|
-
belongs_to :category
|
60
|
-
has_many :disciplines
|
61
|
-
end
|
62
|
-
class Discipline < ActiveRecord::Base
|
63
|
-
belongs_to :sport
|
64
|
-
belongs_to :user
|
65
|
-
end
|
66
|
-
|
67
|
-
# i18n locale file
|
68
|
-
I18n.load_path << File.expand_path("spec/support/locale/en.yml")
|
69
|
-
|
70
|
-
# hack to stop #url_for error
|
71
|
-
module ActionDispatch::Routing::PolymorphicRoutes
|
72
|
-
def polymorphic_path(record_or_hash_or_array, options = {})
|
73
|
-
""
|
74
|
-
end
|
75
|
-
end
|
data/spec/support/factories.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
FactoryGirl.define do
|
2
|
-
factory :user do
|
3
|
-
dob { Time.new(2011,11,5, 17,00,00) }
|
4
|
-
end
|
5
|
-
|
6
|
-
factory :team do
|
7
|
-
sequence(:name) {|n| "Team #{n}" }
|
8
|
-
end
|
9
|
-
|
10
|
-
factory :category do
|
11
|
-
sequence(:name) {|n| "Category #{n}" }
|
12
|
-
end
|
13
|
-
|
14
|
-
factory :sport do
|
15
|
-
sequence(:name) {|n| "Sport #{n}" }
|
16
|
-
category
|
17
|
-
end
|
18
|
-
|
19
|
-
factory :discipline do
|
20
|
-
sequence(:name) {|n| "Discipline #{n}" }
|
21
|
-
sport
|
22
|
-
end
|
23
|
-
end
|
data/spec/support/locale/en.yml
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
en:
|
2
|
-
activerecord:
|
3
|
-
errors:
|
4
|
-
models:
|
5
|
-
user:
|
6
|
-
attributes:
|
7
|
-
city:
|
8
|
-
not_valid_city: "%{attribute} must be an approved city"
|
9
|
-
errors:
|
10
|
-
attributes:
|
11
|
-
city:
|
12
|
-
not_valid_city: "This is never reached"
|
13
|
-
|
14
|
-
messages:
|
15
|
-
not_an_integer: "%{attribute} must be an integer"
|
16
|
-
blank: "%{attribute} must not be blank"
|
17
|
-
greater_than: "%{attribute} must be greater than %{count}"
|
18
|
-
too_long: "%{attribute} is too long (must be less than %{count} characters)"
|
data/spec/support/setup.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
# setup fake ActiveRecord class for tests
|
2
|
-
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
3
|
-
ActiveRecord::Schema.define(:version => 1) do
|
4
|
-
create_table :users do |t|
|
5
|
-
t.string :name
|
6
|
-
t.string :username
|
7
|
-
t.string :country
|
8
|
-
t.integer :age
|
9
|
-
t.text :bio
|
10
|
-
t.string :password
|
11
|
-
t.boolean :accepted
|
12
|
-
t.text :gender
|
13
|
-
t.date :dob
|
14
|
-
t.integer :team_id
|
15
|
-
t.string :time_zone
|
16
|
-
t.integer :discipline_id
|
17
|
-
t.string :foo
|
18
|
-
end
|
19
|
-
create_table :teams do |t|
|
20
|
-
t.string :name
|
21
|
-
end
|
22
|
-
create_table :categories do |t|
|
23
|
-
t.string :name
|
24
|
-
end
|
25
|
-
create_table :sports do |t|
|
26
|
-
t.string :name
|
27
|
-
t.integer :category_id
|
28
|
-
end
|
29
|
-
create_table :disciplines do |t|
|
30
|
-
t.string :name
|
31
|
-
t.integer :sport_id
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
class User < ActiveRecord::Base
|
36
|
-
belongs_to :team
|
37
|
-
|
38
|
-
validates :name, :presence => true
|
39
|
-
validates :username, :length => { :maximum => 10 }
|
40
|
-
validates :country, :format => { :with => /[A-Za-z]/, :allow_blank => true }
|
41
|
-
validates :age, :numericality => { :only_integer => true, :greater_than => 13 }
|
42
|
-
validates :bio, :presence => true
|
43
|
-
validates :password, :format => { :with => /.+/ }, :confirmation => true
|
44
|
-
validates :accepted, :acceptance => true
|
45
|
-
validates :gender, :inclusion => { :in => ["male", "female", "other", "withheld"] }
|
46
|
-
validates :dob, :presence => true
|
47
|
-
validates :team_id, :presence => true
|
48
|
-
validates :time_zone, :presence => true
|
49
|
-
validates :discipline_id, :presence => true
|
50
|
-
validates :foo, :foo => true
|
51
|
-
end
|
52
|
-
|
53
|
-
class Team < ActiveRecord::Base; end
|
54
|
-
|
55
|
-
class Category < ActiveRecord::Base
|
56
|
-
has_many :sports
|
57
|
-
end
|
58
|
-
class Sport < ActiveRecord::Base
|
59
|
-
belongs_to :category
|
60
|
-
has_many :disciplines
|
61
|
-
end
|
62
|
-
class Discipline < ActiveRecord::Base
|
63
|
-
belongs_to :sport
|
64
|
-
belongs_to :user
|
65
|
-
end
|
66
|
-
|
67
|
-
# hack to stop #url_for error
|
68
|
-
module ActionDispatch::Routing::PolymorphicRoutes
|
69
|
-
def polymorphic_path(record_or_hash_or_array, options = {})
|
70
|
-
""
|
71
|
-
end
|
72
|
-
end
|
data/spec/support/spec_helper.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require "bundler/setup"
|
2
|
-
require "active_record"
|
3
|
-
require "action_view"
|
4
|
-
require "judge"
|
5
|
-
require "rspec"
|
6
|
-
require "factory_girl"
|
7
|
-
require "support/validators/city_validator"
|
8
|
-
require "setup"
|
9
|
-
require "support/factories"
|
10
|
-
|
11
|
-
RSpec.configure do |config|
|
12
|
-
config.color_enabled = true
|
13
|
-
end
|