dao 4.4.4 → 4.6.4

Sign up to get free protection for your applications and to get access to all the features.
data/test/form_test.rb CHANGED
@@ -12,6 +12,129 @@ Testing Dao::Form do
12
12
  assert{ new_named_form(:foo).name_for(:a, :b) == 'dao[foo][a.b]' }
13
13
  end
14
14
 
15
+ testing 'Form#select' do
16
+ #
17
+ form = new_form()
18
+ form.attributes.set :key => 42
19
+
20
+ #
21
+ html = assert{ form.select(:key) }
22
+ assert do
23
+ scmp(
24
+ html,
25
+ '<select name="dao[form][key]" class="dao" id="form_key"/>'
26
+ )
27
+ end
28
+
29
+ #
30
+ html = assert{ form.select(:key, :values => %w( a b c )) }
31
+ assert do
32
+ scmp(
33
+ html,
34
+ '<select name="dao[form][key]" class="dao" id="form_key"><option value="a">a</option><option value="b">b</option><option value="c">c</option></select>'
35
+ )
36
+ end
37
+
38
+ #
39
+ html = assert{ form.select(:key, :values => %w( A B C ).zip([1,2,3])) }
40
+ assert do
41
+ scmp(
42
+ html,
43
+ '<select name="dao[form][key]" class="dao" id="form_key"><option value="1">A</option><option value="2">B</option><option value="3">C</option></select>'
44
+ )
45
+ end
46
+
47
+ #
48
+ html = assert{ form.select(:key, :values => %w( a b c ), :blank => true) }
49
+ assert do
50
+ scmp(
51
+ html,
52
+ '<select name="dao[form][key]" class="dao" id="form_key"><option></option><option value="a">a</option><option value="b">b</option><option value="c">c</option></select>'
53
+ )
54
+ end
55
+
56
+ #
57
+ html = assert{ form.select(:key, :values => %w( a b c ), :blank => nil) }
58
+ assert do
59
+ scmp(
60
+ html,
61
+ '<select name="dao[form][key]" class="dao" id="form_key"><option></option><option value="a">a</option><option value="b">b</option><option value="c">c</option></select>'
62
+ )
63
+ end
64
+
65
+ #
66
+ html = assert{ form.select(:key, :values => %w( a b c ), :blank => 42) }
67
+ assert do
68
+ scmp(
69
+ html,
70
+ '<select name="dao[form][key]" class="dao" id="form_key"><option value="">42</option><option value="a">a</option><option value="b">b</option><option value="c">c</option></select>'
71
+ )
72
+ end
73
+
74
+ #
75
+ html = assert{ form.select(:key, :values => %w( a b c ), :blank => false) }
76
+ assert do
77
+ scmp(
78
+ html,
79
+ '<select name="dao[form][key]" class="dao" id="form_key"><option value="a">a</option><option value="b">b</option><option value="c">c</option></select>'
80
+ )
81
+ end
82
+
83
+ #
84
+ html = assert{ form.select(:key, :values => %w( a b c ), :selected => :b) }
85
+ assert do
86
+ scmp(
87
+ html,
88
+ '<select name="dao[form][key]" class="dao" id="form_key"><option value="a">a</option><option value="b" selected>b</option><option value="c">c</option></select>'
89
+ )
90
+ end
91
+
92
+ #
93
+ block = proc do |content, value, selected_value|
94
+ is_selected = value.to_s == selected_value
95
+ [content, value, is_selected]
96
+ end
97
+
98
+ html = assert{ form.select(:key, :values => [41, 42, 43], &block) }
99
+
100
+ assert do
101
+ scmp(
102
+ html,
103
+ '<select name="dao[form][key]" class="dao" id="form_key"><option value="41">41</option><option value="42" selected>42</option><option value="43">43</option></select>'
104
+ )
105
+ end
106
+
107
+ #
108
+ block = proc do |content, value|
109
+ is_selected = value.to_s == '42'
110
+ [content, value, is_selected]
111
+ end
112
+
113
+ html = assert{ form.select(:key, :values => [41, 42, 43], &block) }
114
+
115
+ assert do
116
+ scmp(
117
+ html,
118
+ '<select name="dao[form][key]" class="dao" id="form_key"><option value="41">41</option><option value="42" selected>42</option><option value="43">43</option></select>'
119
+ )
120
+ end
121
+
122
+ #
123
+ block = proc do |content, value|
124
+ is_selected = value.to_s == '42'
125
+ { :content => content, :value => value, :selected => is_selected }
126
+ end
127
+
128
+ html = assert{ form.select(:key, :values => [41, 42, 43], &block) }
129
+
130
+ assert do
131
+ scmp(
132
+ html,
133
+ '<select name="dao[form][key]" class="dao" id="form_key"><option value="41">41</option><option value="42" selected>42</option><option value="43">43</option></select>'
134
+ )
135
+ end
136
+ end
137
+
15
138
  protected
16
139
  def new_form
17
140
  assert{ Dao::Form.new }
data/test/helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
+
2
3
  class User < Map
3
4
  def id() self[:id] end
4
5
  def email() self[:email] end
@@ -10,6 +11,16 @@ end
10
11
 
11
12
  module Kernel
12
13
  private
14
+ def scmp(a, b)
15
+ if b == nil
16
+ puts
17
+ puts a
18
+ puts
19
+ true
20
+ else
21
+ a.to_s.gsub(/\s+/, '') == b.to_s.gsub(/\s+/, '')
22
+ end
23
+ end
13
24
  def current_user()
14
25
  User.current
15
26
  end
data/test/support_test.rb CHANGED
@@ -32,7 +32,6 @@ Testing Dao::Conducer do
32
32
  )
33
33
 
34
34
  assert{ Dao.normalize_parameters(params) }
35
- assert{ params[:dao] = :normalized }
36
35
 
37
36
  assert{ params[:foos].is_a?(Hash) }
38
37
  assert{ params[:foos][:k] == 'v' }
@@ -25,19 +25,40 @@ Testing Dao::Validations do
25
25
  testing 'that errors can relay from other each-able sources' do
26
26
  errors = Dao::Errors.new
27
27
 
28
- source =
28
+ messages = [
29
+ 'foo is fucked',
30
+ 'foo is fucked twice',
31
+ ]
32
+
33
+ model =
29
34
  assert do
30
- c = Class.new Hash do
31
- def self.human_attribute_name(*a) a.first.to_s end
35
+ model_class = Class.new(Hash) do
36
+ def self.human_attribute_name(*args)
37
+ args.first.to_s
38
+ end
39
+
40
+ def errors
41
+ @errors ||= ActiveModel::Errors.new(self)
42
+ end
32
43
  end
33
- m = c.new
34
- e = ActiveModel::Errors.new(m)
35
- e.add('foo', 'is fucked')
44
+ m = model_class.new
45
+ messages.each{|message| m.errors.add(:foo, message)}
46
+ m
36
47
  end
37
48
 
38
- assert{ errors.relay(source) }
49
+ [model, model.errors].each do |source|
50
+ assert{ errors.relay(source) }
51
+ assert{ errors.on(:foo) == messages }
52
+ assert{ errors.clear }
53
+
54
+ assert{ errors.relay(source, :key => :bar) }
55
+ assert{ errors.on(:bar) == messages }
56
+ assert{ errors.clear }
39
57
 
40
- assert{ errors.on(:foo) }
58
+ assert{ errors.relay(source, :prefix => [:a, :b, :c]) }
59
+ assert{ errors.on(:a, :b, :c, :foo) == messages }
60
+ assert{ errors.clear }
61
+ end
41
62
  end
42
63
 
43
64
  ## validations
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dao
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.4
4
+ version: 4.6.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-16 00:00:00.000000000 Z
12
+ date: 2013-03-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70365889599060 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,43 +21,79 @@ dependencies:
21
21
  version: '3.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70365889599060
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '3.1'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: map
27
- requirement: &70365889598300 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
31
36
  - !ruby/object:Gem::Version
32
- version: '5.4'
37
+ version: 6.0.0
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *70365889598300
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 6.0.0
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: fattr
38
- requirement: &70365889597440 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '2.2'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
39
57
  none: false
40
58
  requirements:
41
59
  - - ! '>='
42
60
  - !ruby/object:Gem::Version
43
61
  version: '2.2'
62
+ - !ruby/object:Gem::Dependency
63
+ name: coerce
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: 0.0.3
44
70
  type: :runtime
45
71
  prerelease: false
46
- version_requirements: *70365889597440
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 0.0.3
47
78
  - !ruby/object:Gem::Dependency
48
79
  name: tagz
49
- requirement: &70365889596360 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
50
81
  none: false
51
82
  requirements:
52
83
  - - ! '>='
53
84
  - !ruby/object:Gem::Version
54
- version: '9.3'
85
+ version: '9.6'
55
86
  type: :runtime
56
87
  prerelease: false
57
- version_requirements: *70365889596360
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '9.6'
58
94
  - !ruby/object:Gem::Dependency
59
95
  name: multi_json
60
- requirement: &70365889584580 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
61
97
  none: false
62
98
  requirements:
63
99
  - - ! '>='
@@ -65,10 +101,15 @@ dependencies:
65
101
  version: 1.0.3
66
102
  type: :runtime
67
103
  prerelease: false
68
- version_requirements: *70365889584580
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: 1.0.3
69
110
  - !ruby/object:Gem::Dependency
70
111
  name: uuidtools
71
- requirement: &70365889582220 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
72
113
  none: false
73
114
  requirements:
74
115
  - - ! '>='
@@ -76,10 +117,15 @@ dependencies:
76
117
  version: 2.1.2
77
118
  type: :runtime
78
119
  prerelease: false
79
- version_requirements: *70365889582220
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: 2.1.2
80
126
  - !ruby/object:Gem::Dependency
81
127
  name: wrap
82
- requirement: &70365889581580 !ruby/object:Gem::Requirement
128
+ requirement: !ruby/object:Gem::Requirement
83
129
  none: false
84
130
  requirements:
85
131
  - - ! '>='
@@ -87,32 +133,47 @@ dependencies:
87
133
  version: 1.5.0
88
134
  type: :runtime
89
135
  prerelease: false
90
- version_requirements: *70365889581580
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: 1.5.0
91
142
  - !ruby/object:Gem::Dependency
92
143
  name: rails_current
93
- requirement: &70365889581080 !ruby/object:Gem::Requirement
144
+ requirement: !ruby/object:Gem::Requirement
94
145
  none: false
95
146
  requirements:
96
147
  - - ! '>='
97
148
  - !ruby/object:Gem::Version
98
- version: '1.6'
149
+ version: 1.7.0
99
150
  type: :runtime
100
151
  prerelease: false
101
- version_requirements: *70365889581080
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: 1.7.0
102
158
  - !ruby/object:Gem::Dependency
103
159
  name: rails_nav
104
- requirement: &70365889580380 !ruby/object:Gem::Requirement
160
+ requirement: !ruby/object:Gem::Requirement
105
161
  none: false
106
162
  requirements:
107
163
  - - ! '>='
108
164
  - !ruby/object:Gem::Version
109
- version: 1.1.0
165
+ version: 1.3.0
110
166
  type: :runtime
111
167
  prerelease: false
112
- version_requirements: *70365889580380
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: 1.3.0
113
174
  - !ruby/object:Gem::Dependency
114
- name: rails_helper
115
- requirement: &70365889579660 !ruby/object:Gem::Requirement
175
+ name: rails_errors2html
176
+ requirement: !ruby/object:Gem::Requirement
116
177
  none: false
117
178
  requirements:
118
179
  - - ! '>='
@@ -120,7 +181,12 @@ dependencies:
120
181
  version: 1.3.0
121
182
  type: :runtime
122
183
  prerelease: false
123
- version_requirements: *70365889579660
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: 1.3.0
124
190
  description: ! 'description: dao kicks the ass'
125
191
  email: ara.t.howard@gmail.com
126
192
  executables: []
@@ -192,6 +258,7 @@ files:
192
258
  - test/api_test.rb
193
259
  - test/conducer_test.rb
194
260
  - test/data/han-solo.jpg
261
+ - test/errors_test.rb
195
262
  - test/form_test.rb
196
263
  - test/helper.rb
197
264
  - test/leak.rb
@@ -218,8 +285,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
218
285
  version: '0'
219
286
  requirements: []
220
287
  rubyforge_project: codeforpeople
221
- rubygems_version: 1.8.11
288
+ rubygems_version: 1.8.23
222
289
  signing_key:
223
290
  specification_version: 3
224
291
  summary: dao
225
292
  test_files: []
293
+ has_rdoc: