dsl_accessor 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +0 -0
- data/Manifest.txt +9 -0
- data/README.txt +97 -0
- data/Rakefile +49 -0
- data/lib/dsl_accessor/version.rb +9 -0
- data/lib/dsl_accessor.rb +52 -0
- data/setup.rb +1585 -0
- data/test/dsl_accessor_test.rb +120 -0
- data/test/test_helper.rb +3 -0
- metadata +72 -0
@@ -0,0 +1,120 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class DslAccessorTest < Test::Unit::TestCase
|
4
|
+
class CoolActiveRecord
|
5
|
+
dsl_accessor :primary_key
|
6
|
+
dsl_accessor :table_name
|
7
|
+
end
|
8
|
+
|
9
|
+
class Item < CoolActiveRecord
|
10
|
+
end
|
11
|
+
|
12
|
+
class LegacyItem < CoolActiveRecord
|
13
|
+
primary_key :itcd
|
14
|
+
table_name :item
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def test_accessor_without_initialization
|
19
|
+
assert_equal nil, Item.primary_key
|
20
|
+
assert_equal nil, Item.table_name
|
21
|
+
|
22
|
+
Item.primary_key :itcd
|
23
|
+
Item.table_name :item
|
24
|
+
|
25
|
+
assert_equal :itcd, Item.primary_key
|
26
|
+
assert_equal :item, Item.table_name
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_accessor_with_initialization
|
30
|
+
assert_equal :itcd, LegacyItem.primary_key
|
31
|
+
assert_equal :item, LegacyItem.table_name
|
32
|
+
|
33
|
+
LegacyItem.primary_key :item_id
|
34
|
+
LegacyItem.table_name :item_table
|
35
|
+
|
36
|
+
assert_equal :item_id, LegacyItem.primary_key
|
37
|
+
assert_equal :item_table, LegacyItem.table_name
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
class DslDefaultAccessorTest < Test::Unit::TestCase
|
43
|
+
|
44
|
+
class CoolActiveRecord
|
45
|
+
dsl_accessor :primary_key, :default=>"id"
|
46
|
+
dsl_accessor :table_name, :default=>proc{|klass| klass.name.demodulize.underscore.pluralize}
|
47
|
+
end
|
48
|
+
|
49
|
+
class Item < CoolActiveRecord
|
50
|
+
end
|
51
|
+
|
52
|
+
class User < CoolActiveRecord
|
53
|
+
end
|
54
|
+
|
55
|
+
class Folder
|
56
|
+
dsl_accessor :array_folder, :default=>[]
|
57
|
+
dsl_accessor :hash_folder, :default=>{}
|
58
|
+
end
|
59
|
+
|
60
|
+
class SubFolder < Folder
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_default_accessor_with_string
|
64
|
+
assert_equal "id", Item.primary_key
|
65
|
+
assert_equal "id", User.primary_key
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_default_accessor_with_proc
|
69
|
+
assert_equal "items", Item.table_name
|
70
|
+
assert_equal "users", User.table_name
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_default_accessor_should_duplicate_empty_array_or_hash
|
74
|
+
Folder.array_folder << 1
|
75
|
+
Folder.hash_folder[:name] = "maiha"
|
76
|
+
|
77
|
+
assert_equal([1], Folder.array_folder)
|
78
|
+
assert_equal({:name=>"maiha"}, Folder.hash_folder)
|
79
|
+
|
80
|
+
assert_equal([], SubFolder.array_folder)
|
81
|
+
assert_equal({}, SubFolder.hash_folder)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
class DslOverwritenDefaultAccessorTest < Test::Unit::TestCase
|
87
|
+
class CoolActiveRecord
|
88
|
+
dsl_accessor :primary_key, :default=>"id"
|
89
|
+
dsl_accessor :table_name, :default=>proc{|klass| klass.name.demodulize.underscore.pluralize}
|
90
|
+
end
|
91
|
+
|
92
|
+
class Item < CoolActiveRecord
|
93
|
+
primary_key :item_id
|
94
|
+
table_name :item_table
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_overwrite_default_accessor
|
98
|
+
assert_equal :item_id, Item.primary_key
|
99
|
+
assert_equal :item_table, Item.table_name
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
class DslWriterAccessorTest < Test::Unit::TestCase
|
105
|
+
class Item
|
106
|
+
dsl_accessor :primary_key, :writer=>proc{|value| value.to_s}
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_string_writer
|
110
|
+
assert_equal "", Item.primary_key
|
111
|
+
|
112
|
+
Item.primary_key :id
|
113
|
+
assert_equal "id", Item.primary_key
|
114
|
+
|
115
|
+
Item.primary_key "id"
|
116
|
+
assert_equal "id", Item.primary_key
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.0
|
3
|
+
specification_version: 1
|
4
|
+
name: dsl_accessor
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.1.0
|
7
|
+
date: 2007-01-16 00:00:00 -08:00
|
8
|
+
summary: This gem gives hybrid accessor class methods to classes by DSL like definition.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: anna@wota.jp
|
12
|
+
homepage: http://dsl-accessor.rubyforge.org
|
13
|
+
rubyforge_project: dsl-accessor
|
14
|
+
description: This gem gives hybrid accessor class methods to classes by DSL like definition.
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Maiha
|
31
|
+
- Alex Wayne
|
32
|
+
files:
|
33
|
+
- History.txt
|
34
|
+
- Manifest.txt
|
35
|
+
- README.txt
|
36
|
+
- Rakefile
|
37
|
+
- setup.rb
|
38
|
+
- lib/dsl_accessor.rb
|
39
|
+
- lib/dsl_accessor/version.rb
|
40
|
+
- test/test_helper.rb
|
41
|
+
- test/dsl_accessor_test.rb
|
42
|
+
test_files:
|
43
|
+
- test/dsl_accessor_test.rb
|
44
|
+
rdoc_options: []
|
45
|
+
|
46
|
+
extra_rdoc_files: []
|
47
|
+
|
48
|
+
executables: []
|
49
|
+
|
50
|
+
extensions: []
|
51
|
+
|
52
|
+
requirements: []
|
53
|
+
|
54
|
+
dependencies:
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
version_requirement:
|
58
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 0.0.0
|
63
|
+
version:
|
64
|
+
- !ruby/object:Gem::Dependency
|
65
|
+
name: hoe
|
66
|
+
version_requirement:
|
67
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 1.1.7
|
72
|
+
version:
|