Sha256: 553a982986b7c997bbbf71f584188d3ea03f34089d2691bb21d0232ddcb309f9

Contents?: true

Size: 1.76 KB

Versions: 1

Compression:

Stored size: 1.76 KB

Contents

# coding: UTF-8
require 'spec_helper'

describe "AutoCompleteWithDynamicUrl - Items" do
  let!(:shoes) { create(:category, :name => "shoes") }
  let!(:skirt) { create(:category, :name => "skirt") }
  let!(:pents) { create(:category, :name => "pents") }

  context "without javascript" do
    it "is possible to add new element" do
      visit new_item_path

      fill_in "item_name", :with => "hello"
      fill_in "item_category_id", :with => shoes.id
      click_button "Create Item"

      expect(page).to have_content("hello - #{shoes.id}")

      expect(Item.last.category.id).to eq(shoes.id)
    end

    it "is possible to edit element" do
      item = create(:item, :name => "item", :category_id => shoes.id)
      expect(item.category.id).to eq(shoes.id)

      visit edit_item_path(item)

      fill_in "item_category_id", :with => skirt.id
      click_button "Update Item"

      expect(item.reload.category.id).to eq(skirt.id)
    end
  end

  context "with javascript", :js => true do
    it "is possible to add new element" do
      visit new_item_path

      fill_in "item_name", :with => "hello"
      fill_in_token "item_category_id", :with => "shoes"
      click_button "Create Item"

      expect(page).to have_content("hello")
      expect(page).to have_content("hello - #{shoes.id}")

      expect(Item.last.category.id).to eq(shoes.id)
    end

    it "is possible to edit element" do
      item = create(:item, :name => "item", :category_id => shoes.id)
      expect(item.category.id).to eq(shoes.id)

      visit edit_item_path(item)

      clear_token "item_category_id"
      fill_in_token "item_category_id", :with => "skirt"

      click_button "Update Item"

      expect(page).to have_content("Items")

      expect(item.reload.category.id).to eq(skirt.id)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
token_field-2.0.0 spec/features/autocomplete_with_dynamic_url_spec.rb