spec/requests/tabulatrs_spec.rb in tabulatr-0.1.3 vs spec/requests/tabulatrs_spec.rb in tabulatr-0.2.0

- old
+ new

@@ -1,8 +1,12 @@ require 'spec_helper' describe "Tabulatrs" do + + Mongoid.master.collections.select do |collection| + collection.name !~ /system/ + end.each(&:drop) names = ["lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipisicing", "elit", "sed", "eiusmod", "tempor", "incididunt", "labore", "dolore", "magna", "aliqua", "enim", "minim", "veniam,", "quis", "nostrud", "exercitation", "ullamco", "laboris", "nisi", "aliquip", "commodo", @@ -14,27 +18,28 @@ # control which tests to run. Just to spped testing up tralse = true # General stuf WORKS_IN_GENERAL = CONTAINS_BUTTONS = CONTAINS_COLUMN_HEADERS = CONTAINS_OTHER_CONTROLS = tralse # This fills in the data, so rather not cmment this out - CONTAINS_ACTUAL_DATA = CONTAINS_ASSOC_DATA = CONTAINS_ACTUAL_DATA_MULTIPLE = CONTAINS_DATA_ON_FURTHER_PAGES = true + CONTAINS_ACTUAL_DATA = CONTAINS_ASSOC_DATA = CONTAINS_ACTUAL_DATA_MULTIPLE = CONTAINS_DATA_ON_FURTHER_PAGES = tralse # Paginatione PAGES_UP_AND_DOWN = JUMPS_TO_CORRECT_PAGE = CHANGES_PAGE_SIZE = tralse # Filters FILTERS = FILTERS_WITH_LIKE = FILTERS_WITH_RANGE = tralse # Sorting KNOWS_HOW_TO_SORT = tralse # Statful - SORTS_STATEFULLY = FILTERS_STATEFULLY = SELECTS_STATEFULLY = true + SORTS_STATEFULLY = FILTERS_STATEFULLY = SELECTS_STATEFULLY = tralse # selecting and batch actions SELECT_BUTTONS_WORK = KNOWS_HOW_TO_SELECT_AND_APPLY_BATCH_ACTIONS = tralse 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') + ids = [] describe "General data" do it "works in general" do get index_simple_products_path response.status.should be(200) @@ -50,11 +55,11 @@ page.should_not have_button(Tabulatr::TABLE_OPTIONS[:reset_label]) end if CONTAINS_BUTTONS it "contains column headers" do visit index_simple_products_path - ['Id','Title','Price','Active','Created At','Vendor Name','Tags Title','Tags Count'].each do |n| + ['Id','Title','Price','Active','Created At','Vendor Created At','Vendor Name','Tags Title','Tags Count'].each do |n| page.should have_content(n) end end if CONTAINS_COLUMN_HEADERS it "contains other elements" do @@ -67,13 +72,15 @@ visit index_simple_products_path page.should have_content(names[0]) page.should have_content("true") page.should have_content("10.0") page.should have_content("--0--") + #save_and_open_page page.should have_content(sprintf(Tabulatr::TABLE_OPTIONS[:info_text], 1, 1, 0, 1)) product.vendor = vendor1 product.save! + ids << product.id visit index_simple_products_path page.should have_content("ven d'or") end if CONTAINS_ACTUAL_DATA it "correctly contains the association data" do @@ -88,21 +95,30 @@ it "contains the actual data multiple" do 9.times do |i| product = Product.create!(:title => names[i+1], :active => i.even?, :price => 11.0+i, :description => "blah blah #{i}", :vendor => i.even? ? vendor1 : vendor2) + ids << product.id visit index_simple_products_path page.should have_content(names[i]) page.should have_content((11.0+i).to_s) page.should have_content(sprintf(Tabulatr::TABLE_OPTIONS[:info_text], i+2, i+2, 0, i+2)) end end if CONTAINS_ACTUAL_DATA_MULTIPLE + it "contains row identifiers" do + visit index_simple_products_path + Product.all.each do |product| + page.should have_css("#product_#{product.id}") + end + end if CONTAINS_ACTUAL_DATA + it "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, :description => "blah blah #{i}", :vendor => i.even? ? vendor1 : vendor2) + ids << product.id visit index_simple_products_path page.should_not have_content(n) page.should_not have_content((30.0+i).to_s) page.should have_content(sprintf(Tabulatr::TABLE_OPTIONS[:info_text], 10, i+11, 0, i+11)) end @@ -205,10 +221,11 @@ %w{a o lo lorem}.each do |str| fill_in("product_filter[title][like]", :with => str) click_button("Apply") page.should have_content(str) tot = (names.select do |s| s.match Regexp.new(str) end).length + #save_and_open_page page.should have_content(sprintf(Tabulatr::TABLE_OPTIONS[:info_text], [10,tot].min, names.length, 0, tot)) end end if FILTERS_WITH_LIKE it "filters with range" do @@ -237,10 +254,11 @@ end describe "Sorting" do it "knows how to sort" do visit index_sort_products_path + # save_and_open_page (1..10).each do |i| page.should have_content names[-i] end click_button("product_sort_title_desc") snames = names.sort @@ -271,25 +289,29 @@ page.should have_content names[i-1] end end if SORTS_STATEFULLY it "filters statefully" do + Capybara.reset_sessions! visit index_stateful_products_path fill_in("product_filter[title]", :with => "lorem") click_button("Apply") visit index_stateful_products_path + #save_and_open_page page.should have_content(sprintf(Tabulatr::TABLE_OPTIONS[:info_text], 1, names.length, 0, 1)) click_button("Reset") page.should have_content(sprintf(Tabulatr::TABLE_OPTIONS[:info_text], 10, names.length, 0, names.length)) end if FILTERS_STATEFULLY - + it "selects statefully" do visit index_stateful_products_path + fill_in("product_filter[title]", :with => "") + click_button("Apply") n = names.length (n/10).times do |i| (1..3).each do |j| - check("product_checked_#{10*i+j}") + check("product_checked_#{ids[10*i+j]}") end click_button("Apply") tot = 3*(i+1) page.should have_content(sprintf(Tabulatr::TABLE_OPTIONS[:info_text], 10, n, tot, n)) click_button('product_pagination_page_right') @@ -340,16 +362,16 @@ page.should have_content(sprintf(Tabulatr::TABLE_OPTIONS[:info_text], 10, n, n-tot, tot)) fill_in("product_filter[title][like]", :with => "") click_button("Apply") page.should have_content(sprintf(Tabulatr::TABLE_OPTIONS[:info_text], 10, n, n-tot, n)) end if SELECT_BUTTONS_WORK - + it "knows how to select and apply batch actions" do visit index_select_products_path n = names.length (n/10).times do |i| (1..3).each do |j| - check("product_checked_#{10*i+j}") + check("product_checked_#{ids[10*i+j]}") end click_button("Apply") tot = 3*(i+1) page.should have_content(sprintf(Tabulatr::TABLE_OPTIONS[:info_text], 10, n, tot, n)) click_button('product_pagination_page_right')