merb-helpers 1.0.15 → 1.1.0.pre

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -5,13 +5,14 @@ A plugin for the Merb Web framework that provides different view helpers.
5
5
 
6
6
  To use this plugin in merb in your app
7
7
 
8
- config/dependencies.rb
8
+ edit:
9
+ ./Gemfile
9
10
 
10
- #...
11
+ add the li:
12
+ gem "merb-helpers"
11
13
 
12
- dependency "merb-helpers"
13
-
14
- #...
14
+ run:
15
+ gem bundle
15
16
 
16
17
  # TODO: describe date_time_helpers, form_helpers, tag_helpers
17
18
 
data/Rakefile CHANGED
@@ -1,73 +1,65 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "..", "rake_helpers"))
2
-
3
- ##############################################################################
4
- # Package && release
5
- ##############################################################################
6
- RUBY_FORGE_PROJECT = "merb"
7
- PROJECT_URL = "http://merbivore.com"
8
- PROJECT_SUMMARY = "Helper support for Merb"
9
- PROJECT_DESCRIPTION = PROJECT_SUMMARY
10
-
11
- GEM_AUTHOR = "Michael D. Ivey"
12
- GEM_EMAIL = "ivey@gweezlebur.com"
13
-
14
- GEM_NAME = "merb-helpers"
15
- PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
16
- GEM_VERSION = Merb::VERSION + PKG_BUILD
17
-
18
- RELEASE_NAME = "REL #{GEM_VERSION}"
19
-
20
- require "extlib/tasks/release"
21
-
22
- spec = Gem::Specification.new do |s|
23
- s.rubyforge_project = RUBY_FORGE_PROJECT
24
- s.name = GEM_NAME
25
- s.version = GEM_VERSION
26
- s.platform = Gem::Platform::RUBY
27
- s.has_rdoc = true
28
- s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
29
- s.summary = PROJECT_SUMMARY
30
- s.description = PROJECT_DESCRIPTION
31
- s.author = GEM_AUTHOR
32
- s.email = GEM_EMAIL
33
- s.homepage = PROJECT_URL
34
- s.add_dependency('merb-core', "~> #{Merb::VERSION}")
35
- s.require_path = 'lib'
36
- s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
37
- end
1
+ require 'rubygems'
2
+ require 'rake'
38
3
 
39
- Rake::GemPackageTask.new(spec) do |pkg|
40
- pkg.gem_spec = spec
41
- end
4
+ # Assume a typical dev checkout to fetch the current merb-core version
5
+ require File.expand_path('../../merb-core/lib/merb-core/version', __FILE__)
42
6
 
43
- desc "Install the gem"
44
- task :install do
45
- Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
46
- end
7
+ # Load this library's version information
8
+ require File.expand_path('../lib/merb-helpers/version', __FILE__)
47
9
 
48
- desc "Uninstall the gem"
49
- task :uninstall do
50
- Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
51
- end
52
10
 
53
- desc "Create a gemspec file"
54
- task :gemspec do
55
- File.open("#{GEM_NAME}.gemspec", "w") do |file|
56
- file.puts spec.to_ruby
11
+ begin
12
+
13
+ gem 'jeweler', '~> 1.4'
14
+ require 'jeweler'
15
+
16
+ Jeweler::Tasks.new do |gemspec|
17
+
18
+ gemspec.version = Merb::Helpers::VERSION
19
+
20
+ gemspec.name = "merb-helpers"
21
+ gemspec.description = "Merb plugin containing view helpers"
22
+ gemspec.summary = "Merb plugin that provides helpers for writing HTML templates"
23
+
24
+ gemspec.authors = [ "Michael D. Ivey" ]
25
+ gemspec.email = "ivey@gweezlebur.com"
26
+ gemspec.homepage = "http://merbivore.com/"
27
+
28
+ gemspec.files = %w(LICENSE Rakefile README TODO) + Dir['{lib,spec}/**/*']
29
+
30
+ # Runtime dependencies
31
+ gemspec.add_dependency 'merb-core', "~> #{Merb::VERSION}"
32
+
33
+ # Development dependencies
34
+ gemspec.add_development_dependency 'rspec', '>= 1.2.9'
35
+
57
36
  end
37
+
38
+ Jeweler::GemcutterTasks.new
39
+
40
+ rescue LoadError
41
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
58
42
  end
59
43
 
60
- desc "Run all examples (or a specific spec with TASK=xxxx)"
61
- Spec::Rake::SpecTask.new('spec') do |t|
62
- t.spec_opts = ["-cfs"]
63
- t.spec_files = begin
64
- if ENV["TASK"]
65
- ENV["TASK"].split(',').map { |task| "spec/**/#{task}_spec.rb" }
66
- else
67
- FileList['spec/**/*_spec.rb']
68
- end
69
- end
44
+ require 'spec/rake/spectask'
45
+ Spec::Rake::SpecTask.new(:spec) do |spec|
46
+ spec.spec_opts << '--options' << 'spec/spec.opts' if File.exists?('spec/spec.opts')
47
+ spec.libs << 'lib' << 'spec'
48
+ spec.spec_files = FileList['spec/**/*_spec.rb']
49
+ end
50
+
51
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
52
+ spec.libs << 'lib' << 'spec'
53
+ spec.pattern = 'spec/**/*_spec.rb'
54
+ spec.rcov = true
70
55
  end
71
56
 
72
- desc 'Default: run spec examples'
73
- task :default => 'spec'
57
+ task :default => :spec
58
+
59
+ require 'rake/rdoctask'
60
+ Rake::RDocTask.new do |rdoc|
61
+ rdoc.rdoc_dir = 'rdoc'
62
+ rdoc.title = "test_gem #{Merb::Helpers::VERSION}"
63
+ rdoc.rdoc_files.include('README*')
64
+ rdoc.rdoc_files.include('lib/**/*.rb')
65
+ end
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  class Numeric
2
3
  module Transformer
3
4
 
@@ -36,7 +37,7 @@ class Numeric
36
37
  :separator => '.'
37
38
  },
38
39
  :currency => {
39
- :unit => '$;',
40
+ :unit => '$',
40
41
  :format => '%u%n',
41
42
  :precision => 2
42
43
  }
@@ -385,4 +386,4 @@ class Numeric
385
386
  end
386
387
 
387
388
 
388
- end
389
+ end
@@ -1,5 +1,6 @@
1
1
  require "date"
2
- require File.dirname(__FILE__) + '/date_time_formatting'
2
+ require 'merb-helpers/date_time_formatting'
3
+
3
4
  class Date
4
5
  include DateAndTimeFormatting
5
6
 
@@ -151,6 +151,6 @@ module OrdinalizedFormatting
151
151
  # ==== Examples
152
152
  # 5.days.ago.strftime_ordinalized('%b %d, %Y') # =>
153
153
  def strftime_ordinalized(fmt, format=nil)
154
- strftime(fmt.gsub(/(^|[^-])%d/, '\1_%d_')).gsub(/_(\d+)_/) { |s| s.to_i.ordinalize }
154
+ strftime(fmt.gsub(/(^|[^-])%d/, '\1_%d_')).gsub(/_(\d+)_/) { $1.to_i.ordinalize }
155
155
  end
156
156
  end
@@ -80,13 +80,13 @@ module Merb
80
80
  relative_date(times.first)
81
81
  else
82
82
  first = times.first; last = times.last; now = DateAndTime.time_class.now
83
- arr = [first.strftime_ordinalized('%b %d')]
84
- arr << ", #{first.year}" unless first.year == last.year
85
- arr << ' - '
86
- arr << last.strftime('%b') << ' ' unless first.year == last.year && first.month == last.month
87
- arr << last.day.ordinalize
88
- arr << ", #{last.year}" unless first.year == last.year && last.year == now.year
89
- arr.to_s
83
+ str = first.strftime_ordinalized('%b %d')
84
+ str << ", #{first.year}" unless first.year == last.year
85
+ str << ' - '
86
+ str << last.strftime('%b') << ' ' unless first.year == last.year && first.month == last.month
87
+ str << last.day.ordinalize
88
+ str << ", #{last.year}" unless first.year == last.year && last.year == now.year
89
+ str
90
90
  end
91
91
  end
92
92
 
@@ -114,17 +114,17 @@ module Merb
114
114
 
115
115
  else
116
116
  first = times.first; last = times.last; now = DateAndTime.time_class.now
117
- arr = [prettier_time(first)]
118
- arr << ' '
119
- arr << first.strftime_ordinalized('%b %d')
120
- arr << ", #{first.year}" unless first.year == last.year
121
- arr << ' - '
122
- arr << prettier_time(last)
123
- arr << ' '
124
- arr << last.strftime('%b') << ' ' unless first.year == last.year && first.month == last.month
125
- arr << last.day.ordinalize
126
- arr << ", #{last.year}" unless first.year == last.year && last.year == now.year
127
- arr.to_s
117
+ str = prettier_time(first)
118
+ str << ' '
119
+ str << first.strftime_ordinalized('%b %d')
120
+ str << ", #{first.year}" unless first.year == last.year
121
+ str << ' - '
122
+ str << prettier_time(last)
123
+ str << ' '
124
+ str << last.strftime('%b') << ' ' unless first.year == last.year && first.month == last.month
125
+ str << last.day.ordinalize
126
+ str << ", #{last.year}" unless first.year == last.year && last.year == now.year
127
+ str.to_s
128
128
  end
129
129
  end
130
130
 
@@ -1,4 +1,6 @@
1
- load File.dirname(__FILE__) / ".." / "tag_helpers.rb"
1
+ #load File.dirname(__FILE__) / ".." / "tag_helpers.rb"
2
+
3
+ require 'merb-helpers/tag_helpers'
2
4
 
3
5
  module Merb::Helpers::Form::Builder
4
6
 
@@ -116,7 +118,7 @@ module Merb::Helpers::Form::Builder
116
118
 
117
119
  def submit(value, attrs)
118
120
  attrs[:type] ||= "submit"
119
- attrs[:name] ||= "submit"
121
+ attrs[:name] ||= "form_submit"
120
122
  attrs[:value] ||= value
121
123
  update_unbound_controls(attrs, "submit")
122
124
  self_closing_tag(:input, attrs)
@@ -131,7 +133,7 @@ module Merb::Helpers::Form::Builder
131
133
  attrs[:method] = :post unless attrs[:method] == :get
132
134
  # Use a fake PUT if the object is not new, otherwise use the method
133
135
  # passed in. Defaults to :post if no method is set.
134
- method ||= (@obj.respond_to?(:new?) && !@obj.new?) || (@obj.respond_to?(:new_record?) && !@obj.new_record?) ? :put : :post
136
+ method ||= (@obj.respond_to?(:new_record?) && !@obj.new_record?) ? :put : :post
135
137
 
136
138
  attrs[:enctype] = "multipart/form-data" if attrs.delete(:multipart) || @multipart
137
139
 
@@ -140,7 +142,7 @@ module Merb::Helpers::Form::Builder
140
142
 
141
143
  # This can be overridden to use another method to fake out methods
142
144
  def fake_out_method(attrs, method)
143
- self_closing_tag(:input, :type => "hidden", :name => "_method", :value => method)
145
+ unbound_hidden_field(:name => "_method", :value => method)
144
146
  end
145
147
 
146
148
  def update_bound_controls(method, attrs, type)
@@ -375,8 +377,7 @@ module Merb::Helpers::Form::Builder
375
377
 
376
378
  def update_unbound_controls(attrs, type)
377
379
  if attrs[:name] && !attrs[:id]
378
- # '[' and ']' are illegal in HTML id attributes
379
- attrs.merge!(:id => attrs[:name].to_s.gsub(/(\[|\])/, '_'))
380
+ attrs.merge!(:id => valid_xhtml_id(attrs[:name]))
380
381
  end
381
382
  case type
382
383
  when "text", "radio", "password", "hidden", "checkbox", "file"
@@ -385,6 +386,10 @@ module Merb::Helpers::Form::Builder
385
386
  super
386
387
  end
387
388
 
389
+ def valid_xhtml_id(candidate)
390
+ candidate.to_s.gsub(/(\[|\])/, '_')
391
+ end
392
+
388
393
  def radio_group_item(method, attrs)
389
394
  unless attrs[:id]
390
395
  attrs.merge!(:id => "#{@name}_#{method}_#{attrs[:value]}")
@@ -400,21 +405,20 @@ module Merb::Helpers::Form::Builder
400
405
  obj ||= @obj
401
406
  return "" unless obj.respond_to?(:errors)
402
407
 
403
- sequel = !obj.errors.respond_to?(:each)
404
- errors = sequel ? obj.errors.full_messages : obj.errors
408
+ errors = obj.errors
405
409
 
406
410
  return "" if errors.empty?
407
411
 
408
412
  header_message = header % [errors.size, errors.size == 1 ? "" : "s"]
409
413
  markup = %Q{<div class='#{error_class}'>#{header_message}<ul>}
410
- errors.each {|err| markup << (build_li % (sequel ? err : err.join(" ")))}
414
+ errors.each {|err| markup << (build_li % err.join(" "))}
411
415
  markup << %Q{</ul></div>}
412
416
  end
413
417
 
414
418
  private
415
419
 
416
420
  def update_bound_controls(method, attrs, type)
417
- if @obj && !@obj.errors.on(method.to_sym).blank?
421
+ if @obj && !@obj.errors[method.to_sym].blank?
418
422
  add_css_class(attrs, "error")
419
423
  end
420
424
  super
@@ -20,7 +20,7 @@ module Merb::Helpers::Form
20
20
  if name.is_a?(String) || name.is_a?(Symbol)
21
21
  ivar = instance_variable_get("@#{name}")
22
22
  else
23
- ivar, name = name, name.class.to_s.snake_case
23
+ ivar, name = name, name.class.to_s.snake_case.split('::').last
24
24
  end
25
25
  builder ||= current_form_context.class if current_form_context
26
26
  (builder || self._default_builder).new(ivar, name, self)
@@ -1,5 +1,8 @@
1
- load File.dirname(__FILE__) / "form" / "helpers.rb"
2
- load File.dirname(__FILE__) / "form" / "builder.rb"
1
+ #load File.dirname(__FILE__) / "form" / "helpers.rb"
2
+ #load File.dirname(__FILE__) / "form" / "builder.rb"
3
+
4
+ require 'merb-helpers/form/helpers'
5
+ require 'merb-helpers/form/builder'
3
6
 
4
7
  module Merb::GlobalHelpers
5
8
  include Merb::Helpers::Form
@@ -0,0 +1,5 @@
1
+ module Merb
2
+ module Helpers
3
+ VERSION = '1.1.0.pre'.freeze
4
+ end
5
+ end
data/lib/merb-helpers.rb CHANGED
@@ -6,9 +6,10 @@ module Merb
6
6
  @@helpers_files = Dir["#{@@helpers_dir}/*_helpers.rb"].collect {|h| h.match(/\/(\w+)\.rb/)[1]}
7
7
 
8
8
  def self.load
9
- require @@helpers_dir + '/time_dsl'
10
- require @@helpers_dir + '/core_ext'
11
- require @@helpers_dir + '/core_ext/numeric'
9
+
10
+ require 'merb-helpers/time_dsl'
11
+ require 'merb-helpers/core_ext'
12
+ require 'merb-helpers/core_ext/numeric'
12
13
 
13
14
  if Merb::Plugins.config[:merb_helpers]
14
15
  config = Merb::Plugins.config[:merb_helpers]
@@ -28,6 +29,7 @@ module Merb
28
29
 
29
30
  # Load only specific helpers instead of loading all the helpers
30
31
  def self.load_helpers(helpers = @@helpers_files)
32
+ helpers = helpers.is_a?(Array) ? helpers : [helpers]
31
33
  helpers.each {|helper| Kernel.load(File.join(@@helpers_dir, "#{helper}.rb") )} # using load here allows specs to work
32
34
  end
33
35
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "String" do
4
4
  before :each do
@@ -0,0 +1,7 @@
1
+ module MyNamespace
2
+ class NamespacedFakeModel < FakeModel
3
+ def foo
4
+ 'named_foo'
5
+ end
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  <%= form_for @obj do %>
2
- <%= radio_group (:foo, ["foowee", "baree"]) %>
2
+ <%= radio_group(:foo, ["foowee", "baree"]) %>
3
3
  <% end =%>
@@ -1,4 +1,4 @@
1
1
  <%= form_for @obj do %>
2
- <%= radio_group (:foo, [:bar]) %>
3
- <%= radio_group (:foo, [{:value => 'bar', :label => 'Bar'}])%>
2
+ <%= radio_group(:foo, [:bar]) %>
3
+ <%= radio_group(:foo, [{:value => 'bar', :label => 'Bar'}])%>
4
4
  <% end =%>
@@ -0,0 +1,3 @@
1
+ <%= form_for(:obj, :action => "/some/url") do %>
2
+ Hello
3
+ <% end =%>
@@ -1,3 +1,3 @@
1
1
  <%= form_for @obj do %>
2
- <%= radio_group (:foo, ["foowee", "baree"]) %>
2
+ <%= radio_group(:foo, ["foowee", "baree"]) %>
3
3
  <% end =%>
@@ -20,7 +20,7 @@
20
20
  # See merb/specs/merb/router.rb for a fairly complete usage sample.
21
21
 
22
22
  Merb.logger.info("Compiling routes...")
23
- Merb::Router.prepare do |r|
23
+ Merb::Router.prepare do
24
24
  # RESTful routes
25
25
  # r.resources :posts
26
26
  resources :fake_models
@@ -31,8 +31,8 @@ Merb::Router.prepare do |r|
31
31
  # This is fine for most cases. If you're heavily using resource-based
32
32
  # routes, you may want to comment/remove this line to prevent
33
33
  # clients from calling your create or destroy actions with a GET
34
- r.default_routes
34
+ default_routes
35
35
 
36
36
  # Change this for your home page to be available at /
37
- # r.match('/').to(:controller => 'whatever', :action =>'index')
38
- end
37
+ # match('/').to(:controller => 'whatever', :action =>'index')
38
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "relative_date" do
4
4
  include Merb::Helpers::DateAndTime
@@ -237,11 +237,19 @@ describe "Date" do
237
237
  end
238
238
 
239
239
  it "Should do to_time conversion to utc by default" do
240
- @date.to_time.to_s.should == 'Fri Nov 02 00:00:00 UTC 2007'
240
+ if RUBY_VERSION < "1.9"
241
+ @date.to_time.to_s.should == 'Fri Nov 02 00:00:00 UTC 2007'
242
+ else
243
+ @date.to_time.to_s.should == '2007-11-02 00:00:00 UTC'
244
+ end
241
245
  end
242
246
 
243
247
  it "Should do to_time conversion to utc when param :utc is given" do
244
- @date.to_time(:utc).to_s.should == 'Fri Nov 02 00:00:00 UTC 2007'
248
+ if RUBY_VERSION < "1.9"
249
+ @date.to_time(:utc).to_s.should == 'Fri Nov 02 00:00:00 UTC 2007'
250
+ else
251
+ @date.to_time(:utc).to_s.should == '2007-11-02 00:00:00 UTC'
252
+ end
245
253
  end
246
254
 
247
255
  it "Should do to_time conversion to local time when param :local is given" do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  # Quick rundown of how these specs work
4
4
  # please read before hacking on this plugin
@@ -49,8 +49,7 @@ describe "error_messages_for" do
49
49
  @dm_obj = Object.new
50
50
  @sq_obj = Object.new
51
51
  @dm_errors = [["foo", "bar"],["baz","bat"]]
52
- @sq_errors = Object.new
53
- @sq_errors.stub!(:full_messages).and_return(["foo", "baz"])
52
+ @sq_errors = {:foo => ["bar"],:baz => ["bat"]}
54
53
  @dm_obj.stub!(:errors).and_return(@dm_errors)
55
54
  @dm_obj.stub!(:new_record?).and_return(false)
56
55
  @sq_obj.stub!(:errors).and_return(@sq_errors)
@@ -67,8 +66,8 @@ describe "error_messages_for" do
67
66
  it "should build default error messages for Sequel-like models" do
68
67
  errs = @c.error_messages_for(@sq_obj)
69
68
  errs.should include("<h2>Form submission failed because of 2 problems</h2>")
70
- errs.should include("<li>foo</li>")
71
- errs.should include("<li>baz</li>")
69
+ errs.should include("<li>foo bar</li>")
70
+ errs.should include("<li>baz bat</li>")
72
71
  end
73
72
 
74
73
  # it "should build default error messages for symbol" do
@@ -132,13 +131,13 @@ describe "form" do
132
131
  it "should fake out the put method if set" do
133
132
  ret = @c.render(:fake_put_if_set)
134
133
  ret.should have_selector("form[method=post]")
135
- ret.should have_selector("input[type=hidden][name=_method][value=put]")
134
+ ret.should have_selector("input[type=hidden][name=_method][value=put][class=hidden]")
136
135
  end
137
136
 
138
137
  it "should fake out the delete method if set" do
139
138
  ret = @c.render(:fake_delete_if_set)
140
139
  ret.should have_selector("form[method=post]")
141
- ret.should have_selector("input[type=hidden][name=_method][value=delete]")
140
+ ret.should have_selector("input[type=hidden][name=_method][value=delete][class=hidden]")
142
141
  end
143
142
 
144
143
  # TODO: Why is this required?
@@ -187,6 +186,13 @@ describe "form_for" do
187
186
  form.should_not have_selector("input[type=hidden][name=_method]")
188
187
  end
189
188
 
189
+ it "should use POST if the object passed in is nil" do
190
+ @c.instance_variable_set(:@obj, nil)
191
+ form = @c.render :advanced
192
+ form.should have_selector("form[method=post]")
193
+ form.should_not have_selector("input[type=hidden][value=put][name=_method]")
194
+ end
195
+
190
196
  it "should support PUT if the object passed in is not a new_record? via a hidden field" do
191
197
  form = @c.render :basic
192
198
  form.should have_selector("form[method=post]")
@@ -226,6 +232,13 @@ describe "fields_for" do
226
232
  r = @c.render :midstream
227
233
  r.should have_selector("input[id=fake_model_foo][name='fake_model[foo]'][type=text][extra=true]")
228
234
  end
235
+
236
+ it "should be able to handle namespaced models by setting name attribute to concrete class name" do
237
+ @c.instance_variable_set(:@obj2, MyNamespace::NamespacedFakeModel.new)
238
+ r = @c.render :midstream
239
+ r.should have_selector("input[type=text][value=foowee]")
240
+ r.should have_selector("input[name='namespaced_fake_model[foo]'][type=text][value=named_foo]")
241
+ end
229
242
  end
230
243
 
231
244
  describe "text_field" do
@@ -273,6 +286,12 @@ describe "bound_text_field" do
273
286
  r.should have_selector("input[type=text][id=fake_model_foo][name='fake_model[foo]'][value=foowee]")
274
287
  end
275
288
 
289
+ it "should take a namespaced model and return correct fieldname" do
290
+ @c.instance_variable_set(:@obj, MyNamespace::NamespacedFakeModel.new)
291
+ r = @c.render :basic
292
+ r.should have_selector("input[type=text][id=namespaced_fake_model_foo][name='namespaced_fake_model[foo]'][value=named_foo]")
293
+ end
294
+
276
295
  it "should take additional attributes and use them" do
277
296
  r = @c.render :basic
278
297
  r.should have_selector("input[type=text][name='fake_model[foo]'][value=foowee][bar='7']")
@@ -300,7 +319,7 @@ describe "bound_text_field" do
300
319
  model.stub!(:class).and_return("MyClass")
301
320
  model.stub!(:foo).and_return("FOO")
302
321
  errors = mock("errors")
303
- errors.should_receive(:on).with(:foo).and_return(true)
322
+ errors.should_receive(:[]).with(:foo).and_return(true)
304
323
 
305
324
  model.stub!(:errors).and_return(errors)
306
325
  @c.instance_variable_set(:@obj, model)
@@ -348,7 +367,7 @@ describe "bound_radio_button" do
348
367
  model.stub!(:class).and_return("MyClass")
349
368
  model.stub!(:foo).and_return("FOO")
350
369
  errors = mock("errors")
351
- errors.should_receive(:on).with(:foo).and_return(true)
370
+ errors.should_receive(:[]).with(:foo).and_return(true)
352
371
 
353
372
  model.stub!(:errors).and_return(errors)
354
373
  @c.instance_variable_set(:@obj, model)
@@ -419,7 +438,7 @@ describe "bound_password_field" do
419
438
  model.stub!(:class).and_return("MyClass")
420
439
  model.stub!(:foo).and_return("FOO")
421
440
  errors = mock("errors")
422
- errors.should_receive(:on).with(:foo).and_return(true)
441
+ errors.should_receive(:[]).with(:foo).and_return(true)
423
442
 
424
443
  model.stub!(:errors).and_return(errors)
425
444
 
@@ -583,8 +602,8 @@ describe "bound_check_box" do
583
602
  model.stub!(:baz).and_return("BAZ")
584
603
  model.stub!(:bat).and_return("BAT")
585
604
  errors = mock("errors")
586
- errors.should_receive(:on).with(:baz).and_return(true)
587
- errors.should_receive(:on).with(:bat).and_return(true)
605
+ errors.should_receive(:[]).with(:baz).and_return(true)
606
+ errors.should_receive(:[]).with(:bat).and_return(true)
588
607
 
589
608
  model.stub!(:errors).and_return(errors)
590
609
 
@@ -619,11 +638,16 @@ describe "hidden_field" do
619
638
  @c = HiddenFieldSpecs.new(Merb::Request.new({}))
620
639
  end
621
640
 
622
- it "should return a basic checkbox based on the values passed in" do
641
+ it "should return a basic hidden field based on the values passed in" do
623
642
  r = @c.render :basic
624
643
  r.should match_tag(:input, :type => "hidden", :id => "foo", :name => "foo", :value => "bar")
625
644
  end
626
645
 
646
+ it "should have class 'hidden' by default" do
647
+ r = @c.render :basic
648
+ r.should match_tag(:input, :type => "hidden", :class => 'hidden')
649
+ end
650
+
627
651
  it "should not render a label if the :label option is passed in" do
628
652
  res = @c.render :label
629
653
  res.should_not match(/<label>LABEL/)
@@ -670,7 +694,7 @@ describe "bound_hidden_field" do
670
694
  model.stub!(:class).and_return("MyClass")
671
695
  model.stub!(:foo).and_return("FOO")
672
696
  errors = mock("errors")
673
- errors.should_receive(:on).with(:foo).and_return(true)
697
+ errors.should_receive(:[]).with(:foo).and_return(true)
674
698
 
675
699
  model.stub!(:errors).and_return(errors)
676
700
 
@@ -788,7 +812,6 @@ describe "bound_radio_group" do
788
812
  r = @c.render :basic
789
813
  r.should match_tag(:input, :type => "radio", :id => "fake_model_foo_foowee", :name => "fake_model[foo]", :value => "foowee", :checked => "checked")
790
814
  r.should match_tag(:input, :type => "radio", :id => "fake_model_foo_baree", :name => "fake_model[foo]", :value => "baree")
791
- r.should_not match_tag(:checked => "checked")
792
815
  end
793
816
 
794
817
  it "should provide an additional label tag for each option in array-based options" do
@@ -1093,7 +1116,7 @@ describe "option tags" do
1093
1116
  it "should provide selected options by value" do
1094
1117
  r = @c.render :selected
1095
1118
  r.should match_tag( :option, :value => 'rabbit', :selected => 'selected', :content => 'Rabbit' )
1096
- r.should_not match_tag( :option, :value => 'chicken', :selected => '', :content => 'Chicken' )
1119
+ r.should_not match_tag( :option, :value => 'chicken', :selected => 'nil', :content => 'Chicken' )
1097
1120
  end
1098
1121
 
1099
1122
  it "should handle arrays for selected when :multiple is true" do
@@ -1228,7 +1251,7 @@ describe "submit" do
1228
1251
 
1229
1252
  it "should provide an additional label tag if the :label option is passed in" do
1230
1253
  r = @c.render :submit_with_label
1231
- r.should have_selector("input[type=submit][name=submit][value=Done]")
1254
+ r.should have_selector("input[type=submit][name=form_submit][value=Done]")
1232
1255
  r.should have_selector("label:contains('LABEL')")
1233
1256
  end
1234
1257
 
@@ -1379,4 +1402,4 @@ describe "escaping values" do
1379
1402
  r.should =~ /&amp;&quot;&lt;&gt;/
1380
1403
  end
1381
1404
 
1382
- end
1405
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  # Merb::Router.prepare do
4
4
  # default_routes
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "cycle" do
4
4
  include Merb::Helpers::Text
@@ -1,4 +1,5 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ # -*- encoding: utf-8 -*-
2
+ require 'spec_helper'
2
3
 
3
4
  describe "Numeric helpers" do
4
5