Skip to content

Commit

Permalink
Revert "Merge pull request formtastic#820 from twalpole/rails4"
Browse files Browse the repository at this point in the history
This reverts commit e4f3b04, reversing
changes made to 0f42a5c.

Work still exists in rails4 branch until ready to re-merge.
  • Loading branch information
justinfrench committed Mar 8, 2012
1 parent e4f3b04 commit 363d51e
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 81 deletions.
4 changes: 0 additions & 4 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,3 @@ end
appraise 'rails-3.2' do
gem 'rails', '~> 3.2.0'
end

appraise 'rails-4' do
gem 'rails', :git => 'git://github.com/rails/rails.git'
end
2 changes: 1 addition & 1 deletion formtastic.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.rubygems_version = %q{1.3.6}

s.add_dependency(%q<actionpack>, [">= 3.0"])
s.add_dependency(%q<actionpack>, ["~> 3.0"])

s.add_development_dependency(%q<rspec-rails>, ["~> 2.8.0"])
s.add_development_dependency(%q<rspec_tag_matchers>, [">= 1.0.0"])
Expand Down
7 changes: 0 additions & 7 deletions gemfiles/rails-4.gemfile

This file was deleted.

25 changes: 1 addition & 24 deletions lib/formtastic/inputs/boolean_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,32 +97,9 @@ def input_html_options_name
end

def checked?
if defined? ActionView::Helpers::InstanceTag
object && ActionView::Helpers::InstanceTag.check_box_checked?(object.send(method), checked_value)
else
object && boolean_checked?(object.send(method), checked_value)
end
object && ActionView::Helpers::InstanceTag.check_box_checked?(object.send(method), checked_value)
end

private

def boolean_checked?(value, checked_value)
case value
when TrueClass, FalseClass
value
when NilClass
false
when Integer
value != 0
when String
value == checked_value
when Array
value.include?(checked_value)
else
value.to_i != 0
end
end

end
end
end
2 changes: 1 addition & 1 deletion lib/formtastic/inputs/select_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def input_options
end

def input_html_options
extra_input_html_options.merge(super.reject {|k,v| k==:name && v.nil?} )
extra_input_html_options.merge(super)
end

def extra_input_html_options
Expand Down
2 changes: 1 addition & 1 deletion spec/builder/semantic_fields_for_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@

it 'should render errors on the nested inputs' do
@errors = mock('errors')
@errors.stub!(:[]).with(errors_matcher(:login)).and_return(['oh noes'])
@errors.stub!(:[]).with(:login).and_return(['oh noes'])
@bob.stub!(:errors).and_return(@errors)

concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
Expand Down
20 changes: 10 additions & 10 deletions spec/helpers/semantic_errors_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

describe 'when there is only one error on base' do
before do
@errors.stub!(:[]).with(errors_matcher(:base)).and_return(@base_error)
@errors.stub!(:[]).with(:base).and_return(@base_error)
end

it 'should render an unordered list' do
Expand All @@ -29,7 +29,7 @@

describe 'when there is more than one error on base' do
before do
@errors.stub!(:[]).with(errors_matcher(:base)).and_return(@base_errors)
@errors.stub!(:[]).with(:base).and_return(@base_errors)
end

it 'should render an unordered list' do
Expand All @@ -44,8 +44,8 @@

describe 'when there are errors on title' do
before do
@errors.stub!(:[]).with(errors_matcher(:title)).and_return(@title_errors)
@errors.stub!(:[]).with(errors_matcher(:base)).and_return([])
@errors.stub!(:[]).with(:title).and_return(@title_errors)
@errors.stub!(:[]).with(:base).and_return([])
end

it 'should render an unordered list' do
Expand All @@ -58,8 +58,8 @@

describe 'when there are errors on title and base' do
before do
@errors.stub!(:[]).with(errors_matcher(:title)).and_return(@title_errors)
@errors.stub!(:[]).with(errors_matcher(:base)).and_return(@base_error)
@errors.stub!(:[]).with(:title).and_return(@title_errors)
@errors.stub!(:[]).with(:base).and_return(@base_error)
end

it 'should render an unordered list' do
Expand All @@ -73,8 +73,8 @@

describe 'when there are no errors' do
before do
@errors.stub!(:[]).with(errors_matcher(:title)).and_return(nil)
@errors.stub!(:[]).with(errors_matcher(:base)).and_return(nil)
@errors.stub!(:[]).with(:title).and_return(nil)
@errors.stub!(:[]).with(:base).and_return(nil)
end

it 'should return nil' do
Expand All @@ -86,7 +86,7 @@

describe 'when there is one error on base and options with class is passed' do
before do
@errors.stub!(:[]).with(errors_matcher(:base)).and_return(@base_error)
@errors.stub!(:[]).with(:base).and_return(@base_error)
end

it 'should render an unordered list with given class' do
Expand All @@ -98,7 +98,7 @@

describe 'when :base is passed in as an argument' do
before do
@errors.stub!(:[]).with(errors_matcher(:base)).and_return(@base_error)
@errors.stub!(:[]).with(:base).and_return(@base_error)
end

it 'should ignore :base and only render base errors once' do
Expand Down
7 changes: 2 additions & 5 deletions spec/inputs/custom_input_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ def input_args
@method = :title
@options = {}
@proc = Proc.new {}
if Rails::VERSION::MAJOR == 4
@builder = Formtastic::FormBuilder.new(@object_name, @object, @template, @options)
else
@builder = Formtastic::FormBuilder.new(@object_name, @object, @template, @options, @proc)
end
@builder = Formtastic::FormBuilder.new(@object_name, @object, @template, @options, @proc)

[@builder, @template, @object, @object_name, @method, @options]
end

Expand Down
2 changes: 1 addition & 1 deletion spec/inputs/hidden_input_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

it "should not render inline errors" do
@errors = mock('errors')
@errors.stub!(:[]).with(errors_matcher(:secret)).and_return(["foo", "bah"])
@errors.stub!(:[]).with(:secret).and_return(["foo", "bah"])
@new_post.stub!(:errors).and_return(@errors)

concat(semantic_form_for(@new_post) do |builder|
Expand Down
26 changes: 1 addition & 25 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -413,31 +413,7 @@ def with_config(config_method_name, value, &block)
yield
Formtastic::FormBuilder.send(:"#{config_method_name}=", old_value)
end

class ToSMatcher
def initialize(str)
@str=str.to_s
end

def matches?(value)
value.to_s==@str
end

def failure_message_for_should
"Expected argument that converted to #{@str}"
end
end

def errors_matcher(method)
# In edge rails (Rails 4) tags store method_name as a string and index the errors object using a string
# therefore allow stubs to match on either string or symbol. The errors object calls to_sym on all index
# accesses so @object.errors[:abc] is equivalent to @object.errors["abc"]
if Rails::VERSION::MAJOR == 4
ToSMatcher.new(method)
else
method
end
end

end

::ActiveSupport::Deprecation.silenced = false
Expand Down
4 changes: 2 additions & 2 deletions spec/support/custom_macros.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ def it_should_apply_error_logic_for_input_type(type)
before do
@title_errors = ['must not be blank', 'must be longer than 10 characters', 'must be awesome']
@errors = mock('errors')
@errors.stub!(:[]).with(errors_matcher(:title)).and_return(@title_errors)
@errors.stub!(:[]).with(:title).and_return(@title_errors)
Formtastic::FormBuilder.file_metadata_suffixes.each do |suffix|
@errors.stub!(:[]).with(errors_matcher("title_#{suffix}".to_sym)).and_return(nil)
@errors.stub!(:[]).with("title_#{suffix}".to_sym).and_return(nil)
end
@new_post.stub!(:errors).and_return(@errors)
end
Expand Down

0 comments on commit 363d51e

Please sign in to comment.