Given(/^I'm logged in as (\w+)$/) do |name|
  @context.given_logged_in(name)
end

Given(/^the "(.+)" template$/) do |name|
  @context.given_template(name)
end

Given(/^the "(.+)" partial$/) do |name|
  @context.given_partial(name)
end

Given(/^I'm on the (?:details|edit) page for the "(.+)" (\w+)$/) do |name, type|
  @context.given_on_show_page(name, type)
end

Given(/^a (?:.+) field with the name of "(.+)"$/) do |value|
  @context.given_field_value(value)
end

Given(/^the "(.+)" partial is a page partial for the "(.+)" page$/) do |partial, page|
  @context.given_page(page)
  @context.given_page_partial(partial, page)
end

When(/^I create the "(.+)" (template|partial|page)$/) do |name, type|
  @context.send("create_#{type}", name)
end

When(/^I add the "(.+)" field to the (?:partial|template)$/) do |name|
  @context.add_field(name)
end

When(/^I delete the (?:partial|template|page partial|object|user|redirect)$/) do
  @context.delete
end

When(/^I change the "(.+)"(?:.*)field to "(.*)"$/) do |field, value|
  @context.change_field(field, value)
end

When(/^I change the "(.+)" to "(.*)"$/) do |attribute, new_value|
  @context.change_attribute(attribute, new_value)
end

When(/^I delete the (?:template|partial) field$/) do
  @context.delete_field
end

When(/^I drag the "(.+)" (?:plan feature|partial) to the (\d+|last)(?:\w*) position$/) do |text, position|
  @context.rearrange(text, position)
end

When(/^I preview the page$/) do
  @context.preview_page
end

Then(/^I should see all of the (partials|pages|templates)$/) do |type|
  @context.expect_all_names_on_page(@context.make_class_name(type[0...-1]))
  @context.expect_names_alphabetized
end

Then(/^I should see all of the (?:users|redirects)$/) do
  @context.expect_all
  @context.expect_alphabetized
end

Then(/^there should only be 1 instance of the (template|partial|page|tooltip|feature)$/) do |type|
  @context.expect_one_instance(type)
end

Then(/^the (?:template|partial) should have the "(.+)" field$/) do |name|
  @context.expect_field_to_exist(name)
end

Then(/^the "(.+)" (?:partial|template|redirect) should not exist$/) do |name|
  @context.expect_not_in_database(name)
  @context.expect_content_not_on_page(name)
end

Then(/^the (?:template|partial) should not have a field named "(.+)"$/) do |name|
  @context.expect_field_not_in_database(name)
  @context.expect_field_not_on_page(name)
  @context.expect_order_rearranged
end

Then(/^the (?:page partial|plan feature) should be in the correct position$/) do
  @context.expect_correct_backend_order
  @context.expect_correct_data_index
  @context.expect_correct_position_on_screen
end

Then(/^the "(.+)" page partial should be updated$/) do |partial|
  @context.expect_updated(partial)
end

Then(/^(?:he|I) should be on the "(.+)" page$/) do |url|
  expect(current_path).to eq(url)
end

Then (/^the (plan's|user's) "(.+)" (should|should not) be changed$/) do |type, attribute, should_or_not|
  @context.expect_changed_attribute(type[0...-2], attribute, should_or_not)
end

Then(/^I should see all of the partial's pages$/) do
  @context.expect_all_pages
  @context.expect_pages_alphabetized
end
