class Pageify::PageObject

Attributes

full_selector[RW]
intend[RW]
name[RW]
parent[RW]
self_selector[RW]

Public Class Methods

create(raw_row) click to toggle source
# File lib/pageify/page_object.rb, line 24
def self.create (raw_row)
  name = raw_row.lstrip.split(":").first
  self_selector = raw_row.slice(raw_row.index(':')+1..-1)
  intend = raw_row.lspace
  PageObject.new(name,self_selector,intend)
end
new(name,self_selector,intend) click to toggle source
# File lib/pageify/page_object.rb, line 35
def initialize (name,self_selector,intend)
  @name = name
  @self_selector = self_selector
  @intend = intend
end

Public Instance Methods

all(*args) click to toggle source
# File lib/pageify/capybara/base.rb, line 25
def all(*args)
  page.all(selector,*args)
end
Also aliased as: find_all
click_on(child) click to toggle source
# File lib/pageify/capybara/bulk_actions.rb, line 27
def click_on child
  get_child(child).find.click 
  self
end
createChild(raw_row) click to toggle source
# File lib/pageify/page_object.rb, line 5
def createChild (raw_row)
  child = PageObject.create(raw_row)
  child.parent = self
  define_singleton_method(child.name) do |*arguments|
    unless arguments.eql? []
      child_selector = (child.self_selector % arguments).strip_quotes.strip
    else
      child_selector = (child.self_selector % '').strip_quotes.strip
    end
    if child_selector.start_with? "&"
      child.full_selector = @full_selector + child_selector.gsub(/^&/, "")
    else
      child.full_selector = @full_selector + " " + child_selector
    end
    child
  end
  return child
end
find(*args) click to toggle source
# File lib/pageify/capybara/base.rb, line 14
def find(*args)
  get_session.find(selector,*args)
end
find_all(*args)
Alias for: all
first(*args) click to toggle source
# File lib/pageify/capybara/base.rb, line 31
def first(*args)
  page.first(selector,*args)
end
run_block(&block) click to toggle source
# File lib/pageify/page_object.rb, line 41
def run_block (&block)
  @self_before_instance_eval = eval "self", block.binding
  instance_eval &block
end
selector() click to toggle source
# File lib/pageify/page_object.rb, line 31
def selector
  @full_selector.strip
end
set_fields(children_with_values_as_hash) click to toggle source
# File lib/pageify/capybara/bulk_actions.rb, line 32
def set_fields children_with_values_as_hash
  children_with_values_as_hash.each do |key,value|
    get_child(key).set value
  end
  self
end
should_have_disabled(fields) click to toggle source
# File lib/pageify/capybara/bulk_actions.rb, line 19
def should_have_disabled fields 
  process_fields(fields,Proc.new{|field| get_child(field).find.should be_disabled})
end
should_have_enabled(fields) click to toggle source
# File lib/pageify/capybara/bulk_actions.rb, line 15
def should_have_enabled fields 
  process_fields(fields,Proc.new{|field| get_child(field).find.should be_enabled})
end
should_match_fields(fields) click to toggle source
# File lib/pageify/capybara/bulk_actions.rb, line 5
def should_match_fields fields
  if fields.is_a?(Hash)
    match_fields fields
  else
    fields.hashes.each do |field|
      match_fields field 
    end
  end
end
should_not_have(fields) click to toggle source
# File lib/pageify/capybara/bulk_actions.rb, line 23
def should_not_have fields
  process_fields(fields,Proc.new{|field|page.should_not have_css get_selector(field)})
end
with_text(text) click to toggle source
# File lib/pageify/capybara/base.rb, line 35
def with_text(text)
  page.find(selector,:text=>text)
end

Private Instance Methods

get_child(children) click to toggle source
# File lib/pageify/capybara/bulk_actions.rb, line 62
def get_child children 
  children = children.to_s.gsub(" ","").underscore
  child_object = self
  children.split('.').each do |child|
    method_name = child.split('(')[0]
    arguments = child.split('(')[1].chomp(')').split(',') if child.include? '('
    child_object = arguments.present? ? child_object.send(method_name,*[*arguments]) : child_object.send(child)
  end
  child_object
end
get_selector(children) click to toggle source
# File lib/pageify/capybara/bulk_actions.rb, line 58
def get_selector children
  get_child(childeren).selector
end
match_fields(field) click to toggle source
# File lib/pageify/capybara/bulk_actions.rb, line 40
def match_fields field 
  field.each do|key,value|
    element = page.find(get_selector(key))
    if element.tag_name == 'input' && element[:type] == 'checkbox'
      value == 'true' ? element.should(be_checked) : element.should_not(be_checked)
    else
      element.should match value
    end
  end
end
process_fields(fields,block) click to toggle source
# File lib/pageify/capybara/bulk_actions.rb, line 51
def process_fields fields,block 
  fields = fields.is_a?(Array) ? fields : fields.raw.map{|x|x[0]}
  fields.each do |field|
    block.call(field)
  end
end