add smore more fun

This commit is contained in:
John Bintz 2012-11-23 11:37:18 -05:00
parent 58b42a7392
commit 361c5c5714
2 changed files with 57 additions and 5 deletions

View File

@ -18,17 +18,17 @@ module SemanticRailsViewHelpers
def field(field, options = {})
if options[:value]
value = options[:value]
raw_value = options[:value]
else
value = @object.send(field)
raw_value = @object.send(field)
end
value = raw_value
value = value.to_label if value.respond_to?(:to_label)
value = @context.content_tag(:data, value, 'data-field' => field)
if options[:as]
value = @context.render(:partial => "attributes/#{options[:as]}", :locals => { :object => @object, :field => field, :value => value })
value = @context.render(:partial => "attributes/#{options[:as]}", :locals => { :object => @object, :field => field, :raw_value => raw_value, :value => value })
end
(value or '').html_safe

View File

@ -1,4 +1,56 @@
def find_attribute(name)
find("[data-field='#{name}']")
attribute = find("[data-field='#{name}']")
yield attribute, @inputs[name] if block_given?
attribute
end
def find_input(name)
find("[name$='[#{name}]']")
end
def set_input(name, value)
@inputs ||= {}
@inputs[name] = value
find_input(name).set(value)
end
def find_attributes(*attrs)
attrs.each do |attr|
find_attribute(attr).text.should == @inputs[attr]
end
end
def find_submit
find('[type=submit]')
end
def find_action(action)
find("[data-action='#{action}']")
end
module Capybara
class ElementFound < StandardError
def initialize(search)
@search = search
end
def message
@search
end
end
end
def dont_find(search)
find(search)
raise Capybara::ElementFound.new(search)
rescue Capybara::ElementNotFound
true
end
def dont_find_object(object)
dont_find("[data-id='#{object.id}']")
end