module RailsGwt::DSL

Public Instance Methods

dump_page() click to toggle source
# File lib/rails_gwt/dsl.rb, line 54
def dump_page
  puts page.html.gsub(/></, ">\n<")
end
login_session(username, use_last_pwd = false) { || ... } click to toggle source
# File lib/rails_gwt/dsl.rb, line 25
def login_session(username, use_last_pwd = false)
  puts "login user: '#{username}'"
  if use_last_pwd
    line = File.read('log/test.log').gsub(/\r/, '').split("\n").grep(/new password :/).last
    pwd = line.gsub(/.*new password : (.*)/ , '\1') if line
  end
  if pwd.blank?
    fill_in 'username', :with => username
    click_on('password reset')
    page.should have_content('new password was sent to your email address')

    pwd = File.read('log/test.log').gsub(/\r/, '').split("\n").grep(/new password :/).last.gsub(/.*new password : (.*)/ , '\1')
  end
  fill_in 'login', :with => username
  fill_in 'password', :with => pwd
  click_on('login')

  should_have_no_loading

  yield

  click_on('logout')
  page.should have_content('password reset')
end
should_have_action_button(name) click to toggle source
# File lib/rails_gwt/dsl.rb, line 90
def should_have_action_button(name)
  find(:xpath, "//div[@class='gwt-rails-model']//div[@class='gwt-rails-buttons']/button[text()='#{name}' and not(@style='display: none;')]")
end
should_have_action_buttons(*buttons) click to toggle source
# File lib/rails_gwt/dsl.rb, line 121
def should_have_action_buttons(*buttons)
  buttons = buttons.flatten
  found = []
  all(:xpath, "//div[@class='gwt-rails-model']//div[@class='gwt-rails-buttons']/button").each do |b|
    found << b.text unless b.text.blank?
  end
  (found || bottons).each do |button|
    if buttons.member? button
      should_have_action_button(button) unless button.blank?
    else
      should_have_no_action_button(button) unless button.blank?
    end
  end 
end
should_have_button(name) click to toggle source
# File lib/rails_gwt/dsl.rb, line 58
def should_have_button(name)
  find(:xpath, "//button[text()='#{name}' and not(@style='display: none;')]")
end
should_have_buttons(*buttons) click to toggle source
# File lib/rails_gwt/dsl.rb, line 140
def should_have_buttons(*buttons)
  buttons = buttons.flatten
  found = []
  all(:xpath, "//div[contains(@class, 'gwt-rails-display')]/div[@class='gwt-rails-buttons']/button").each do |b|
    text = b.text
    found << text unless text.blank?
  end
  (found || buttons).each do |button|
    if buttons.member? button
      should_have_button(button)
    else
      should_have_no_button(button)
    end
  end
end
should_have_menu_items(*items) click to toggle source
# File lib/rails_gwt/dsl.rb, line 66
def should_have_menu_items(*items)
  found = []
  all(:xpath, "//div[@class='gwt-rails-menu']/button").each do |b|
    found << b.text if b[:style].blank?
  end
  found.sort!.should == items.flatten.sort
end
should_have_model_display() click to toggle source
# File lib/rails_gwt/dsl.rb, line 82
def should_have_model_display
  find(:xpath, "//div[@class='gwt-rails-model' and not(@style='display: none;')]")
end
should_have_model_list_display() click to toggle source
# File lib/rails_gwt/dsl.rb, line 78
def should_have_model_list_display
  find(:xpath, "//div[@class='gwt-rails-model-list' and not(table/@style='display: none;')]")
end
should_have_no_action_button(name) click to toggle source
# File lib/rails_gwt/dsl.rb, line 94
def should_have_no_action_button(name)
  find(:xpath, "//div[@class='gwt-rails-buttons']/button[text()='#{name}' and @style='display: none;']")
end
should_have_no_action_buttons() click to toggle source
# File lib/rails_gwt/dsl.rb, line 117
def should_have_no_action_buttons
  should_have_action_buttons
end
should_have_no_button(name) click to toggle source
# File lib/rails_gwt/dsl.rb, line 62
def should_have_no_button(name)
  find(:xpath, "//button[text()='#{name}' and @style='display: none;']")
end
should_have_no_buttons() click to toggle source
# File lib/rails_gwt/dsl.rb, line 136
def should_have_no_buttons
  should_have_buttons
end
should_have_no_loading() click to toggle source
# File lib/rails_gwt/dsl.rb, line 50
def should_have_no_loading
  page.should have_xpath('//div[@class = "gwt-rails-loading" and @style = "display: none;"]')
end
should_have_no_model_display() click to toggle source
# File lib/rails_gwt/dsl.rb, line 74
def should_have_no_model_display
  find(:xpath, "//div[@class='gwt-rails-model' and @style='display: none;']")
end
should_have_no_model_list_display() click to toggle source
# File lib/rails_gwt/dsl.rb, line 86
def should_have_no_model_list_display
  find(:xpath, "//div[@class='gwt-rails-model-list' and table/@style='display: none;']")
end
visit_resource(config, &block) click to toggle source
# File lib/rails_gwt/dsl.rb, line 156
def visit_resource(config, &block)
  puts "----- resource: '#{config.resource}'"
  page.should have_content("Welcome #{config.name}")
  page.should have_content('logout')

  should_have_menu_items(config.menu)
  
  config.action = :new
  if config.action
    within_page("/Users.html##{config.resource}/new", config.mode) do
      should_have_action_buttons(config.action_buttons)
      should_have_buttons(config.buttons)
    end
  end

  config.action = :edit
  if config.action
    id = config.mode == :singleton ? '' : "/#{config.resource_id}"
    within_page("/Users.html##{config.resource}#{id}/edit", config.mode) do
      should_have_action_buttons(config.action_buttons)
      should_have_buttons(config.buttons)
    end
  end
  
  config.action = :show
  if config.action      
    id = config.mode == :singleton ? '' : "/#{config.resource_id}"
    within_page("/Users.html##{config.resource}#{id}", config.mode) do
      should_have_action_buttons(config.action_buttons)
      should_have_buttons(config.buttons)
    end
  end

  config.action = :index
  if config.action
    within_page("/Users.html##{config.resource}", :index) do
      should_have_action_buttons(config.action_buttons)
      should_have_buttons(config.buttons)
    end

    # list
    config.content.each do |item|
      page.should have_content(item)
    end
    
    # no user list after search
    #      fill_in 'search', :with => 'pipapo'
    #      page.should have_no_content('root@example.com')
    
  end

  block.call(config) if block
end
within_page(path, mode = :page, &block) click to toggle source
# File lib/rails_gwt/dsl.rb, line 98
def within_page(path, mode = :page, &block)
  puts "visit page: #{path}"
  visit "#{path}"
  should_have_no_loading
  
  case mode
  when :index
    should_have_no_model_display
    should_have_model_list_display
  when :page
    should_have_model_display
    should_have_no_model_list_display
  when :singleton
    should_have_model_display
  end

  block.call if block
end