module ActiveLeonardo::Leosca::Rspec
Protected Instance Methods
attribute_to_factories(attribute)
click to toggle source
# File lib/generators/active_leonardo.rb, line 70 def attribute_to_factories(attribute) spaces = 34 space_association = " " * (spaces-11).abs space_sequence = " " * (spaces-attribute.name.size-11).abs space_other = " " * (spaces-attribute.name.size).abs name = case attribute.type when :references, :belongs_to then "#{singular_table_name[0..0]}.association#{space_association}" when :boolean, :datetime, :time, :timestamp then "#{singular_table_name[0..0]}.#{attribute.name}#{space_other}" else "#{singular_table_name[0..0]}.sequence(:#{attribute.name})#{space_sequence}" end value = case attribute.type when :boolean then "true" when :integer then "{|n| n }" when :float, :decimal then "{|n| n }" when :references, :belongs_to then ":#{attribute.name}" when :date then "{|n| n.month.ago }" when :datetime then "#{Time.now.strftime("%Y-%m-%d %H:%M:%S.000")}".inspect when :time, :timestamp then "#{Time.now.strftime("%H:%M:%S.000")}".inspect else "{|n| \"#{attribute.name.titleize}\#{n}\" }" end " #{name}#{value}" end
attribute_to_requests(attribute, object_id=nil)
click to toggle source
# File lib/generators/active_leonardo.rb, line 93 def attribute_to_requests(attribute, object_id=nil) object_id ||= "#{singular_table_name}_#{attribute.name}" object_id = object_id.gsub('#', "\#{#{singular_table_name}.id}").gsub('name', attribute.name) case attribute.type when :boolean then "check \"#{object_id}\" if #{singular_table_name}.#{attribute.name}" when :references, :belongs_to then "select #{singular_table_name}.#{attribute.name}.name, :from => \"#{object_id}_id\"" when :datetime, :time, :timestamp then "" when :date then "fill_in \"#{object_id}\", :with => #{singular_table_name}.#{attribute.name}.strftime('%d-%m-%Y')" else "fill_in \"#{object_id}\", :with => #{singular_table_name}.#{attribute.name}" end end
fill_form_with_values(object_id=nil)
click to toggle source
# File lib/generators/active_leonardo.rb, line 134 def fill_form_with_values(object_id=nil) items = [] attributes.each{|a|items << " #{attribute_to_requests(a, object_id)}"} items end
get_attr_to_check(view=:list)
click to toggle source
# File lib/generators/active_leonardo.rb, line 126 def get_attr_to_check(view=:list) case view when :something else attributes.each{|a| case a.type when :string, :text then return a.name end} attributes.each{|a| case a.type when :references, :belongs_to, :datetime then nil else return a.name end} end end
get_attr_to_match(view=:list)
click to toggle source
# File lib/generators/active_leonardo.rb, line 106 def get_attr_to_match(view=:list) #attributes.each do |attribute| # case attribute.type # when :string, :text then # return "have_content(#{singular_table_name}.#{attribute.name})", # "have_no_content(#{singular_table_name}.#{attribute.name})" # end #end attr = get_attr_to_check(view) return "have_content(#{singular_table_name}.#{attr})", "have_no_content(#{singular_table_name}.#{attr})" if attr #If there are not string or text attributes case view when :list return "have_xpath('//table/tbody/tr')", "have_no_xpath('//table/tbody/tr')" when :show return "have_xpath('//table/tbody/tr')", "have_no_xpath('//table/tbody/tr')" end end