glue 0.0.1 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,214 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
2
+
3
+ require 'test/unit'
4
+
5
+ require 'glue'
6
+ require 'glue/property'
7
+ require 'glue/validation'
8
+
9
+ N::Property.type_checking = false
10
+
11
+ class TC_Validation < Test::Unit::TestCase # :nodoc: all
12
+
13
+ # Override the default error message
14
+ N::Validation::Errors.invalid_format = 'INVALID'
15
+
16
+ module Mixin
17
+ prop_accessor :value, String
18
+ validate_format :value, :format => /123/, :msg => 'mixin error'
19
+ end
20
+
21
+ class User
22
+ include Mixin
23
+
24
+ prop_accessor :name, String
25
+ validate_format :name, :format => /L.o/, :msg => 'per class override'
26
+ end
27
+
28
+ class Article
29
+ prop_accessor :name, String
30
+ validate_format :name, :format => /news/
31
+ end
32
+
33
+ class Dummy1
34
+ prop_accessor :test, Fixnum
35
+ prop_accessor :str, String
36
+ validate_value :test, :str
37
+ end
38
+
39
+ class Dummy2
40
+ prop_accessor :password, String
41
+ validate_confirmation :password
42
+ end
43
+
44
+ class Dummy3
45
+ prop_accessor :vmin, String
46
+ validate_length :vmin, :min => 2
47
+
48
+ prop_accessor :vmax, String
49
+ validate_length :vmax, :max => 3, :msg => 'LOOONG'
50
+
51
+ prop_accessor :vran, String
52
+ validate_length :vran, :range => 2..4, :msg_long => 'argh'
53
+
54
+ prop_accessor :vlen, String
55
+ validate_length :vlen, :length => 3, :msg => 'argh'
56
+ end
57
+
58
+ class Dummy4
59
+ prop_accessor :sex, String
60
+ validate_inclusion :sex, :in => %w{ Male Female }, :msg => 'huh?'
61
+
62
+ prop_accessor :age, Fixnum
63
+ validate_inclusion :age, :in => 5..99
64
+ end
65
+
66
+ class Dummy5
67
+ property :age, Fixnum
68
+ validate_numeric :age, :integer => true
69
+
70
+ property :rate, Float
71
+ validate_numeric :rate
72
+ end
73
+
74
+ # bug
75
+
76
+ class NoProp
77
+ include Mixin
78
+ validate_length :value, :min => 3
79
+ end
80
+
81
+ def test_validate_value
82
+ d = Dummy1.new
83
+
84
+ assert !d.valid?
85
+ assert_equal 2, d.errors.count
86
+ d.test = 1
87
+ assert !d.valid?
88
+ assert_equal 1, d.errors.count
89
+ d.str = 'yeah'
90
+ assert d.valid?
91
+ end
92
+
93
+ def test_validate_confirmation
94
+ d = Dummy2.new
95
+
96
+ assert_respond_to d, :password_confirmation
97
+
98
+ d.password = 'hello'
99
+ assert !d.valid?
100
+ d.password_confirmation = 'hel'
101
+ assert !d.valid?
102
+ d.password_confirmation = 'hello'
103
+ assert d.valid?
104
+ end
105
+
106
+ def test_validate_format
107
+ u = User.new
108
+
109
+ u.value = '1234'
110
+
111
+ u.name = 'George'
112
+ assert !u.valid?
113
+
114
+ assert_equal 'per class override', u.errors[:name].first
115
+
116
+ u.name = 'Leonard'
117
+ assert u.valid?
118
+
119
+ a = Article.new
120
+
121
+ a.name = 'In the news'
122
+ assert a.valid?
123
+
124
+ a.name = 'Sports'
125
+ assert !a.valid?
126
+
127
+ assert_equal 1, a.errors.count
128
+ assert_equal 1, a.errors.on(:name).size
129
+ assert_kind_of Array, a.errors[:name]
130
+
131
+ assert_equal 'INVALID', a.errors[:name].first
132
+
133
+ # test mixin
134
+
135
+ u.value = '543'
136
+ assert !u.valid?
137
+ end
138
+
139
+ def test_validate_length
140
+ d = Dummy3.new
141
+
142
+ d.vmin = 'q'
143
+ d.vmax = '2'
144
+ d.vlen = '123'
145
+ d.vran = '123'
146
+
147
+ assert !d.valid?
148
+ assert_equal 'Too short, must be more than 2 characters long', d.errors.on(:vmin).first
149
+ d.vmin = 'longer'
150
+ assert d.valid?
151
+
152
+ d.vmax = 'loooooooooooong'
153
+ assert !d.valid?
154
+ assert_equal 'LOOONG', d.errors.on(:vmax).first
155
+
156
+ d.vmax = nil
157
+ assert !d.valid?
158
+ assert_equal 'No value provided', d.errors.on(:vmax).first
159
+
160
+ d.vlen = '12'
161
+ assert !d.valid?
162
+ assert_equal 'argh', d.errors.on(:vlen).first
163
+
164
+ d.vlen = '1234565'
165
+ assert !d.valid?
166
+
167
+ d.vran = '1'
168
+ assert !d.valid?
169
+ assert_equal 'Too short, must be more than 2 characters long', d.errors.on(:vran).first
170
+
171
+ d.vran = '11111111'
172
+ assert !d.valid?
173
+ assert_equal 'argh', d.errors.on(:vran).first
174
+ end
175
+
176
+ def test_validate_inclusion
177
+ d = Dummy4.new
178
+
179
+ d.sex = 'Alien'
180
+ d.age = 1
181
+
182
+ assert !d.valid?
183
+ assert_equal 2, d.errors.count
184
+
185
+ d.sex = 'Male'
186
+ assert !d.valid?
187
+ assert_equal 1, d.errors.count
188
+
189
+ d.age = 110
190
+ assert !d.valid?
191
+ assert_equal 1, d.errors.count
192
+
193
+ d.age = 90
194
+ assert d.valid?
195
+ end
196
+
197
+ def test_validate_numeric
198
+ d = Dummy5.new
199
+
200
+ d.rate = 'Alien'
201
+ d.age = 'World'
202
+
203
+ assert !d.valid?
204
+ assert_equal 2, d.errors.count
205
+
206
+ d.rate = 3
207
+ assert !d.valid?
208
+ assert_equal 1, d.errors.count
209
+
210
+ d.rate = 1.2
211
+ d.age = 123
212
+ assert d.valid?
213
+ end
214
+ end
metadata CHANGED
@@ -1,97 +1,103 @@
1
1
  --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.8
3
+ specification_version: 1
2
4
  name: glue
3
5
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- platform: ruby
6
- authors:
7
- - Jordan Dobson
8
- autorequire:
9
- bindir: bin
10
- cert_chain: []
11
-
12
- date: 2009-08-18 00:00:00 -07:00
6
+ version: 0.13.0
7
+ date: 2005-03-17
8
+ summary: Glue utilities
9
+ require_paths:
10
+ - lib
11
+ email: gm@navel.gr
12
+ homepage: http://nitro.rubyforge.org
13
+ rubyforge_project: nitro
14
+ description: A collection of utilities and useful classes
15
+ autorequire: glue
13
16
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: httparty
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
24
- version:
25
- - !ruby/object:Gem::Dependency
26
- name: mocha
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: "0"
34
- version:
35
- - !ruby/object:Gem::Dependency
36
- name: hoe
37
- type: :development
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- version: 1.12.2
44
- version:
45
- description: |-
46
- The Glue gem enables posting to GlueNow.com API service using an account subdomain, username, password. In this version you can add a post by providing a title, body, optional author name and optional private settings. You can also access some basic info about a users account and check if their account info is valid.
47
-
48
- You can also request public posts from an account using the same RSS that powers the many Glue feeds.
49
- email:
50
- - jordan.dobson@madebysquad.com
51
- executables:
52
- - glue
53
- extensions: []
54
-
55
- extra_rdoc_files:
56
- - History.txt
57
- - Manifest.txt
58
- - README.txt
59
- files:
60
- - History.txt
61
- - Manifest.txt
62
- - README.txt
63
- - Rakefile
64
- - bin/glue
65
- - lib/glue.rb
66
- - test/test_glue.rb
17
+ bindir: bin
67
18
  has_rdoc: true
68
- homepage: http://Glue.RubyForge.org
69
- licenses: []
70
-
71
- post_install_message:
72
- rdoc_options:
73
- - --main
74
- - README.txt
75
- require_paths:
76
- - lib
77
- required_ruby_version: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - ">="
80
- - !ruby/object:Gem::Version
81
- version: "0"
82
- version:
83
- required_rubygems_version: !ruby/object:Gem::Requirement
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
84
20
  requirements:
85
- - - ">="
86
- - !ruby/object:Gem::Version
87
- version: "0"
21
+ -
22
+ - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 1.8.1
88
25
  version:
26
+ platform: ruby
27
+ authors:
28
+ - George Moschovitis
29
+ files:
30
+ - Rakefile
31
+ - INSTALL
32
+ - CHANGELOG
33
+ - README
34
+ - install.rb
35
+ - doc/LICENSE
36
+ - doc/AUTHORS
37
+ - doc/RELEASES
38
+ - lib/glue.rb
39
+ - lib/glue
40
+ - lib/glue/mixins.rb
41
+ - lib/glue/logger.rb
42
+ - lib/glue/pool.rb
43
+ - lib/glue/inflector.rb
44
+ - lib/glue/hash.rb
45
+ - lib/glue/number.rb
46
+ - lib/glue/time.rb
47
+ - lib/glue/property.rb
48
+ - lib/glue/misc.rb
49
+ - lib/glue/flexob.rb
50
+ - lib/glue/cache.rb
51
+ - lib/glue/string.rb
52
+ - lib/glue/object.rb
53
+ - lib/glue/array.rb
54
+ - lib/glue/validation.rb
55
+ - lib/glue/attribute.rb
56
+ - test/glue
57
+ - test/glue/tc_strings.rb
58
+ - test/glue/tc_property_type_checking.rb
59
+ - test/glue/tc_logger.rb
60
+ - test/glue/tc_validation.rb
61
+ - test/glue/tc_property.rb
62
+ - test/glue/tc_hash.rb
63
+ - test/glue/tc_attribute.rb
64
+ - test/glue/tc_property_mixins.rb
65
+ - test/glue/tc_cache.rb
66
+ - test/glue/tc_numbers.rb
67
+ test_files: []
68
+ rdoc_options:
69
+ - "--main"
70
+ - README
71
+ - "--title"
72
+ - Glue Documentation
73
+ - "--all"
74
+ - "--inline-source"
75
+ extra_rdoc_files:
76
+ - Rakefile
77
+ - INSTALL
78
+ - CHANGELOG
79
+ - README
80
+ executables: []
81
+ extensions: []
89
82
  requirements: []
90
-
91
- rubyforge_project: glue
92
- rubygems_version: 1.3.3
93
- signing_key:
94
- specification_version: 3
95
- summary: The Glue gem enables posting to GlueNow.com API service using an account subdomain, username, password
96
- test_files:
97
- - test/test_glue.rb
83
+ dependencies:
84
+ - !ruby/object:Gem::Dependency
85
+ name: extensions
86
+ version_requirement:
87
+ version_requirements: !ruby/object:Gem::Version::Requirement
88
+ requirements:
89
+ -
90
+ - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: "0.5"
93
+ version:
94
+ - !ruby/object:Gem::Dependency
95
+ name: flexmock
96
+ version_requirement:
97
+ version_requirements: !ruby/object:Gem::Version::Requirement
98
+ requirements:
99
+ -
100
+ - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 0.0.3
103
+ version:
data/History.txt DELETED
@@ -1,6 +0,0 @@
1
- === 1.0.0 / 2009-06-24
2
-
3
- * 1 major enhancement
4
-
5
- * Birthday!
6
-
data/Manifest.txt DELETED
@@ -1,7 +0,0 @@
1
- History.txt
2
- Manifest.txt
3
- README.txt
4
- Rakefile
5
- bin/glue
6
- lib/glue.rb
7
- test/test_glue.rb
data/README.txt DELETED
@@ -1,127 +0,0 @@
1
- = glue
2
-
3
- http://Glue.RubyForge.org
4
-
5
- http://GlueNow.com
6
-
7
- == DESCRIPTION:
8
-
9
- The Glue gem enables posting to GlueNow.com API service using an account subdomain, username, password. In this version you can add a post by providing a title, body, optional author name and optional private settings. You can also access some basic info about a users account and check if their account info is valid.
10
-
11
- You can also request public posts from an account using the same RSS that powers the many Glue feeds.
12
-
13
- == FEATURES/PROBLEMS:
14
-
15
- * To Add a new post Title & Body text must be included
16
- * Access info about an account with successful login:
17
- * Email Address
18
- * If they are an admin
19
- * Thier Author Name
20
- * Can check if a subdomain is valid and belongs to an account
21
- * Read all public posts
22
- * This Gem is throughly tested
23
- * Adding & Reading posts Only at this time
24
- * You can't editor delete a posts yet
25
- * No way to verify if a post has accepted the author name yet
26
-
27
-
28
- == SYNOPSIS:
29
-
30
- 1. Instantiate your account
31
-
32
- * Provide the subdomain, username and password for http://Your-Account.GlueNow.com
33
-
34
- account = Glue::API.new( "your-account", "j-username", "j-password" )
35
-
36
- 2. Check if the account subdomain is valid
37
-
38
- account.valid_site?
39
-
40
- 3. Get more info about the user's account
41
-
42
- response = account.user_info
43
-
44
- response #=> {"rsp"=>{"user"=>{"author"=>"Jordan Dobson","admin"=>"true","email"=>"jordandobson@gmail.com"},"stat"=>"ok"}}
45
-
46
- 4. Post your Content
47
-
48
- * Both Title and Body are required - Set to a variable to check the response
49
-
50
- response = account.post("My Title", "My Body")
51
-
52
- * You can also choose to set the post as private and/or use the optional Author Name
53
- * In this example we set false for not private and true to use the author name
54
-
55
- response = account.post("My Title", "My Body", false, true)
56
-
57
-
58
- 5. Get a success or error hash back
59
-
60
- * A Successful response would look like this
61
-
62
- response #=> {"rsp"=>{"post"=>{"title"=>"My Title","url"=>"http://bit.ly/sakIM","id"=>"14415","longurl"=>"http://jordandobson.com"},"stat"=>"ok"}}
63
-
64
- * A Error response would be empty like this
65
-
66
- response #=> {}
67
-
68
- ----
69
-
70
- 1. Instantiate your Reader with your account info
71
-
72
- * Provide the subdomain for http://Your-Account.GlueNow.com
73
-
74
- account = Glue::RSS.new( "your-account" )
75
-
76
- 2. Request posts from the RSS feed
77
-
78
- * If you want all of them don't include any limiting or range. Defaults to up to 999 posts on one page
79
-
80
- response = account.feed
81
-
82
- * If you want to limit the results include a limit (1-999) and which page (used for paging)
83
-
84
- response = account.feed(10, 3)
85
-
86
- 3. Get an RSS feed back or HTML page - These Examples are simplified to include most important nodes
87
-
88
- * A successful RSS response would look like
89
-
90
- response #=> {"rss"=>{"channel"=>{"item"=>{"pubDate"=>"Fri, 12 Sep 2008 00:00:00 +0000","title"=>"My Title","guid"=>"http://jordandobson.com#14415","dc:creator"=>"Jordan","description"=>"<p>My Body</p>","link"=>"http://jordandobson.com","source"=>"Glue"}}}}
91
-
92
- * A failed HTML responsed would look like
93
-
94
- response #=> {"html"=>{"head"=>{"title"=>"GLUE | Web + Mobile Content Publishing"},"body"=>"<p>Webpage Body</p>"}}
95
-
96
- == REQUIREMENTS:
97
-
98
- * Mechanize & HTTParty
99
-
100
- == INSTALL:
101
-
102
- * sudo gem install glue -include-dependencies
103
-
104
- == LICENSE:
105
-
106
- (The MIT License)
107
-
108
- Copyright (c) 2009 Squad, Inc.
109
-
110
- Permission is hereby granted, free of charge, to any person obtaining
111
- a copy of this software and associated documentation files (the
112
- 'Software'), to deal in the Software without restriction, including
113
- without limitation the rights to use, copy, modify, merge, publish,
114
- distribute, sublicense, and/or sell copies of the Software, and to
115
- permit persons to whom the Software is furnished to do so, subject to
116
- the following conditions:
117
-
118
- The above copyright notice and this permission notice shall be
119
- included in all copies or substantial portions of the Software.
120
-
121
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
122
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
123
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
124
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
125
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
126
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
127
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.