Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Fix rspec suite #71

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/tabulatr/data/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def buttons(opts = {}, &block)
output = ->(r) {
tdbb = Tabulatr::Data::ButtonBuilder.new
self.instance_exec tdbb, r, &block
self.controller.render_to_string partial: '/tabulatr/tabulatr_buttons', locals: {buttons: tdbb.val}, formats: [:html]
self.controller.render_to_string partial: '/tabulatr/bs3/tabulatr_buttons', locals: {buttons: tdbb.val}, formats: [:html]
}
opts = {header: opts[:header] || '', filter: false, sortable: false}.merge(opts)
table_column = Tabulatr::Renderer::Buttons.from(
Expand Down
1 change: 1 addition & 0 deletions spec/controller/application_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def current_user

expect_any_instance_of(Tabulatr::Data).to receive(:data_for_table).with(
{"pagesize"=>"20", "arguments"=>"products:title", "controller"=>"anonymous", "action"=>"index"},
{:default_order=>nil},
{:locals=>{current_user: "Han Solo"}, controller: controller}
).and_return(fake_response)
expect(fake_response).to receive(:to_tabulatr_json).and_return({})
Expand Down
55 changes: 28 additions & 27 deletions spec/features/tabulatrs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
"officia", "deserunt", "mollit", "anim", "est", "laborum"]

before(:each) do
@vendor1 = Vendor.create!(:name => "ven d'or", :active => true)
@vendor2 = Vendor.create!(:name => 'producer', :active => true)
@tag1 = Tag.create!(:title => 'foo')
@tag2 = Tag.create!(:title => 'bar')
@tag3 = Tag.create!(:title => 'fubar')
@vendor1 = Vendor.create!(name: "ven d'or", active: true)
@vendor2 = Vendor.create!(name: 'producer', active: true)
@tag1 = Tag.create!(title: 'foo')
@tag2 = Tag.create!(title: 'bar')
@tag3 = Tag.create!(title: 'fubar')
end

feature "General data" do
Expand All @@ -37,10 +37,11 @@
end

scenario "contains the actual data", js: true do
product = Product.create!(:title => names[0], :active => true, :price => 10.0)
product = Product.create!(title: names[0], active: true, price: 10.0)
product.vendor = @vendor1
product.save!
visit simple_index_products_path
wait_for_ajax
expect(page).to have_content("true")
expect(page).to have_content("10.0")
expect(product.vendor.name).to eq("ven d'or")
Expand All @@ -49,7 +50,7 @@
end

scenario "correctly contains the association data", js: true do
product = Product.create!(:title => names[0], :active => true, :price => 10.0)
product = Product.create!(title: names[0], active: true, price: 10.0)
[@tag1, @tag2, @tag3].each_with_index do |tag, i|
product.tags << tag
product.save
Expand All @@ -60,8 +61,8 @@

scenario "contains the actual data multiple times", js: true do
9.times do |i|
product = Product.create!(:title => names[i], :active => i.even?, :price => 11.0+i,
:vendor => i.even? ? @vendor1 : @vendor2)
product = Product.create!(title: names[i], active: i.even?, price: 11.0+i,
vendor: i.even? ? @vendor1 : @vendor2)
visit simple_index_products_path
expect(page).to have_content(names[i])
expect(page).to have_content((11.0+i).to_s)
Expand All @@ -70,8 +71,8 @@

scenario "contains the further data on the further pages" do
names[10..-1].each_with_index do |n,i|
product = Product.create!(:title => n, :active => i.even?, :price => 20.0+i,
:vendor => i.even? ? @vendor1 : @vendor2)
product = Product.create!(title: n, active: i.even?, price: 20.0+i,
vendor: i.even? ? @vendor1 : @vendor2)
visit simple_index_products_path
expect(page).to have_no_content(/\s+#{n}\s+/)
expect(page).to have_no_content((30.0+i).to_s)
Expand All @@ -81,7 +82,7 @@

feature 'has_many' do
scenario 'displays the count when called with :count', js: true do
product = Product.create!(:title => names[0], :active => true, :price => 10.0)
product = Product.create!(title: names[0], active: true, price: 10.0)
[@tag1, @tag2, @tag3].each do |tag|
product.tags << tag
end
Expand All @@ -97,7 +98,7 @@
context 'pagination setting is true' do
scenario 'has pages', js: true do
5.times do |i|
Product.create!(:title => "test #{i}")
Product.create!(title: "test #{i}")
end
visit one_item_per_page_with_pagination_products_path
expect(page).to have_css('.pagination li a[data-page]', count: 5)
Expand Down Expand Up @@ -126,7 +127,7 @@
feature "Filters" do
scenario "filters with like", js: true do
names.each do |n|
Product.create!(:title => n, :active => true, :price => 10.0)
Product.create!(title: n, active: true, price: 10.0)
end
visit simple_index_products_path
click_link 'Filter'
Expand All @@ -136,7 +137,7 @@
expect(page).to have_selector('td[data-tabulatr-column-name="products:title"]', text: 'dolore')

within(".tabulatr_filter_form") do
fill_in("product_filter[products:title][like]", :with => "loreem")
fill_in("product_filter[products:title][like]", with: "loreem")
end
expect(page).not_to have_selector('td[data-tabulatr-column-name="products:title"]', text: 'lorem')
expect(page).not_to have_selector('td[data-tabulatr-column-name="products:title"]', text: 'labore')
Expand Down Expand Up @@ -165,18 +166,18 @@

click_link 'Filter'
within('.tabulatr_filter_form') do
fill_in("product_filter[products:price][from]", :with => 4)
fill_in("product_filter[products:price][from]", with: 4)
wait_for_ajax
fill_in("product_filter[products:price][to]", :with => 10)
fill_in("product_filter[products:price][to]", with: 10)
wait_for_ajax
end
expect(page).to have_no_css('.tabulatr-spinner-box')
expect(page).to have_css(".tabulatr_table tbody tr", text: 'foo')
expect(page).to have_no_css(".tabulatr_table tbody tr", text: 'bar')
within('.tabulatr_filter_form') do
fill_in("product_filter[products:price][from]", :with => 12)
fill_in("product_filter[products:price][from]", with: 12)
wait_for_ajax
fill_in("product_filter[products:price][to]", :with => 19)
fill_in("product_filter[products:price][to]", with: 19)
wait_for_ajax
end
expect(page).to have_no_css('.tabulatr-spinner-box')
Expand Down Expand Up @@ -289,7 +290,7 @@

scenario "contains the actual data", js: false do
names.shuffle.each.with_index do |n,i|
p = Product.new(:title => n, :active => true, :price => 10.0 + i)
p = Product.new(title: n, active: true, price: 10.0 + i)
p.vendor = [@vendor1, @vendor2].shuffle.first
p.tags = [@tag1, @tag2, @tag3].shuffle[0..rand(3)]
p.save!
Expand Down Expand Up @@ -323,9 +324,9 @@


scenario 'executes the action when clicked' do
product1 = Product.create!(:title => names[0], :active => true, :price => 10.0)
product2 = Product.create!(:title => names[1], :active => true, :price => 10.0)
product3 = Product.create!(:title => names[2], :active => true, :price => 10.0)
product1 = Product.create!(title: names[0], active: true, price: 10.0)
product2 = Product.create!(title: names[1], active: true, price: 10.0)
product3 = Product.create!(title: names[2], active: true, price: 10.0)
visit with_batch_actions_products_path
expect(page).to have_css(".tabulatr_table tbody tr", count: 3)
find(".tabulatr-checkbox[value='#{product1.id}']").trigger('click')
Expand All @@ -338,9 +339,9 @@
end

scenario 'executes the action for all items if nothing selected' do
product1 = Product.create!(:title => names[0], :active => true, :price => 10.0)
product2 = Product.create!(:title => names[1], :active => true, :price => 10.0)
product3 = Product.create!(:title => names[2], :active => false, :price => 10.0)
product1 = Product.create!(title: names[0], active: true, price: 10.0)
product2 = Product.create!(title: names[1], active: true, price: 10.0)
product3 = Product.create!(title: names[2], active: false, price: 10.0)
visit with_batch_actions_products_path
find('.tabulatr-batch-actions-menu-wrapper a').click
within('.dropdown.open') do
Expand All @@ -352,7 +353,7 @@

feature "Column options", js: true do
scenario 'applys the given style' do
p = Product.create!(:title => names[0], :active => true, :price => 10.0)
p = Product.create!(title: names[0], active: true, price: 10.0)
visit with_styling_products_path
cell = find(".tabulatr_table tbody td[data-tabulatr-column-name='products:title']")
header = find(".tabulatr_table thead th[data-tabulatr-column-name='products:title']")
Expand Down
3 changes: 2 additions & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
require 'spec_helper'

Capybara.javascript_driver = :poltergeist
Capybara.server = :webrick

Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, {js_errors: true})
Expand All @@ -25,4 +26,4 @@

RSpec.configure do |config|
config.use_transactional_fixtures = false
end
end