tabulatr 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/.gitignore +1 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +5 -5
  4. data/Gemfile.lock +92 -49
  5. data/README.textile +95 -54
  6. data/assets/images/buttons_lite_background.png +0 -0
  7. data/assets/images/pager_arrow_left.gif +0 -0
  8. data/assets/images/pager_arrow_left_off.gif +0 -0
  9. data/assets/images/pager_arrow_right.gif +0 -0
  10. data/assets/images/pager_arrow_right_off.gif +0 -0
  11. data/assets/images/sort_arrow_down.gif +0 -0
  12. data/assets/images/sort_arrow_down_off.gif +0 -0
  13. data/assets/images/sort_arrow_up.gif +0 -0
  14. data/assets/images/sort_arrow_up_off.gif +0 -0
  15. data/init.rb +1 -0
  16. data/lib/generators/tabulatr/install_generator.rb +53 -0
  17. data/lib/tabulatr/version.rb +3 -0
  18. data/spec/dummy_app/.gitignore +4 -0
  19. data/spec/dummy_app/app/controllers/application_controller.rb +3 -0
  20. data/spec/dummy_app/app/controllers/products_controller.rb +90 -0
  21. data/spec/dummy_app/app/controllers/vendors_controller.rb +83 -0
  22. data/spec/dummy_app/app/helpers/application_helper.rb +2 -0
  23. data/spec/dummy_app/app/helpers/products_helper.rb +2 -0
  24. data/spec/dummy_app/app/helpers/vendors_helper.rb +2 -0
  25. data/spec/dummy_app/app/models/product.rb +6 -0
  26. data/spec/dummy_app/app/models/tag.rb +3 -0
  27. data/spec/dummy_app/app/models/vendor.rb +5 -0
  28. data/spec/dummy_app/app/views/layouts/application.html.erb +14 -0
  29. data/spec/dummy_app/app/views/products/_form.html.erb +41 -0
  30. data/spec/dummy_app/app/views/products/edit.html.erb +6 -0
  31. data/spec/dummy_app/app/views/products/index.html.erb +31 -0
  32. data/spec/dummy_app/app/views/products/index_filters.html.erb +8 -0
  33. data/spec/dummy_app/app/views/products/index_select.html.erb +6 -0
  34. data/spec/dummy_app/app/views/products/index_simple.html.erb +10 -0
  35. data/spec/dummy_app/app/views/products/new.html.erb +5 -0
  36. data/spec/dummy_app/app/views/products/show.html.erb +35 -0
  37. data/spec/dummy_app/app/views/vendors/_form.html.erb +33 -0
  38. data/spec/dummy_app/app/views/vendors/edit.html.erb +6 -0
  39. data/spec/dummy_app/app/views/vendors/index.html.erb +31 -0
  40. data/spec/dummy_app/app/views/vendors/new.html.erb +5 -0
  41. data/spec/dummy_app/app/views/vendors/show.html.erb +30 -0
  42. data/spec/dummy_app/config.ru +4 -0
  43. data/spec/dummy_app/config/application.rb +42 -0
  44. data/spec/dummy_app/config/boot.rb +13 -0
  45. data/spec/dummy_app/config/database.yml +22 -0
  46. data/spec/dummy_app/config/environment.rb +5 -0
  47. data/spec/dummy_app/config/environments/development.rb +26 -0
  48. data/spec/dummy_app/config/environments/production.rb +49 -0
  49. data/spec/dummy_app/config/environments/test.rb +35 -0
  50. data/spec/dummy_app/config/initializers/backtrace_silencers.rb +7 -0
  51. data/spec/dummy_app/config/initializers/inflections.rb +10 -0
  52. data/spec/dummy_app/config/initializers/mime_types.rb +5 -0
  53. data/spec/dummy_app/config/initializers/secret_token.rb +7 -0
  54. data/spec/dummy_app/config/initializers/session_store.rb +8 -0
  55. data/spec/dummy_app/config/initializers/tabulatr_settings.rb +11 -0
  56. data/spec/dummy_app/config/locales/en.yml +5 -0
  57. data/spec/dummy_app/config/routes.rb +69 -0
  58. data/spec/dummy_app/db/migrate/20110112151112_create_vendors.rb +16 -0
  59. data/spec/dummy_app/db/migrate/20110112151200_create_products.rb +17 -0
  60. data/spec/dummy_app/db/migrate/20110212104327_create_tags.rb +19 -0
  61. data/spec/dummy_app/doc/README_FOR_APP +2 -0
  62. data/spec/dummy_app/lib/tasks/.gitkeep +0 -0
  63. data/spec/dummy_app/lib/tasks/db.rake +40 -0
  64. data/spec/dummy_app/public/404.html +26 -0
  65. data/spec/dummy_app/public/422.html +26 -0
  66. data/spec/dummy_app/public/500.html +26 -0
  67. data/spec/dummy_app/public/favicon.ico +0 -0
  68. data/spec/dummy_app/public/images/rails.png +0 -0
  69. data/spec/dummy_app/public/images/tabulatr/buttons_lite_background.png +0 -0
  70. data/spec/dummy_app/public/images/tabulatr/pager_arrow_left.gif +0 -0
  71. data/spec/dummy_app/public/images/tabulatr/pager_arrow_left_off.gif +0 -0
  72. data/spec/dummy_app/public/images/tabulatr/pager_arrow_right.gif +0 -0
  73. data/spec/dummy_app/public/images/tabulatr/pager_arrow_right_off.gif +0 -0
  74. data/spec/dummy_app/public/images/tabulatr/sort_arrow_down.gif +0 -0
  75. data/spec/dummy_app/public/images/tabulatr/sort_arrow_down_off.gif +0 -0
  76. data/spec/dummy_app/public/images/tabulatr/sort_arrow_up.gif +0 -0
  77. data/spec/dummy_app/public/images/tabulatr/sort_arrow_up_off.gif +0 -0
  78. data/spec/dummy_app/public/index.html +239 -0
  79. data/spec/dummy_app/public/javascripts/application.js +2 -0
  80. data/spec/dummy_app/public/javascripts/controls.js +965 -0
  81. data/spec/dummy_app/public/javascripts/dragdrop.js +974 -0
  82. data/spec/dummy_app/public/javascripts/effects.js +1123 -0
  83. data/spec/dummy_app/public/javascripts/prototype.js +6001 -0
  84. data/spec/dummy_app/public/javascripts/rails.js +175 -0
  85. data/spec/dummy_app/public/robots.txt +5 -0
  86. data/spec/dummy_app/public/stylesheets/.gitkeep +0 -0
  87. data/spec/dummy_app/public/stylesheets/tabulatr.css +107 -0
  88. data/spec/requests/tabulatrs_spec.rb +275 -0
  89. data/spec/spec_helper.rb +22 -0
  90. data/tabulatr.gemspec +25 -22
  91. metadata +166 -19
@@ -0,0 +1,175 @@
1
+ (function() {
2
+ // Technique from Juriy Zaytsev
3
+ // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
4
+ function isEventSupported(eventName) {
5
+ var el = document.createElement('div');
6
+ eventName = 'on' + eventName;
7
+ var isSupported = (eventName in el);
8
+ if (!isSupported) {
9
+ el.setAttribute(eventName, 'return;');
10
+ isSupported = typeof el[eventName] == 'function';
11
+ }
12
+ el = null;
13
+ return isSupported;
14
+ }
15
+
16
+ function isForm(element) {
17
+ return Object.isElement(element) && element.nodeName.toUpperCase() == 'FORM'
18
+ }
19
+
20
+ function isInput(element) {
21
+ if (Object.isElement(element)) {
22
+ var name = element.nodeName.toUpperCase()
23
+ return name == 'INPUT' || name == 'SELECT' || name == 'TEXTAREA'
24
+ }
25
+ else return false
26
+ }
27
+
28
+ var submitBubbles = isEventSupported('submit'),
29
+ changeBubbles = isEventSupported('change')
30
+
31
+ if (!submitBubbles || !changeBubbles) {
32
+ // augment the Event.Handler class to observe custom events when needed
33
+ Event.Handler.prototype.initialize = Event.Handler.prototype.initialize.wrap(
34
+ function(init, element, eventName, selector, callback) {
35
+ init(element, eventName, selector, callback)
36
+ // is the handler being attached to an element that doesn't support this event?
37
+ if ( (!submitBubbles && this.eventName == 'submit' && !isForm(this.element)) ||
38
+ (!changeBubbles && this.eventName == 'change' && !isInput(this.element)) ) {
39
+ // "submit" => "emulated:submit"
40
+ this.eventName = 'emulated:' + this.eventName
41
+ }
42
+ }
43
+ )
44
+ }
45
+
46
+ if (!submitBubbles) {
47
+ // discover forms on the page by observing focus events which always bubble
48
+ document.on('focusin', 'form', function(focusEvent, form) {
49
+ // special handler for the real "submit" event (one-time operation)
50
+ if (!form.retrieve('emulated:submit')) {
51
+ form.on('submit', function(submitEvent) {
52
+ var emulated = form.fire('emulated:submit', submitEvent, true)
53
+ // if custom event received preventDefault, cancel the real one too
54
+ if (emulated.returnValue === false) submitEvent.preventDefault()
55
+ })
56
+ form.store('emulated:submit', true)
57
+ }
58
+ })
59
+ }
60
+
61
+ if (!changeBubbles) {
62
+ // discover form inputs on the page
63
+ document.on('focusin', 'input, select, texarea', function(focusEvent, input) {
64
+ // special handler for real "change" events
65
+ if (!input.retrieve('emulated:change')) {
66
+ input.on('change', function(changeEvent) {
67
+ input.fire('emulated:change', changeEvent, true)
68
+ })
69
+ input.store('emulated:change', true)
70
+ }
71
+ })
72
+ }
73
+
74
+ function handleRemote(element) {
75
+ var method, url, params;
76
+
77
+ var event = element.fire("ajax:before");
78
+ if (event.stopped) return false;
79
+
80
+ if (element.tagName.toLowerCase() === 'form') {
81
+ method = element.readAttribute('method') || 'post';
82
+ url = element.readAttribute('action');
83
+ params = element.serialize();
84
+ } else {
85
+ method = element.readAttribute('data-method') || 'get';
86
+ url = element.readAttribute('href');
87
+ params = {};
88
+ }
89
+
90
+ new Ajax.Request(url, {
91
+ method: method,
92
+ parameters: params,
93
+ evalScripts: true,
94
+
95
+ onComplete: function(request) { element.fire("ajax:complete", request); },
96
+ onSuccess: function(request) { element.fire("ajax:success", request); },
97
+ onFailure: function(request) { element.fire("ajax:failure", request); }
98
+ });
99
+
100
+ element.fire("ajax:after");
101
+ }
102
+
103
+ function handleMethod(element) {
104
+ var method = element.readAttribute('data-method'),
105
+ url = element.readAttribute('href'),
106
+ csrf_param = $$('meta[name=csrf-param]')[0],
107
+ csrf_token = $$('meta[name=csrf-token]')[0];
108
+
109
+ var form = new Element('form', { method: "POST", action: url, style: "display: none;" });
110
+ element.parentNode.insert(form);
111
+
112
+ if (method !== 'post') {
113
+ var field = new Element('input', { type: 'hidden', name: '_method', value: method });
114
+ form.insert(field);
115
+ }
116
+
117
+ if (csrf_param) {
118
+ var param = csrf_param.readAttribute('content'),
119
+ token = csrf_token.readAttribute('content'),
120
+ field = new Element('input', { type: 'hidden', name: param, value: token });
121
+ form.insert(field);
122
+ }
123
+
124
+ form.submit();
125
+ }
126
+
127
+
128
+ document.on("click", "*[data-confirm]", function(event, element) {
129
+ var message = element.readAttribute('data-confirm');
130
+ if (!confirm(message)) event.stop();
131
+ });
132
+
133
+ document.on("click", "a[data-remote]", function(event, element) {
134
+ if (event.stopped) return;
135
+ handleRemote(element);
136
+ event.stop();
137
+ });
138
+
139
+ document.on("click", "a[data-method]", function(event, element) {
140
+ if (event.stopped) return;
141
+ handleMethod(element);
142
+ event.stop();
143
+ });
144
+
145
+ document.on("submit", function(event) {
146
+ var element = event.findElement(),
147
+ message = element.readAttribute('data-confirm');
148
+ if (message && !confirm(message)) {
149
+ event.stop();
150
+ return false;
151
+ }
152
+
153
+ var inputs = element.select("input[type=submit][data-disable-with]");
154
+ inputs.each(function(input) {
155
+ input.disabled = true;
156
+ input.writeAttribute('data-original-value', input.value);
157
+ input.value = input.readAttribute('data-disable-with');
158
+ });
159
+
160
+ var element = event.findElement("form[data-remote]");
161
+ if (element) {
162
+ handleRemote(element);
163
+ event.stop();
164
+ }
165
+ });
166
+
167
+ document.on("ajax:after", "form", function(event, element) {
168
+ var inputs = element.select("input[type=submit][disabled=true][data-disable-with]");
169
+ inputs.each(function(input) {
170
+ input.value = input.readAttribute('data-original-value');
171
+ input.removeAttribute('data-original-value');
172
+ input.disabled = false;
173
+ });
174
+ });
175
+ })();
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-Agent: *
5
+ # Disallow: /
@@ -0,0 +1,107 @@
1
+ <style type="text/css" media="screen">
2
+
3
+ body {
4
+ font: 9pt Verdana;
5
+ }
6
+
7
+ table {
8
+ border-collapse: collapse;
9
+ width:100%;
10
+ }
11
+
12
+ td, th {
13
+ border: 1px solid gray;
14
+ padding:5px;
15
+ text-overflow: ellipsis;
16
+ white-space: nowrap;
17
+ overflow: ellipsis;
18
+ }
19
+
20
+ th {
21
+ background-color: #ccc;
22
+ text-shadow: 1px 1px 1px rgba(0,0,0,.2);
23
+ }
24
+
25
+ div.table-controls {
26
+ font: 9pt Verdana;
27
+ width: 100%-10px;
28
+ border: 1px solid gray;
29
+ padding:5px;
30
+ margin-bottom: 10px;
31
+ background-color: #eee;
32
+ border-radius: 5px;
33
+ position: relative;
34
+ }
35
+
36
+ div.table-controls input {
37
+ font: 9pt Verdana;
38
+ }
39
+
40
+ div.table-controls input[type=submit] {
41
+ position: relative;
42
+ background-repeat: repeat-x;
43
+ color: #efefef;
44
+ font-weight: bold;
45
+ display: inline-block;
46
+ text-decoration: none;
47
+ border-width: 1px;
48
+ border-style: solid;
49
+ padding: 0 12px;
50
+ margin: 0;
51
+ text-shadow: 1px 1px 1px rgba(0,0,0,.2);
52
+ -moz-box-shadow: 1px 1px 1px rgba(0,0,0,.25);
53
+ -webkit-box-shadow: 1px 1px 1px rgba(0,0,0,.25);
54
+ box-shadow: 1px 1px 1px rgba(0,0,0,.25);
55
+ -moz-border-radius: 5px;
56
+ -webkit-border-radius: 5px;
57
+ border-radius: 5px;
58
+ cursor: pointer;
59
+ background-position: 0 -80px;
60
+ font-size: 11px;
61
+ height: 24px;
62
+ line-height: 24px;
63
+ }
64
+
65
+ div.table-controls input[type=submit] {
66
+ background-image: url(../images/tabulatr/buttons_lite_background.png);
67
+ background-color: #263849;
68
+ border-color: #16222c;
69
+ color: #efefef;
70
+ }
71
+
72
+ div.table-controls input[type=submit]:hover {
73
+ background-color: #16222c;
74
+ color: #efefef;
75
+ text-decoration: none;
76
+ }
77
+
78
+ div.paginator {
79
+ display: inline-block;
80
+ margin-right: 40px;
81
+ }
82
+
83
+ div.batch-actions {
84
+ display: inline-block;
85
+ }
86
+
87
+ div.check-controls {
88
+ margin-top: 10px;
89
+ position: absolute;
90
+ bottom: 5px;
91
+ right: 5px;
92
+ }
93
+
94
+ div.check-controls input[type=submit] {
95
+ font-size: 9px;
96
+ height: 20px;
97
+ line-height: 20px;
98
+ margin:3px;
99
+ }
100
+
101
+ div.info-text {
102
+ margin-top:10px;
103
+ font-size: 9pt;
104
+ }
105
+
106
+
107
+ </style>
@@ -0,0 +1,275 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Tabulatrs" do
4
+
5
+ names = ["lorem", "ipsum", "dolor", "sit", "amet", "consectetur",
6
+ "adipisicing", "elit", "sed", "eiusmod", "tempor", "incididunt", "labore",
7
+ "dolore", "magna", "aliqua", "enim", "minim", "veniam,", "quis", "nostrud",
8
+ "exercitation", "ullamco", "laboris", "nisi", "aliquip", "commodo",
9
+ "consequat", "duis", "aute", "irure", "reprehenderit", "voluptate", "velit",
10
+ "esse", "cillum", "fugiat", "nulla", "pariatur", "excepteur", "sint",
11
+ "occaecat", "cupidatat", "non", "proident", "sunt", "culpa", "qui",
12
+ "officia", "deserunt", "mollit", "anim", "est", "laborum"]
13
+
14
+ # control which tests to run. Just to spped testing up
15
+ tralse = true
16
+ # General stuf
17
+ WORKS_IN_GENERAL = CONTAINS_BUTTONS = CONTAINS_COLUMN_HEADERS = CONTAINS_OTHER_CONTROLS = tralse
18
+ # This fills in the data, so rather not cmment this out
19
+ CONTAINS_ACTUAL_DATA = CONTAINS_ACTUAL_DATA_MULTIPLE = CONTAINS_DATA_ON_FURTHER_PAGES = true
20
+ # Paginatione
21
+ PAGES_UP_AND_DOWN = JUMPS_TO_CORRECT_PAGE = CHANGES_PAGE_SIZE = tralse
22
+ # Filters
23
+ FILTERS = FILTERS_WITH_LIKE = FILTERS_WITH_RANGE = tralse
24
+ # Sorting
25
+ KNOWS_HOW_TO_SORT = tralse
26
+ # selecting and batch actions
27
+ KNOWS_HOW_TO_SELECT_AND_APPLY_BATCH_ACTIONS = tralse
28
+
29
+ vendor1 = Vendor.create!(:name => "ven d'or", :active => true)
30
+ vendor2 = Vendor.create!(:name => 'producer', :active => true)
31
+ tag1 = Tag.create!(:title => 'foo')
32
+ tag2 = Tag.create!(:title => 'bar')
33
+ tag3 = Tag.create!(:title => 'fubar')
34
+ name
35
+
36
+ describe "General data" do
37
+ it "works in general" do
38
+ get index_simple_products_path
39
+ response.status.should be(200)
40
+ end if WORKS_IN_GENERAL
41
+
42
+ it "contains buttons" do
43
+ visit index_simple_products_path
44
+ [:submit_label, :select_all_label, :select_none_label, :select_visible_label,
45
+ :unselect_visible_label, :select_filtered_label, :unselect_filtered_label
46
+ ].each do |n|
47
+ page.should have_button(Tabulatr::TABLE_OPTIONS[n])
48
+ end
49
+ end if CONTAINS_BUTTONS
50
+
51
+ it "contains column headers" do
52
+ visit index_simple_products_path
53
+ ['Id','Title','Price','Active','Vendor Name','Tags Title'].each do |n|
54
+ page.should have_content(n)
55
+ end
56
+ end if CONTAINS_COLUMN_HEADERS
57
+
58
+ it "contains other elements" do
59
+ visit index_simple_products_path
60
+ page.should have_content(sprintf(Tabulatr::TABLE_OPTIONS[:info_text], 0, 0, 0, 0))
61
+ end if CONTAINS_OTHER_CONTROLS
62
+
63
+ it "contains the actual data" do
64
+ product = Product.create!(:title => names[0], :active => true, :price => 10.0, :description => 'blah blah', :vendor => vendor1)
65
+ visit index_simple_products_path
66
+ page.should have_content(names[0])
67
+ page.should have_content("true")
68
+ page.should have_content("10.0")
69
+ page.should have_content("ven d'or")
70
+ page.should have_content(sprintf(Tabulatr::TABLE_OPTIONS[:info_text], 1, 1, 0, 1))
71
+ end if CONTAINS_ACTUAL_DATA
72
+
73
+ it "contains the actual data multiple" do
74
+ 9.times do |i|
75
+ product = Product.create!(:title => names[i+1], :active => i.even?, :price => 11.0+i,
76
+ :description => "blah blah #{i}", :vendor => i.even? ? vendor1 : vendor2)
77
+ visit index_simple_products_path
78
+ page.should have_content(names[i])
79
+ page.should have_content((11.0+i).to_s)
80
+ page.should have_content(sprintf(Tabulatr::TABLE_OPTIONS[:info_text], i+2, i+2, 0, i+2))
81
+ end
82
+ end if CONTAINS_ACTUAL_DATA_MULTIPLE
83
+
84
+ it "contains the further data on the further pages" do
85
+ names[10..-1].each_with_index do |n,i|
86
+ product = Product.create!(:title => n, :active => i.even?, :price => 20.0+i,
87
+ :description => "blah blah #{i}", :vendor => i.even? ? vendor1 : vendor2)
88
+ visit index_simple_products_path
89
+ page.should_not have_content(n)
90
+ page.should_not have_content((30.0+i).to_s)
91
+ page.should have_content(sprintf(Tabulatr::TABLE_OPTIONS[:info_text], 10, i+11, 0, i+11))
92
+ end
93
+ end if CONTAINS_DATA_ON_FURTHER_PAGES
94
+ end
95
+
96
+ describe "Pagination" do
97
+ it "pages up and down" do
98
+ visit index_simple_products_path
99
+ k = 1+names.length/10
100
+ k.times do |i|
101
+ ((i*10)...[names.length, ((i+1)*10)].min).each do |j|
102
+ page.should have_content(names[j])
103
+ end
104
+ if i==0
105
+ page.should have_no_button('product_pagination_page_left')
106
+ else
107
+ page.should have_button('product_pagination_page_left')
108
+ end
109
+ if i==k-1
110
+ page.should have_no_button('product_pagination_page_right')
111
+ else
112
+ page.should have_button('product_pagination_page_right')
113
+ click_button('product_pagination_page_right')
114
+ end
115
+ end
116
+ # ...and down
117
+ k.times do |ii|
118
+ i = k-ii-1
119
+ ((i*10)...[names.length, ((i+1)*10)].min).each do |j|
120
+ page.should have_content(names[j])
121
+ end
122
+ if i==k-1
123
+ page.should have_no_button('product_pagination_page_right')
124
+ else
125
+ page.should have_button('product_pagination_page_right')
126
+ end
127
+ if i==0
128
+ page.should have_no_button('product_pagination_page_left')
129
+ else
130
+ page.should have_button('product_pagination_page_left')
131
+ click_button('product_pagination_page_left')
132
+ end
133
+ end
134
+ end if PAGES_UP_AND_DOWN
135
+
136
+ it "jumps to the correct page" do
137
+ visit index_simple_products_path
138
+ k = 1+names.length/10
139
+ l = (1..k).entries.shuffle
140
+ l.each do |ii|
141
+ i = ii-1
142
+ fill_in("product_pagination[page]", :with => ii.to_s)
143
+ click_button("Apply")
144
+ ((i*10)...[names.length, ((i+1)*10)].min).each do |j|
145
+ page.should have_content(names[j])
146
+ end
147
+ if i==0
148
+ page.should have_no_button('product_pagination_page_left')
149
+ else
150
+ page.should have_button('product_pagination_page_left')
151
+ end
152
+ if i==k-1
153
+ page.should have_no_button('product_pagination_page_right')
154
+ else
155
+ page.should have_button('product_pagination_page_right')
156
+ end
157
+ end
158
+ end if JUMPS_TO_CORRECT_PAGE
159
+
160
+ it "changes the page size" do
161
+ visit index_simple_products_path
162
+ [50,20,10].each do |s|
163
+ select s.to_s, :from => "product_pagination[pagesize]"
164
+ click_button "Apply"
165
+ s.times do |i|
166
+ page.should have_content(names[i])
167
+ end
168
+ page.should_not have_content(names[s])
169
+ end
170
+ end if CHANGES_PAGE_SIZE
171
+ end
172
+
173
+ describe "Filters" do
174
+ it "filters" do
175
+ visit index_simple_products_path
176
+ #save_and_open_page
177
+ fill_in("product_filter[title]", :with => "lorem")
178
+ click_button("Apply")
179
+ page.should have_content("lorem")
180
+ page.should have_content(sprintf(Tabulatr::TABLE_OPTIONS[:info_text], 1, names.length, 0, 1))
181
+ fill_in("product_filter[title]", :with => "loreem")
182
+ click_button("Apply")
183
+ page.should_not have_content("lorem")
184
+ page.should have_content(sprintf(Tabulatr::TABLE_OPTIONS[:info_text], 0, names.length, 0, 0))
185
+ end if FILTERS
186
+
187
+ it "filters with like" do
188
+ visit index_filters_products_path
189
+ %w{a o lo lorem}.each do |str|
190
+ fill_in("product_filter[title][like]", :with => str)
191
+ click_button("Apply")
192
+ page.should have_content(str)
193
+ tot = (names.select do |s| s.match Regexp.new(str) end).length
194
+ page.should have_content(sprintf(Tabulatr::TABLE_OPTIONS[:info_text], [10,tot].min, names.length, 0, tot))
195
+ end
196
+ end if FILTERS_WITH_LIKE
197
+
198
+ it "filters with range" do
199
+ visit index_filters_products_path
200
+ n = names.length
201
+ (0..n/2).each do |i|
202
+ fill_in("product_filter[price][from]", :with => (10+i).to_s)
203
+ fill_in("product_filter[price][to]", :with => "")
204
+ click_button("Apply")
205
+ tot = n-i
206
+ #save_and_open_page
207
+ page.should have_content(sprintf(Tabulatr::TABLE_OPTIONS[:info_text], [10,tot].min, n, 0, tot))
208
+ fill_in("product_filter[price][to]", :with => (10+i).to_s)
209
+ fill_in("product_filter[price][from]", :with => "")
210
+ click_button("Apply")
211
+ tot = i+1
212
+ #save_and_open_page
213
+ page.should have_content(sprintf(Tabulatr::TABLE_OPTIONS[:info_text], [10,tot].min, n, 0, tot))
214
+ fill_in("product_filter[price][from]", :with => (10+i).to_s)
215
+ fill_in("product_filter[price][to]", :with => (10+n-i-1).to_s)
216
+ click_button("Apply")
217
+ tot = n-i*2
218
+ page.should have_content(sprintf(Tabulatr::TABLE_OPTIONS[:info_text], [10,tot].min, n, 0, tot))
219
+ end
220
+ end if FILTERS_WITH_RANGE
221
+ end
222
+
223
+ describe "Sorting" do
224
+ it "knows how to sort" do
225
+ visit index_sort_products_path
226
+ (1..10).each do |i|
227
+ page.should have_content names[-i]
228
+ end
229
+ click_button("product_sort_title_desc")
230
+ snames = names.sort
231
+ (1..10).each do |i|
232
+ page.should have_content snames[-i]
233
+ end
234
+ click_button("product_sort_title_asc")
235
+ (1..10).each do |i|
236
+ page.should have_content snames[i-1]
237
+ end
238
+ end if KNOWS_HOW_TO_SORT
239
+ end
240
+
241
+ describe "Select and Batch actions" do
242
+ it "knows how to select and apply batch actions" do
243
+ visit index_select_products_path
244
+ n = names.length
245
+ (n/10).times do |i|
246
+ (1..3).each do |j|
247
+ check("product_checked_#{10*i+j}")
248
+ end
249
+ click_button("Apply")
250
+ tot = 3*(i+1)
251
+ page.should have_content(sprintf(Tabulatr::TABLE_OPTIONS[:info_text], 10, n, tot, n))
252
+ click_button('product_pagination_page_right')
253
+ end
254
+ select 'Delete', :from => 'product_batch'
255
+ click_button("Apply")
256
+ tot = n-3*(n/10)
257
+ page.should have_content(sprintf(Tabulatr::TABLE_OPTIONS[:info_text], 10, tot, 0, tot))
258
+ #save_and_open_page
259
+ end if KNOWS_HOW_TO_SELECT_AND_APPLY_BATCH_ACTIONS
260
+ end
261
+
262
+ # describe "GET /products empty" do
263
+ # it "works in general" do
264
+ # get products_path
265
+ # response.status.should be(200)
266
+ # end
267
+ # end
268
+
269
+
270
+ end
271
+
272
+
273
+
274
+
275
+