ajax_pagination 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ 3002
@@ -1,92 +1,142 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'paginating with javascript on', :js => true do
4
+ def ajaxCount
5
+ page.evaluate_script("document.getElementById('countajaxloading').innerHTML").to_i # using javascript to get content because selenium cannot get content of non-visible elements
6
+ end
7
+
4
8
  it 'displays a loading image' do
5
9
  # following 3 lines to warm up loading image
6
- visit("http://localhost:#{SERVERPORT}") # goes to welcome page
7
- click_link 'About'
8
- sleep(2)
10
+ visit("http://localhost:#{SERVERSLOWPORT}") # goes to welcome page
11
+ sleep(3)
12
+ click_link 'Changelog'
13
+ sleep(3)
9
14
 
10
- visit("http://localhost:#{SERVERPORT}") # goes to welcome page
11
- page.should have_no_selector('.ajaxloader')
12
- sleep(1)
15
+ visit("http://localhost:#{SERVERSLOWPORT}") # goes to welcome page
16
+ page.should have_no_selector('.ajaxpagination-loader')
17
+ sleep(1.5)
13
18
  click_link 'About'
14
- page.should have_selector('.ajaxloader')
15
- sleep(1)
16
- page.should have_no_selector('.ajaxloader')
19
+ page.should have_selector('.ajaxpagination-loader')
20
+ sleep(1.5)
21
+ page.should have_no_selector('.ajaxpagination-loader')
17
22
  click_link 'Readme'
18
- page.should have_selector('.ajaxloader')
19
- sleep(1)
20
- page.should have_no_selector('.ajaxloader')
23
+ page.should have_selector('.ajaxpagination-loader')
24
+ sleep(1.5)
25
+ page.should have_no_selector('.ajaxpagination-loader')
21
26
  end
22
27
  it 'displays a loading image with nested and multiple paginated sections' do
23
- visit("http://localhost:#{SERVERPORT}/changelog")
28
+ visit("http://localhost:#{SERVERSLOWPORT}/changelog")
29
+ sleep(2)
30
+ page.should have_selector('#changelogpagetitle')
24
31
  find('#_paginated_section').find('.next_page').click
25
- page.should have_selector('.ajaxloader')
26
- sleep(1)
27
- page.should have_no_selector('.ajaxloader')
32
+ page.should have_selector('.ajaxpagination-loader')
33
+ sleep(1.5)
34
+ page.should have_no_selector('.ajaxpagination-loader')
28
35
  find('#signin').click
29
- visit("http://localhost:#{SERVERPORT}/posts")
30
36
  sleep(2)
37
+ visit("http://localhost:#{SERVERSLOWPORT}/posts")
38
+ sleep(2)
39
+ page.should have_selector('#postspagetitle')
31
40
  find('#page_paginated_section').find('.next_page').click
32
- page.should have_selector('.ajaxloader')
33
- sleep(1)
34
- page.should have_no_selector('.ajaxloader')
41
+ page.should have_selector('.ajaxpagination-loader')
42
+ sleep(1.5)
43
+ page.should have_no_selector('.ajaxpagination-loader')
35
44
  find('#upcomingpage_paginated_section').find('.next_page').click
36
- page.should have_selector('.ajaxloader')
37
- sleep(1)
38
- page.should have_no_selector('.ajaxloader')
45
+ page.should have_selector('.ajaxpagination-loader')
46
+ sleep(1.5)
47
+ page.should have_no_selector('.ajaxpagination-loader')
39
48
  end
40
49
  it 'shows the configured loading image' do
41
- visit("http://localhost:#{SERVERPORT}/changelog")
42
- find('#_paginated_section').find('.next_page').click
43
- page.should have_xpath("//img[@class='ajaxloader' and @src = '/assets/myajax-loader.gif']")
44
- sleep(1)
45
- visit("http://localhost:#{SERVERPORT}/posts")
46
- find('#_paginated_section').find('.next_page').click
47
- page.should have_xpath("//img[@class='ajaxloader' and @src = '/assets/ajax-loader.gif']")
50
+ # warmup images
51
+ visit("http://localhost:#{SERVERSLOWPORT}/changelog")
52
+ find('#page_paginated_section').find('.next_page').click
53
+ sleep(3)
54
+ visit("http://localhost:#{SERVERSLOWPORT}/posts")
55
+ find('#page_paginated_section').find('.next_page').click
56
+ sleep(3)
57
+
58
+
59
+ visit("http://localhost:#{SERVERSLOWPORT}/changelog")
60
+ find('#page_paginated_section').find('.next_page').click
61
+ page.should have_xpath("//img[@class='ajaxpagination-loader' and @src = '/assets/myajax-loader.gif']")
62
+ sleep(1.5)
63
+ visit("http://localhost:#{SERVERSLOWPORT}/posts")
64
+ find('#page_paginated_section').find('.next_page').click
65
+ page.should have_xpath("//img[@class='ajaxpagination-loader' and @src = '/assets/ajax-loader.gif']")
48
66
  end
49
67
  it 'works with browser back and forward buttons' do
68
+ visit("http://localhost:#{SERVERPORT}/pages/about") # warmup serverport
69
+ sleep(3)
70
+ page.should have_selector('#aboutpagetitle')
71
+
72
+ # actual test
50
73
  visit("http://localhost:#{SERVERPORT}/changelog")
51
- find('#_paginated_section').find('.next_page').click
52
74
  sleep(1)
75
+ page.should have_selector('#changelogpagetitle')
53
76
  click_link 'About'
54
77
  sleep(1)
78
+ page.should have_selector('#aboutpagetitle')
55
79
  click_link 'Readme'
56
- sleep(2)
57
- page.should have_no_selector('.ajaxloader')
80
+ sleep(1)
58
81
  page.should have_selector('#readmepagetitle')
82
+ count = ajaxCount
59
83
  page.evaluate_script('window.history.back();') # back to About
60
- page.should have_selector('.ajaxloader')
61
- sleep(1)
62
- page.should have_no_selector('.ajaxloader')
63
84
  page.should have_selector('#aboutpagetitle')
85
+ ajaxCount.should == count + 1
64
86
  page.evaluate_script('window.history.forward();') # forward to readme
65
- sleep(1)
66
87
  page.should have_selector('#readmepagetitle')
67
- page.evaluate_script('window.history.go(-2);') # back to changelog page 2
68
- sleep(1)
88
+ page.evaluate_script('window.history.go(-2);') # back to changelog
69
89
  page.should have_no_selector('#aboutpagetitle')
70
90
  page.evaluate_script('window.history.forward();') # forward to about
91
+ page.should have_selector('#aboutpagetitle')
92
+ end
93
+ it 'has correct reload behaviour on history' do
94
+ visit("http://localhost:#{SERVERPORT}/pages/about")
95
+ sleep(3) # rbx has long warmup time
96
+ page.should have_selector('#aboutpagetitle')
97
+ click_link 'Readme' # History will have [about,readme]
71
98
  sleep(1)
99
+ page.should have_selector('#readmepagetitle')
100
+ click_link 'Readme' # should not add readme to history again - behaviour should be like a page refresh
101
+ sleep(0.5)
102
+ page.should have_no_selector('.ajaxpagination-loader')
103
+ page.evaluate_script('window.history.back();') # back to About (if readme not added to history twice)
72
104
  page.should have_selector('#aboutpagetitle')
73
105
  end
106
+ it 'has correct reload behaviour when jumping between history with the same url' do
107
+ visit("http://localhost:#{SERVERPORT}/pages/about")
108
+ sleep(3) # allow warmup time (zzz... rbx)
109
+ page.should have_selector('#aboutpagetitle')
110
+ click_link 'Readme' # History will have [about,readme]
111
+ sleep(1)
112
+ page.should have_selector('#readmepagetitle')
113
+ click_link 'About' # History will have [about,readme,about]
114
+ sleep(1)
115
+ page.should have_selector('#aboutpagetitle')
116
+ find("#aboutpagetitle").text.should_not == "ReloadReferenceToken"
117
+ page.evaluate_script('document.getElementById("aboutpagetitle").innerHTML = "ReloadReferenceToken";') # allows us to tell if it got reloaded
118
+ find("#aboutpagetitle").text.should == "ReloadReferenceToken"
119
+ page.evaluate_script('window.history.go(-2);') # back from about page to about page again
120
+
121
+ sleep(1)
122
+ find("#aboutpagetitle").text.should == "ReloadReferenceToken" # hasn't reloaded if token is still there
123
+ end
74
124
  it 'displays error pages within div' do
75
125
  visit("http://localhost:#{SERVERPORT}") # goes to welcome page
126
+ sleep(1)
76
127
  click_link("AJAX Pagination Example Application")
77
- sleep(2)
78
128
  page.current_url.should == "http://localhost:#{SERVERPORT}/broken%20link"
79
129
  page.should have_content("AJAX Pagination Example Application")
80
130
  page.should have_content("No route matches")
81
131
  end
82
132
  it 'changes url to match redirection' do
83
133
  visit("http://localhost:#{SERVERPORT}")
134
+ sleep(1)
84
135
  click_link("Posts")
85
136
  sleep(1)
86
137
  page.should have_content("New Post")
87
138
  myurl = page.current_url # to get the canonical url
88
139
  click_link("New Post")
89
- sleep(2)
90
140
  page.should have_content("Access Denied")
91
141
  page.current_url.should == myurl
92
142
  end
@@ -94,7 +144,6 @@ describe 'paginating with javascript on', :js => true do
94
144
  visit("http://localhost:#{SERVERPORT}/pages/about")
95
145
  count = page.find("#submits").html.to_i
96
146
  click_button("Submit")
97
- sleep(1)
98
147
  page.should have_content("#{count+1} submit")
99
148
  page.should have_selector('#aboutpagetitle') # ensures loading was via AJAX Pagination
100
149
  end
@@ -103,11 +152,10 @@ describe 'paginating with javascript on', :js => true do
103
152
  myurl = page.current_url # to get the canonical url
104
153
  count = page.find("#submits").html.to_i
105
154
  click_button("Submit")
106
- sleep(1)
107
155
  page.should have_content("#{count+1} submit")
108
156
  page.current_url.should == myurl # url remains the same (so history has not changed)
109
157
  end
110
- it 'submits ajax_form_for form via POST and PUT and DELETE link' do
158
+ it 'submits ajax_form_for form via POST and DELETE link' do
111
159
  visit("http://localhost:#{SERVERPORT}")
112
160
  find('#signin').click
113
161
  click_link("Posts")
@@ -115,34 +163,48 @@ describe 'paginating with javascript on', :js => true do
115
163
  page.should have_content("New Post")
116
164
  myurl = page.current_url # to get the canonical url
117
165
  visit("http://localhost:#{SERVERPORT}/posts/new")
166
+ sleep(1)
118
167
  within("#new_post") do
119
168
  fill_in 'Title', :with => 'very unique title for test'
120
169
  fill_in 'Content', :with => 'my supercontent'
121
170
  end
171
+ count = ajaxCount
122
172
  click_button("Create Post");
123
- page.should have_selector('.ajaxloader')
124
173
  sleep(2)
125
174
  page.should have_content("Post was successfully created.")
175
+ ajaxCount.should == count + 1
126
176
  page.current_url.should_not == myurl # means we have gotten redirected
127
- click_link("Edit");
128
- within(".edit_post") do
129
- fill_in 'Content', :with => 'my supercontent again'
130
- end
131
- click_button("Update Post");
132
- page.should have_selector('.ajaxloader')
133
- sleep(2)
134
- page.should have_content("my supercontent again")
177
+
178
+ count = ajaxCount
135
179
  click_link("Destroy");
136
180
  page.driver.browser.switch_to.alert.accept
137
- page.should have_selector('.ajaxloader')
138
181
  sleep(2)
139
182
  page.should have_content("Post destroyed.")
183
+ ajaxCount.should == count + 1
140
184
  end
185
+ ## This spec does not work in rbx on travis.
186
+ ## Tested to work in rbx-1.2.4 on local machine. Also works using MRI ruby on travis.
187
+ #it 'submits ajax_form_for form via PUT link' do
188
+ # visit("http://localhost:#{SERVERPORT}")
189
+ # find('#signin').click
190
+ # sleep(2)
191
+ # visit("http://localhost:#{SERVERPORT}/posts/2")
192
+ # click_link("Edit");
193
+ # sleep(2)
194
+ # within(".edit_post") do
195
+ # fill_in 'Content', :with => 'some supercontent'
196
+ # end
197
+ # count = ajaxCount
198
+ # click_button("Update Post");
199
+ # sleep(3)
200
+ # # page.should have_content("Post was successfully updated.") # does not work in rbx on travis (????)
201
+ # page.should have_content("some supercontent")
202
+ # ajaxCount.should == count + 1
203
+ #end
141
204
  it 'changes title' do
142
205
  visit("http://localhost:#{SERVERPORT}")
143
206
  title = page.evaluate_script("document.title") # because what is between the <title> tags and what is shown in the window title can differ (document.title gets set by javascript)
144
207
  click_link("About");
145
- sleep(1)
146
208
  page.should have_selector('#aboutpagetitle') # ensures loading was via AJAX Pagination
147
209
  page.evaluate_script("document.title").should_not == title
148
210
  end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'disabled with javascript', :js => true do
4
+ before :each do
5
+ visit("http://localhost:#{SERVERPORT}/pages/warnings")
6
+ find("#disablehistoryjslink").click
7
+ page.driver.browser.switch_to.alert.accept
8
+ end
9
+ it 'link within action still works' do
10
+ find("#fullpagelink").click
11
+ page.should have_content("You are on page 2")
12
+ end
13
+
14
+ it 'site navigation still works' do
15
+ click_link("Readme")
16
+ page.should have_selector('#readmepagetitle')
17
+ end
18
+ end
@@ -20,10 +20,11 @@ describe 'paginating with javascript on', :type => :request, :driver => :seleniu
20
20
  visit("http://localhost:#{SERVERPORT}/posts")
21
21
  page.should have_selector('#page_paginated_section .previous_page.disabled')
22
22
  find('#page_paginated_section').find('.next_page').click
23
+ sleep(1)
23
24
  page.should have_no_selector('#page_paginated_section .previous_page.disabled')
24
25
  page.should have_selector('#upcomingpage_paginated_section .previous_page.disabled')
25
26
  find('#upcomingpage_paginated_section').find('.next_page').click
26
- sleep(0.5)
27
+ sleep(1)
27
28
  page.should have_no_selector('#upcomingpage_paginated_section .previous_page.disabled')
28
29
  page.should have_no_selector('#page_paginated_section .previous_page.disabled')
29
30
  end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'javascript warnings', :js => true do
4
+ it 'warns about excess page content' do
5
+ visit("http://localhost:#{SERVERPORT}/pages/warnings")
6
+ find("#fullpagelink").click
7
+ sleep(0.5)
8
+ alertmsg = page.driver.browser.switch_to.alert.text
9
+ alertmsg.should include("EXTRA_CONTENT_DISCARDED")
10
+ page.driver.browser.switch_to.alert.accept
11
+ page.should have_content("You are on page 2")
12
+ end
13
+
14
+ it 'warns about missing dependencies' do
15
+ visit("http://localhost:#{SERVERPORT}/pages/warnings")
16
+ find("#disablehistoryjslink").click
17
+ sleep(0.5)
18
+ alertmsg = page.driver.browser.switch_to.alert.text
19
+ alertmsg.should include("MISSING_DEPENDENCIES")
20
+ page.driver.browser.switch_to.alert.accept
21
+ page.should have_content("Disabled")
22
+ end
23
+
24
+ it 'warns about missing reference' do
25
+ visit("http://localhost:#{SERVERPORT}/pages/warnings")
26
+ find("#missingreferencelink").click
27
+ alertmsg = page.driver.browser.switch_to.alert.text
28
+ alertmsg.should include("MISSING_REFERENCE")
29
+ page.driver.browser.switch_to.alert.accept
30
+ end
31
+
32
+ it 'warns about reference to more than one section of same id' do
33
+ visit("http://localhost:#{SERVERPORT}/pages/warnings")
34
+ find("#doublesectionlink").click
35
+ alertmsg = page.driver.browser.switch_to.alert.text
36
+ alertmsg.should include("UNIQUE_SECTION_NOT_FOUND")
37
+ page.driver.browser.switch_to.alert.accept
38
+ end
39
+
40
+ it 'warns about reference to section which does not exist' do
41
+ visit("http://localhost:#{SERVERPORT}/pages/warnings")
42
+ find("#nosectionlink").click
43
+ alertmsg = page.driver.browser.switch_to.alert.text
44
+ alertmsg.should include("UNIQUE_SECTION_NOT_FOUND")
45
+ page.driver.browser.switch_to.alert.accept
46
+ end
47
+ end
@@ -39,4 +39,4 @@ gem 'ajax_pagination', :path => "../.."
39
39
  # gem 'capistrano'
40
40
 
41
41
  # To use debugger
42
- gem 'ruby-debug'
42
+ # gem 'ruby-debug' # requires MRI Ruby
@@ -9,6 +9,7 @@
9
9
  * compiled file, but it's generally better to create a new file per style scope.
10
10
  *
11
11
  *= require_self
12
+ *= require ajax_pagination
12
13
  *= require_tree .
13
14
  */
14
15
 
@@ -3,8 +3,10 @@ class ApplicationController < ActionController::Base
3
3
  before_filter :slowajaxload
4
4
  ajax_pagination :pagination => "", :render => { :layout => "ajax" }
5
5
  def slowajaxload
6
- if params[:pagination] && Rails.env == "test"
7
- sleep(1)
6
+ if (request.GET[:pagination] || params[:pagination]) && Rails.env == "test"
7
+ delay = 0
8
+ delay = ENV['AJAX_DELAY'] if ENV['AJAX_DELAY']
9
+ sleep(delay.to_f)
8
10
  end
9
11
  end
10
12
 
@@ -18,4 +18,11 @@ class PagesController < ApplicationController
18
18
  ajax_pagination format, :pagination => "", :render => { :layout => "ajax" }
19
19
  end
20
20
  end
21
+
22
+ def warnings
23
+ respond_to do |format|
24
+ format.html
25
+ ajax_pagination format, :pagination => "disable", :render => { :layout => "ajax" }
26
+ end
27
+ end
21
28
  end
@@ -1,3 +1,3 @@
1
- <h2>Changelog</h2>
1
+ <h2 id="changelogpagetitle">Changelog</h2>
2
2
 
3
3
  <%= ajax_pagination %>
@@ -7,6 +7,18 @@
7
7
  <%= csrf_meta_tags %>
8
8
  </head>
9
9
  <body>
10
+ <div id="countajaxloading" style="display: none;">0</div>
11
+ <script type="text/javascript">
12
+ $(document).ready(function () {
13
+ $(document).on("ajaxp:loading", function() { // increment hidden div every time something loads
14
+ $("#countajaxloading").text((parseInt($("#countajaxloading").text(),10) + 1).toString());
15
+ });
16
+ });
17
+ /*jQuery(document).ready(function () {
18
+ alert($.ajax_pagination.version);
19
+ $.ajax_pagination("").get("http://localhost:3000/pages/about");
20
+ });*/
21
+ </script>
10
22
  <div style="float: right;">
11
23
  <% if session[:admin] %>
12
24
  <%= link_to "Sign out", sessions_signout_url, :id => "signout" %>
@@ -26,6 +38,7 @@
26
38
  <li><%= link_to "Posts", posts_url %></li>
27
39
  <li><%= link_to "Changelog", changelog_url %></li>
28
40
  <li><%= link_to "Readme", pages_readme_url %></li>
41
+ <li><%= link_to "Warnings", pages_warnings_url %></li>
29
42
  <li><%= link_to "About", pages_about_url %></li>
30
43
  </ul>
31
44
  </div>
@@ -0,0 +1,43 @@
1
+
2
+ This page gives examples of the warnings that may be given, from AJAX Pagination, when some configuration or otherwise is suboptimal, or prevents proper functioning of the gem.
3
+
4
+ <%= content_tag :div, :style => "display: inline-block; width: 300px; height: 100px; border: 1px solid black; margin: 10px; padding: 10px; vertical-align: middle;" do %>
5
+ <%= ajax_pagination do %>
6
+ <p>You are on page <%= params[:page] ||= 1 %>.</p>
7
+
8
+ <p><%= ajax_link_to "Reload whole page just to refresh this content", pages_warnings_path(:page => (params[:page].to_i+1)), :pagination => "page", :id => "fullpagelink" %></p>
9
+ <% end %>
10
+ <% end %>
11
+
12
+ <%= content_tag :div, :style => "display: inline-block; width: 300px; height: 100px; border: 1px solid black; margin: 10px; padding: 10px; vertical-align: middle;" do %>
13
+ <p>AJAX Pagination Status: <%= raw (params[:disable] ||= false)?"<span style=\"color:red;\">Disabled":"<span style=\"color:green;\">Enabled" %></span></p>
14
+ <% if params[:disable] %>
15
+ <script type="text/javascript">History = null;</script>
16
+ <p><%= link_to "Enable History.js", pages_warnings_path %></p>
17
+ <% else %>
18
+ <p><%= link_to "Disable History.js", pages_warnings_path(:disable => true), :id => "disablehistoryjslink" %></p>
19
+ <% end %>
20
+ <p><i>Note: History.js is an AJAX Pagination dependency.</i></p>
21
+ <% end %>
22
+
23
+ <%= content_tag :div, :style => "display: inline-block; width: 300px; height: 100px; border: 1px solid black; margin: 10px; padding: 10px; vertical-align: middle;" do %>
24
+ <p>AJAX Links need to reference a valid pagination section, otherwise AJAX Pagination doesn't know where the new content should go.</p>
25
+ <p><%= ajax_link_to "Link without valid AJAX Pagination section", pages_warnings_path, :pagination => "RANDOM", :id => "nosectionlink" %></p>
26
+ <% end %>
27
+
28
+ <%= content_tag :div, :style => "display: inline-block; width: 300px; height: 100px; border: 1px solid black; margin: 10px; padding: 10px; vertical-align: middle;" do %>
29
+ <%= content_tag :div, :style => "border: 1px solid black; margin: 10px;" do %>
30
+ <%= ajax_pagination :pagination => "double" do %>My section name is "double".<% end %>
31
+ <% end %>
32
+ <%= content_tag :div, :style => "border: 1px solid black; margin: 10px;" do %>
33
+ <%= ajax_pagination :pagination => "double" do %>My section name is "double".<% end %>
34
+ <% end %>
35
+ <p><%= ajax_link_to "Load stuff in section named \"double\"", pages_warnings_path, :pagination => "double", :id => "doublesectionlink" %></p>
36
+ <% end %>
37
+
38
+ <%= content_tag :div, :class => "paginated_section", :style => "display: inline-block; width: 300px; height: 100px; border: 1px solid black; margin: 10px; padding: 10px; vertical-align: middle;" do %>
39
+ <%= content_tag :div, :class => "ajaxpagination" do %>
40
+ <p>If a link does not reference a section into which content can be loaded, AJAX will be cancelled, and the link will load in the whole window.</p>
41
+ <p><%= link_to "Link without reference to any section", pages_warnings_path, :id => "missingreferencelink" %></p>
42
+ <% end %>
43
+ <% end %>