Given(/^a user named "(.+)"$/) do |name|
  @context.given_user(name, @context.get_user_information[name])
end

Given(/^a user named "(.+)" with a blog post$/) do |name|
  @context.given_user(name, @context.get_user_information[name])
  @context.given_user_with_a_blog_post(name)
end

Given(/^I'm on the edit page for "(.+)"$/) do |name|
  @context.given_on_show_page(name, 'user')
end

Given(/^the Guest Author template exists$/) do
  template = Template.create!(name: "Guest Author", plural: "Guest Authors")
  default_params = {
    template_id: template.id,
    mandatory: false,
    char_limit: 0,
    object_type: ""
  }

  Field.create!(default_params.merge({ name: "Name", field_type: "text", char_limit: 200, order: 0 }))
  Field.create!(default_params.merge({ name: "Bio", field_type: "text", char_limit: 400, order: 1 }))
  Field.create!(default_params.merge({ name: "Image", field_type: "image", order: 2 }))
  Field.create!(default_params.merge({ name: "Twitter Handle", field_type: "text", char_limit: 100, order: 3 }))
end

When(/^I create an? (\w+) user named "(.+)"$/) do |valid_or_invalid, user_name|
  @context.click_a_tag('Add User')
  @context.create_user(user_name, valid_or_invalid)
end

When(/^I delete the user "(.+)"$/) do |name|
  @context.delete_user(name)
end

When(/^I click the permissions dropdown$/) do
  @context.open_permissions
end

Then(/^the "(.+)" should exist$/) do |name|
  user = User.last
  @context.expect_user_in_database(user, name)
  @context.expect_in_index(user)
end

Then(/^the user "(.+)" should not exist in the database$/) do |name|
  @context.expect_user_not_in_database(name)
end

Then(/^a (.+) Objekt with a (.+) of (.+) should be in the database$/) do |objekt_type, property, value|
  @context.expect_objekt_in_database(objekt_type, property, value)
end

Then(/^(.+)'s blog post should be assigned to an appropriate Guest Author Objekt$/) do |name|
  @context.expect_blog_post_to_be_guest_authored(name)
end

Then(/^I should only see permission levels below administrator$/) do
  @context.expect_correct_permissions
end

Then(/^I should see my privilages$/) do
  @context.expect_correct_privileges
end
