Given /^I am logged in as an administrator$/ do
  @current_user = User.create!(
    :email => 'a@b.c',
    :name => 'Admin',
    :password => 'admin'
  ) { |u| u.admin = true }

  Given "I am on the login page"
  fill_in("Email", :with => 'a@b.c') 
  fill_in("Password", :with => 'admin') 
  click_button("Login")
  visit url_for response.redirected_to()
end

Then /^I should see a list of websites$/ do
  Then "I should see \"#{websites(:guitar_gear).name}\""
  Then "I should see \"#{websites(:website_without_analytics).name}\""
end

Then /^I should see links to edit websites$/ do
  # check one of the websites
  response.should have_xpath("//a[@href='#{edit_website_path(websites(:guitar_gear))}']")
end

Then /^I should see a link to add a new website$/ do
  response.should have_xpath("//a[@href='#{new_website_path}']")
end

Then /^a new website should exist with the domain "([^\"]*)"$/ do |domain|
  Website.find_by_domain(domain).should_not be_nil
end


Given /^I am logged in as an administrator$/ do
  @current_user = User.create!(
    :email => 'admin@example.org',
    :name => 'Admin',
    :password => 'admin'
  ) { |u| u.admin = true }

  Given "I am on the login page"
  fill_in("Email", :with => @current_user.email)
  fill_in("Password", :with => @current_user.password)
  click_button("Login")
  visit url_for response.redirected_to()
end

Then /^I should see a list of websites$/ do
  Then "I should see \"#{websites(:guitar_gear).name}\""
  Then "I should see \"#{websites(:website_without_analytics).name}\""
end

Then /^I should see links to edit websites$/ do
  # check one of the websites
  response.should have_xpath("//a[@href='#{edit_website_path(websites(:guitar_gear))}']")
end

Then /^I should see a link to add a new website$/ do
  response.should have_xpath("//a[@href='#{new_website_path}']")
end

Then /^a new website should exist with the domain "([^\"]*)"$/ do |domain|
  Website.find_by_domain(domain).should_not be_nil
end


Use a valid email address for administrator user account in 'I am logged in as an administrator' cucumber step
Use a valid email address for administrator user account in 'I am logged in as an administrator' cucumber step
