This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/formtastic/i18n.rb | |
SCOPES = [ | |
'soccer_team.player.update.name', | |
'soccer_team.update.name', | |
'soccer_team.player.name', | |
'soccer_team.name', | |
'player.name', | |
'name' | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/formtastic/i18n.rb | |
def translate(*args) | |
key = args.shift.to_sym | |
options = args.extract_options! | |
options.reverse_merge!(:default => DEFAULT_VALUES[key]) | |
options[:scope] = [DEFAULT_SCOPE, options[:scope]].flatten.compact | |
::I18n.translate(key, *(args << options)) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# actionpack/lib/action_view/base.rb | |
module ActionView | |
class Base | |
... | |
attr_accessor :output_buffer | |
... | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# actionpack/lib/action_view/helpers/text_helper.rb | |
def concat(string, unused_binding = nil) | |
if unused_binding | |
ActiveSupport::Deprecation.warn("The binding argument of #concat is no longer needed. Please remove it from your views and helpers.", caller) | |
end | |
output_buffer.safe_concat(string) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec/commit_button_spec.rb | |
describe 'SemanticFormBuilder#commit_button' do | |
... | |
before do | |
@output_buffer = '' | |
mock_everything | |
end | |
... | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec/commit_button_spec.rb | |
it 'should pass options given in :button_html to the button' do | |
@new_post.stub!(:new_record?).and_return(false) | |
semantic_form_for(@new_post) do |builder| | |
concat(builder.commit_button('text', :button_html => {:class => 'my_class', :id => 'my_id'})) | |
end | |
output_buffer.should have_tag('li.commit input#my_id') | |
output_buffer.should have_tag('li.commit input.my_class') | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Event < ActiveRecord::Base | |
validates_length_of :title, :minimum => 5 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> reflection = Event.reflect_on_validations_for(:title) | |
>> reflection[0].macro | |
=> :validates_length_of | |
>> reflection[0].options | |
=> { :minimum => 5 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/validation_reflection.rb | |
ActiveRecord::Base.class_eval do | |
include ::ActiveRecordExtensions::ValidationReflection | |
::ActiveRecordExtensions::ValidationReflection.load_config | |
::ActiveRecordExtensions::ValidationReflection.install(self) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/validation_reflection.rb | |
def install(base) | |
@@reflected_validations.each do |validation_type| | |
next if base.respond_to?(:"#{validation_type}_with_reflection") | |
ignore_subvalidations = false | |
if validation_type.kind_of?(::Hash) | |
ignore_subvalidations = validation_type[:ignore_subvalidations] | |
validation_type = validation_type[:method] | |
end |