spec/requests/tabulatrs_spec.rb in tabulatr-0.3.0 vs spec/requests/tabulatrs_spec.rb in tabulatr-0.4.0
- old
+ new
@@ -1,9 +1,9 @@
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",
@@ -13,27 +13,10 @@
"consequat", "duis", "aute", "irure", "reprehenderit", "voluptate", "velit",
"esse", "cillum", "fugiat", "nulla", "pariatur", "excepteur", "sint",
"occaecat", "cupidatat", "non", "proident", "sunt", "culpa", "qui",
"officia", "deserunt", "mollit", "anim", "est", "laborum"]
- # 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 = 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 = 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')
@@ -41,33 +24,33 @@
describe "General data" do
it "works in general" do
get index_simple_products_path
response.status.should be(200)
- end if WORKS_IN_GENERAL
+ end
it "contains buttons" do
visit index_simple_products_path
[:submit_label, :select_all_label, :select_none_label, :select_visible_label,
:unselect_visible_label, :select_filtered_label, :unselect_filtered_label
].each do |n|
page.should have_button(Tabulatr::TABLE_OPTIONS[n])
end
page.should_not have_button(Tabulatr::TABLE_OPTIONS[:reset_label])
- end if CONTAINS_BUTTONS
+ end
it "contains column headers" do
visit index_simple_products_path
['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
+ end
it "contains other elements" do
visit index_simple_products_path
page.should have_content(sprintf(Tabulatr::TABLE_OPTIONS[:info_text], 0, 0, 0, 0))
- end if CONTAINS_OTHER_CONTROLS
+ end
it "contains the actual data" do
product = Product.create!(:title => names[0], :active => true, :price => 10.0, :description => 'blah blah')
visit index_simple_products_path
page.should have_content(names[0])
@@ -79,21 +62,21 @@
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
+ end
it "correctly contains the association data" do
product = Product.first
[tag1, tag2, tag3].each_with_index do |tag, i|
product.tags << tag
visit index_simple_products_path
page.should have_content tag.title
page.should have_content(sprintf("--%d--", i+1))
end
- end if CONTAINS_ASSOC_DATA
+ end
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)
@@ -101,18 +84,18 @@
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
+ end
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
+ end
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)
@@ -120,11 +103,11 @@
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
- end if CONTAINS_DATA_ON_FURTHER_PAGES
+ end
end
describe "Pagination" do
it "pages up and down" do
visit index_simple_products_path
@@ -161,11 +144,11 @@
else
page.should have_button('product_pagination_page_left')
click_button('product_pagination_page_left')
end
end
- end if PAGES_UP_AND_DOWN
+ end
it "jumps to the correct page" do
visit index_simple_products_path
k = 1+names.length/10
l = (1..k).entries.shuffle
@@ -185,11 +168,11 @@
page.should have_no_button('product_pagination_page_right')
else
page.should have_button('product_pagination_page_right')
end
end
- end if JUMPS_TO_CORRECT_PAGE
+ end
it "changes the page size" do
visit index_simple_products_path
[50,20,10].each do |s|
select s.to_s, :from => "product_pagination[pagesize]"
@@ -197,11 +180,11 @@
s.times do |i|
page.should have_content(names[i])
end
page.should_not have_content(names[s])
end
- end if CHANGES_PAGE_SIZE
+ end
end
describe "Filters" do
it "filters" do
visit index_simple_products_path
@@ -212,11 +195,11 @@
page.should have_content(sprintf(Tabulatr::TABLE_OPTIONS[:info_text], 1, names.length, 0, 1))
fill_in("product_filter[title]", :with => "loreem")
click_button("Apply")
page.should_not have_content("lorem")
page.should have_content(sprintf(Tabulatr::TABLE_OPTIONS[:info_text], 0, names.length, 0, 0))
- end if FILTERS
+ end
it "filters with like" do
visit index_filters_products_path
%w{a o lo lorem}.each do |str|
fill_in("product_filter[title][like]", :with => str)
@@ -224,11 +207,11 @@
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
+ end
it "filters with range" do
visit index_filters_products_path
n = names.length
(0..n/2).each do |i|
@@ -248,11 +231,11 @@
fill_in("product_filter[price][to]", :with => (10+n-i-1).to_s)
click_button("Apply")
tot = n-i*2
page.should have_content(sprintf(Tabulatr::TABLE_OPTIONS[:info_text], [10,tot].min, n, 0, tot))
end
- end if FILTERS_WITH_RANGE
+ end
end
describe "Sorting" do
it "knows how to sort" do
visit index_sort_products_path
@@ -267,15 +250,16 @@
end
click_button("product_sort_title_asc")
(1..10).each do |i|
page.should have_content snames[i-1]
end
- end if KNOWS_HOW_TO_SORT
+ end
end
describe "statefulness" do
it "sorts statefully" do
+ Capybara.reset_sessions!
visit index_stateful_products_path
click_button("product_sort_title_desc")
snames = names.sort
(1..10).each do |i|
page.should have_content snames[-i]
@@ -286,11 +270,11 @@
end
click_button("Reset")
(1..10).each do |i|
page.should have_content names[i-1]
end
- end if SORTS_STATEFULLY
+ end
it "filters statefully" do
Capybara.reset_sessions!
visit index_stateful_products_path
fill_in("product_filter[title]", :with => "lorem")
@@ -298,13 +282,14 @@
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
+ end
it "selects statefully" do
+ Capybara.reset_sessions!
visit index_stateful_products_path
fill_in("product_filter[title]", :with => "")
click_button("Apply")
n = names.length
(n/10).times do |i|
@@ -319,11 +304,11 @@
visit index_stateful_products_path
tot = 3*(n/10)
page.should have_content(sprintf(Tabulatr::TABLE_OPTIONS[:info_text], names.length % 10, n, tot, n))
click_button("Reset")
page.should have_content(sprintf(Tabulatr::TABLE_OPTIONS[:info_text], 10, names.length, 0, names.length))
- end if SELECTS_STATEFULLY
+ end
end
describe "Select and Batch actions" do
it "knows how to interpret the select_... buttons" do
@@ -361,11 +346,11 @@
click_button('Unselect filtered')
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
+ end
it "knows how to select and apply batch actions" do
visit index_select_products_path
n = names.length
(n/10).times do |i|
@@ -380,10 +365,10 @@
select 'Delete', :from => 'product_batch'
click_button("Apply")
tot = n-3*(n/10)
page.should have_content(sprintf(Tabulatr::TABLE_OPTIONS[:info_text], 10, tot, 0, tot))
#save_and_open_page
- end if KNOWS_HOW_TO_SELECT_AND_APPLY_BATCH_ACTIONS
+ end
end
# describe "GET /products empty" do
# it "works in general" do
# get products_path