alias 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,72 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper.rb')
2
+
3
+ class Alias::ValidatorTest < Test::Unit::TestCase
4
+ context "Validator" do
5
+ before(:all) { eval "class ::TestCreator < Alias::Creator; end"}
6
+ before(:each) { Alias::Validator.instance_eval "@validators = {}"}
7
+
8
+ def validate(options={})
9
+ creator = TestCreator.new
10
+ options.each {|k,v| creator.send("#{k}=",v)}
11
+ @validator.validate(creator, {}, :blah)
12
+ end
13
+
14
+ def validator_message
15
+ @validator.create_message(:blah)
16
+ end
17
+
18
+ def create_validator(options)
19
+ @validator = TestCreator.valid :num, options
20
+ end
21
+
22
+ def create_parent_validator(key)
23
+ Alias::Validator.register_validators [{:key=>key, :if=>lambda {|e| 'yo'}, :message=>lambda {|e| 'cool'}}]
24
+ @parent_validator = Alias::Validator.validators[key]
25
+ end
26
+
27
+ test "copies a validator when using a previous one" do
28
+ create_parent_validator :num
29
+ create_validator :if=>:num
30
+ @parent_validator.validate(TestCreator.new, {}, :blah).should == validate
31
+ end
32
+
33
+ test "inherits a validator's message when using a previous one" do
34
+ create_parent_validator :num
35
+ create_validator :if=>:num
36
+ validator_message.should == 'cool'
37
+ end
38
+
39
+ test "overrides an inherited message with explicit message" do
40
+ create_parent_validator :num
41
+ create_validator :if=>:num, :message=>lambda {|e| 'cooler'}
42
+ validator_message.should == 'cooler'
43
+ end
44
+
45
+ test "sets a default message if an invalid one is given" do
46
+ create_validator :if=>lambda {|e| 'yo'}, :message=>:blah
47
+ validator_message.should =~ /Validation failed/
48
+ end
49
+
50
+ test "with :with option sets proc arg" do
51
+ create_validator :if=>lambda {|e| 'yo'}, :with=>[:a, :b]
52
+ @validator.validation_proc.expects(:call).with(['a','c'])
53
+ @validator.validate(TestCreator.new, {:a=>'a', :b=>'c', :c=>'d'}, :c)
54
+ end
55
+
56
+ test "with :unless option negates result and changes message" do
57
+ create_validator :unless=>lambda {|e| true }, :message=>lambda {|e| "yo doesn't exist"}
58
+ validate.should == false
59
+ validator_message.should == 'yo already exists'
60
+ end
61
+
62
+ test "with :optional option can be forced" do
63
+ create_validator :if=>lambda { false }, :optional=>true
64
+ validate(:force=>true).should == true
65
+ end
66
+
67
+ test "without :optional option cannot be forced" do
68
+ create_validator :if=>lambda { false }
69
+ validate(:force=>true).should == false
70
+ end
71
+ end
72
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alias
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Gabriel Horner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-07 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Creates aliases for class methods, instance methods, constants, delegated methods and more. Aliases can be easily searched or saved as YAML config files to load later. Custom alias types are easy to create with the DSL Alias provides. Although Alias was created with the irb user in mind, any Ruby console program can hook into Alias for creating configurable aliases.
17
+ email: gabriel.horner@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE.txt
24
+ - README.rdoc
25
+ files:
26
+ - CHANGELOG.rdoc
27
+ - LICENSE.txt
28
+ - README.rdoc
29
+ - Rakefile
30
+ - VERSION.yml
31
+ - lib/alias.rb
32
+ - lib/alias/console.rb
33
+ - lib/alias/creator.rb
34
+ - lib/alias/creators/any_to_instance_method_creator.rb
35
+ - lib/alias/creators/class_method_creator.rb
36
+ - lib/alias/creators/class_to_instance_method_creator.rb
37
+ - lib/alias/creators/constant_creator.rb
38
+ - lib/alias/creators/instance_method_creator.rb
39
+ - lib/alias/manager.rb
40
+ - lib/alias/util.rb
41
+ - lib/alias/validator.rb
42
+ - test/alias_test.rb
43
+ - test/aliases.yml
44
+ - test/any_to_instance_method_creator_test.rb
45
+ - test/class_method_creator_test.rb
46
+ - test/class_to_instance_method_creator_test.rb
47
+ - test/console_test.rb
48
+ - test/constant_creator_test.rb
49
+ - test/creator_test.rb
50
+ - test/instance_method_creator_test.rb
51
+ - test/manager_test.rb
52
+ - test/test_helper.rb
53
+ - test/util_test.rb
54
+ - test/validator_test.rb
55
+ has_rdoc: true
56
+ homepage: http://tagaholic.me/alias/
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options:
61
+ - --charset=UTF-8
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
75
+ version:
76
+ requirements: []
77
+
78
+ rubyforge_project: tagaholic
79
+ rubygems_version: 1.3.2
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: Creates, manages and saves aliases for class methods, instance methods, constants, delegated methods and more.
83
+ test_files:
84
+ - test/alias_test.rb
85
+ - test/any_to_instance_method_creator_test.rb
86
+ - test/class_method_creator_test.rb
87
+ - test/class_to_instance_method_creator_test.rb
88
+ - test/console_test.rb
89
+ - test/constant_creator_test.rb
90
+ - test/creator_test.rb
91
+ - test/instance_method_creator_test.rb
92
+ - test/manager_test.rb
93
+ - test/test_helper.rb
94
+ - test/util_test.rb
95
+ - test/validator_test.rb