From 361c5c5714910691d0dc066a4040144d7fcaba03 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Fri, 23 Nov 2012 11:37:18 -0500 Subject: [PATCH] add smore more fun --- .../attributes_builder.rb | 8 +-- lib/semantic_rails_view_helpers/capybara.rb | 54 ++++++++++++++++++- 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/lib/semantic_rails_view_helpers/attributes_builder.rb b/lib/semantic_rails_view_helpers/attributes_builder.rb index 991096a..b7dccd2 100644 --- a/lib/semantic_rails_view_helpers/attributes_builder.rb +++ b/lib/semantic_rails_view_helpers/attributes_builder.rb @@ -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 diff --git a/lib/semantic_rails_view_helpers/capybara.rb b/lib/semantic_rails_view_helpers/capybara.rb index c5cfa36..60c0039 100644 --- a/lib/semantic_rails_view_helpers/capybara.rb +++ b/lib/semantic_rails_view_helpers/capybara.rb @@ -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