bcms_rankings 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +165 -0
- data/README.markdown +8 -0
- data/app/controllers/application_controller.rb +10 -0
- data/app/controllers/cms/page_rankings_controller.rb +2 -0
- data/app/controllers/page_rankings_controller.rb +12 -0
- data/app/helpers/application_helper.rb +3 -0
- data/app/models/page_ranking.rb +14 -0
- data/app/portlets/highest_ranked_pages_portlet.rb +13 -0
- data/app/portlets/rank_this_page_portlet.rb +23 -0
- data/app/views/cms/page_rankings/_form.html.erb +2 -0
- data/app/views/cms/page_rankings/render.html.erb +3 -0
- data/app/views/portlets/highest_ranked_pages/_form.html.erb +3 -0
- data/app/views/portlets/highest_ranked_pages/render.html.erb +7 -0
- data/app/views/portlets/rank_this_page/_form.html.erb +2 -0
- data/app/views/portlets/rank_this_page/render.html.erb +15 -0
- data/db/migrate/20090430194533_create_page_rankings.rb +19 -0
- data/lib/bcms_rankings/routes.rb +12 -0
- data/lib/bcms_rankings.rb +1 -0
- data/rails/init.rb +3 -0
- data/test/functional/page_rankings_controller_test.rb +24 -0
- data/test/performance/browsing_test.rb +9 -0
- data/test/test_helper.rb +38 -0
- data/test/unit/highest_ranked_pages_portlet_test.rb +41 -0
- data/test/unit/page_ranking_test.rb +33 -0
- data/test/unit/rank_this_page_portlet_test.rb +53 -0
- metadata +77 -0
data/LICENSE.txt
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
2
|
+
Version 3, 29 June 2007
|
3
|
+
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
6
|
+
of this license document, but changing it is not allowed.
|
7
|
+
|
8
|
+
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
11
|
+
License, supplemented by the additional permissions listed below.
|
12
|
+
|
13
|
+
0. Additional Definitions.
|
14
|
+
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
17
|
+
General Public License.
|
18
|
+
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
20
|
+
other than an Application or a Combined Work as defined below.
|
21
|
+
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
25
|
+
of using an interface provided by the Library.
|
26
|
+
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
28
|
+
Application with the Library. The particular version of the Library
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
30
|
+
Version".
|
31
|
+
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
35
|
+
based on the Application, and not on the Linked Version.
|
36
|
+
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
38
|
+
object code and/or source code for the Application, including any data
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
41
|
+
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
43
|
+
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
46
|
+
|
47
|
+
2. Conveying Modified Versions.
|
48
|
+
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
51
|
+
that uses the facility (other than as an argument passed when the
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
53
|
+
version:
|
54
|
+
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
56
|
+
ensure that, in the event an Application does not supply the
|
57
|
+
function or data, the facility still operates, and performs
|
58
|
+
whatever part of its purpose remains meaningful, or
|
59
|
+
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
61
|
+
this License applicable to that copy.
|
62
|
+
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
64
|
+
|
65
|
+
The object code form of an Application may incorporate material from
|
66
|
+
a header file that is part of the Library. You may convey such object
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
68
|
+
material is not limited to numerical parameters, data structure
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
71
|
+
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
73
|
+
Library is used in it and that the Library and its use are
|
74
|
+
covered by this License.
|
75
|
+
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
77
|
+
document.
|
78
|
+
|
79
|
+
4. Combined Works.
|
80
|
+
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
82
|
+
taken together, effectively do not restrict modification of the
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
85
|
+
the following:
|
86
|
+
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
88
|
+
the Library is used in it and that the Library and its use are
|
89
|
+
covered by this License.
|
90
|
+
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
92
|
+
document.
|
93
|
+
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
95
|
+
execution, include the copyright notice for the Library among
|
96
|
+
these notices, as well as a reference directing the user to the
|
97
|
+
copies of the GNU GPL and this license document.
|
98
|
+
|
99
|
+
d) Do one of the following:
|
100
|
+
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
102
|
+
License, and the Corresponding Application Code in a form
|
103
|
+
suitable for, and under terms that permit, the user to
|
104
|
+
recombine or relink the Application with a modified version of
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
107
|
+
Corresponding Source.
|
108
|
+
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
111
|
+
a copy of the Library already present on the user's computer
|
112
|
+
system, and (b) will operate properly with a modified version
|
113
|
+
of the Library that is interface-compatible with the Linked
|
114
|
+
Version.
|
115
|
+
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
117
|
+
be required to provide such information under section 6 of the
|
118
|
+
GNU GPL, and only to the extent that such information is
|
119
|
+
necessary to install and execute a modified version of the
|
120
|
+
Combined Work produced by recombining or relinking the
|
121
|
+
Application with a modified version of the Linked Version. (If
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
126
|
+
for conveying Corresponding Source.)
|
127
|
+
|
128
|
+
5. Combined Libraries.
|
129
|
+
|
130
|
+
You may place library facilities that are a work based on the
|
131
|
+
Library side by side in a single library together with other library
|
132
|
+
facilities that are not Applications and are not covered by this
|
133
|
+
License, and convey such a combined library under terms of your
|
134
|
+
choice, if you do both of the following:
|
135
|
+
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
137
|
+
on the Library, uncombined with any other library facilities,
|
138
|
+
conveyed under the terms of this License.
|
139
|
+
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
141
|
+
is a work based on the Library, and explaining where to find the
|
142
|
+
accompanying uncombined form of the same work.
|
143
|
+
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
145
|
+
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
148
|
+
versions will be similar in spirit to the present version, but may
|
149
|
+
differ in detail to address new problems or concerns.
|
150
|
+
|
151
|
+
Each version is given a distinguishing version number. If the
|
152
|
+
Library as you received it specifies that a certain numbered version
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
154
|
+
applies to it, you have the option of following the terms and
|
155
|
+
conditions either of that published version or of any later version
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
160
|
+
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
164
|
+
permanent authorization for you to choose that version for the
|
165
|
+
Library.
|
data/README.markdown
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# Rankings Module for BrowserCMS
|
2
|
+
This is module for BrowserCMS, which allows users to rank pages. It includes the following features:
|
3
|
+
|
4
|
+
* Rank This Page - Users can use a control on a page that allows users to rank a page from 1-5.
|
5
|
+
* Highest Ranked Pages - Users can see a list of pages which have the highest rank.
|
6
|
+
|
7
|
+
This module is primarily for demo purposes, and currently does not have any 'voter fraud' detection to prevent multiple
|
8
|
+
votes. Ideally, this would need to be done client side, with a cookie, so as to keep pages cachable in the CMS.
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Filters added to this controller apply to all controllers in the application.
|
2
|
+
# Likewise, all the methods added will be available for all controllers.
|
3
|
+
|
4
|
+
class ApplicationController < ActionController::Base
|
5
|
+
helper :all # include all helpers, all the time
|
6
|
+
protect_from_forgery # See ActionController::RequestForgeryProtection for details
|
7
|
+
|
8
|
+
# Scrub sensitive parameters from your log
|
9
|
+
# filter_parameter_logging :password
|
10
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class PageRankingsController < ApplicationController
|
2
|
+
|
3
|
+
def create
|
4
|
+
@page_ranking = PageRanking.new(params[:page_ranking])
|
5
|
+
@page_ranking.ip = request.remote_ip
|
6
|
+
@page_ranking.name = "Page '#{@page_ranking.page.name}' ranked as #{@page_ranking.rank}"
|
7
|
+
if !@page_ranking.save
|
8
|
+
flash[:notice] = "New Ranking was created"
|
9
|
+
end
|
10
|
+
redirect_to @page_ranking.page.path
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class PageRanking < ActiveRecord::Base
|
2
|
+
acts_as_content_block
|
3
|
+
|
4
|
+
belongs_to :page
|
5
|
+
|
6
|
+
validates_presence_of :page_id
|
7
|
+
|
8
|
+
named_scope :for_page, lambda{|p| {:conditions => ["page_rankings.page_id = ?", p.id]}}
|
9
|
+
|
10
|
+
|
11
|
+
def self.rank(page, rank)
|
12
|
+
PageRanking.create!(:page=>page, :rank=>rank)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class HighestRankedPagesPortlet < Portlet
|
2
|
+
|
3
|
+
def render
|
4
|
+
@pages =
|
5
|
+
Page.find(:all,
|
6
|
+
:select => 'pages.*, COUNT(page_rankings.id) AS rankings_count, AVG(page_rankings.rank) as avg_rank',
|
7
|
+
:joins => 'INNER JOIN page_rankings ON page_rankings.page_id = pages.id',
|
8
|
+
:group => 'pages.id',
|
9
|
+
:limit => @portlet.number_to_show,
|
10
|
+
:order => "avg_rank desc")
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class RankThisPagePortlet < Portlet
|
2
|
+
|
3
|
+
def render
|
4
|
+
@page = @controller.instance_variable_get("@page")
|
5
|
+
if @page
|
6
|
+
@rankings = PageRanking.for_page(@page)
|
7
|
+
@average_rank = average_ranking(@rankings)
|
8
|
+
|
9
|
+
# For the form to create a new ranking
|
10
|
+
@page_ranking = PageRanking.new(:page => @page)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def average_ranking(rankings)
|
15
|
+
return 0 unless rankings.size > 0
|
16
|
+
total = 0.0
|
17
|
+
rankings.each do |r|
|
18
|
+
total = total + r.rank
|
19
|
+
end
|
20
|
+
(total/rankings.size).round_with_precision(1)
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
<h2>Highest Ranked Pages</h2>
|
2
|
+
<p>The list of pages below shows the highest ranked pages, in order of popularity.</p>
|
3
|
+
<ol>
|
4
|
+
<% @pages.each do |page| %>
|
5
|
+
<li><%= link_to page.name, page.path %>: Average is <%= page.avg_rank.to_f.round_with_precision(1) %> with <%= page.rankings_count %> total votes.</li>
|
6
|
+
<% end %>
|
7
|
+
</ol>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<% if @page %>
|
2
|
+
Average rank is <%= @average_rank %> out of <%= @rankings.size %> total.
|
3
|
+
<h3>Rank this Page</h3>
|
4
|
+
<p>Please rank the quality of this page, with #1 being the worst, and #5 the best.</p>
|
5
|
+
<% form_for @page_ranking do |f| %>
|
6
|
+
<%= f.hidden_field :page_id %>
|
7
|
+
<% (1..5).each do |count| %>
|
8
|
+
<%= count %><%= f.radio_button :rank, count %>
|
9
|
+
<% end %>
|
10
|
+
<%= f.submit "Rate It!" %>
|
11
|
+
|
12
|
+
<% end %>
|
13
|
+
<% else %>
|
14
|
+
This portlet must be placed on a page in order to view it.
|
15
|
+
<% end %>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class CreatePageRankings < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_versioned_table :page_rankings do |t|
|
4
|
+
t.belongs_to :page
|
5
|
+
t.string :name
|
6
|
+
t.integer :rank
|
7
|
+
t.string :ip
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
ContentType.create!(:name => "PageRanking", :group_name => "Page Ranking")
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.down
|
15
|
+
ContentType.delete_all(['name = ?', 'PageRanking'])
|
16
|
+
drop_table :page_ranking_versions
|
17
|
+
drop_table :page_rankings
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Cms::Routes
|
2
|
+
def routes_for_bcms_rankings
|
3
|
+
page_rankings "/page_rankings",
|
4
|
+
:controller => "page_rankings",
|
5
|
+
:action => "create",
|
6
|
+
:conditions => {:method => :post}
|
7
|
+
|
8
|
+
namespace(:cms) do |cms|
|
9
|
+
cms.content_blocks :page_rankings
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'bcms_rankings/routes'
|
data/rails/init.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '/../test_helper')
|
2
|
+
|
3
|
+
class PageRankingsControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
test "Should create a ranking with a name" do
|
10
|
+
page = Page.create!(:name => "Rank Me", :path=>"/path")
|
11
|
+
assert_equal "0.0.0.0", @request.remote_ip, "Verifies what the expected IP is from the Mock request"
|
12
|
+
|
13
|
+
post :create, :page_ranking => {:rank => 4, :page_id => page.id}
|
14
|
+
|
15
|
+
ranks = PageRanking.all
|
16
|
+
|
17
|
+
|
18
|
+
assert_equal 1, ranks.size
|
19
|
+
assert_equal page, ranks[0].page
|
20
|
+
assert_equal 4, ranks[0].rank
|
21
|
+
assert_equal "0.0.0.0", ranks[0].ip
|
22
|
+
assert_equal "Page 'Rank Me' ranked as 4", ranks[0].name
|
23
|
+
end
|
24
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
3
|
+
require 'test_help'
|
4
|
+
|
5
|
+
class ActiveSupport::TestCase
|
6
|
+
# Transactional fixtures accelerate your tests by wrapping each test method
|
7
|
+
# in a transaction that's rolled back on completion. This ensures that the
|
8
|
+
# test database remains unchanged so your fixtures don't have to be reloaded
|
9
|
+
# between every test method. Fewer database queries means faster tests.
|
10
|
+
#
|
11
|
+
# Read Mike Clark's excellent walkthrough at
|
12
|
+
# http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
|
13
|
+
#
|
14
|
+
# Every Active Record database supports transactions except MyISAM tables
|
15
|
+
# in MySQL. Turn off transactional fixtures in this case; however, if you
|
16
|
+
# don't care one way or the other, switching from MyISAM to InnoDB tables
|
17
|
+
# is recommended.
|
18
|
+
#
|
19
|
+
# The only drawback to using transactional fixtures is when you actually
|
20
|
+
# need to test transactions. Since your test is bracketed by a transaction,
|
21
|
+
# any transactions started in your code will be automatically rolled back.
|
22
|
+
self.use_transactional_fixtures = true
|
23
|
+
|
24
|
+
# Instantiated fixtures are slow, but give you @david where otherwise you
|
25
|
+
# would need people(:david). If you don't want to migrate your existing
|
26
|
+
# test cases which use the @david style and don't mind the speed hit (each
|
27
|
+
# instantiated fixtures translates to a database query per test method),
|
28
|
+
# then set this back to true.
|
29
|
+
self.use_instantiated_fixtures = false
|
30
|
+
|
31
|
+
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
32
|
+
#
|
33
|
+
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
34
|
+
# -- they do not yet inherit this setting
|
35
|
+
fixtures :all
|
36
|
+
|
37
|
+
# Add more helper methods to be used by all tests here...
|
38
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '/../test_helper')
|
2
|
+
|
3
|
+
class HighestRankedPagesPortletTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
test "Portlet should find the highest ranked pages, in order of highest average ranking" do
|
15
|
+
page_b = Page.create!(:name=>"B", :path=>"/b")
|
16
|
+
page_c = Page.create!(:name=>"C", :path=>"/c")
|
17
|
+
page_a = Page.create!(:name=>"A", :path=>"/a")
|
18
|
+
|
19
|
+
|
20
|
+
PageRanking.rank(page_a, 1)
|
21
|
+
PageRanking.rank(page_a, 1)
|
22
|
+
PageRanking.rank(page_a, 1)
|
23
|
+
PageRanking.rank(page_b, 2)
|
24
|
+
PageRanking.rank(page_b, 1)
|
25
|
+
PageRanking.rank(page_c, 1)
|
26
|
+
|
27
|
+
portlet = HighestRankedPagesPortlet.new
|
28
|
+
portlet.number_to_show = 2
|
29
|
+
# This should be unnecessary, but Portlets can't internally reference their own properties atm.
|
30
|
+
portlet.instance_variable_set(:@portlet, portlet)
|
31
|
+
|
32
|
+
portlet.render
|
33
|
+
|
34
|
+
pages = portlet.instance_variable_get(:@pages)
|
35
|
+
assert_equal [page_b, page_a], pages
|
36
|
+
assert_equal "2", pages[0].rankings_count, "should include the total # of rankings"
|
37
|
+
assert_equal "3", pages[1].rankings_count
|
38
|
+
assert_equal 1.5, pages[0].avg_rank.to_f, "should include the average rank"
|
39
|
+
assert_equal 1, pages[1].avg_rank.to_f
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '/../test_helper')
|
2
|
+
|
3
|
+
class PageRankingTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
test "Page ranking can be found per page" do
|
15
|
+
page = Page.create!(:name=>"Ranked Page", :path => "/ranked")
|
16
|
+
rank = PageRanking.create!(:name=>"Testing", :page=>page)
|
17
|
+
|
18
|
+
list = PageRanking.for_page(page)
|
19
|
+
assert_equal [rank], list, "Should find all rankings for a given page."
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
test "PageRanking.rank should create a rank for a given page" do
|
24
|
+
page = Page.create!(:name => "Name", :path=>"/path")
|
25
|
+
|
26
|
+
rank = PageRanking.rank(page, 1)
|
27
|
+
|
28
|
+
assert(PageRanking === rank, "Should create a PageRanking object")
|
29
|
+
assert_equal page, rank.page
|
30
|
+
assert_equal 1, rank.rank
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '/../test_helper')
|
2
|
+
|
3
|
+
class RankThisPagePortletTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
test "Calculate average rankings" do
|
15
|
+
portlet = RankThisPagePortlet.new
|
16
|
+
|
17
|
+
assert_equal 3, portlet.average_ranking([PageRanking.new(:rank => 2), PageRanking.new(:rank=>4)])
|
18
|
+
assert_equal 2.5, portlet.average_ranking([PageRanking.new(:rank=>2), PageRanking.new(:rank=>3)])
|
19
|
+
assert_equal 2.7, portlet.average_ranking([PageRanking.new(:rank=>2), PageRanking.new(:rank=>3), PageRanking.new(:rank=>3)])
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
# Tests the fields made available to template. Since template is copied on creation, further versions should attempt
|
24
|
+
# to be backwards compatible so as to not break previously created portlets.
|
25
|
+
test "Portlet should load all rankings, average them, and make all attributes avaiable to the template" do
|
26
|
+
page = Page.create!(:name=>"Ranked Page", :path => "/ranked")
|
27
|
+
rankings = [
|
28
|
+
PageRanking.create!(:page=>page, :rank=>3),
|
29
|
+
PageRanking.create!(:page=>page, :rank=>2)]
|
30
|
+
portlet = RankThisPagePortlet.new
|
31
|
+
|
32
|
+
class MockController
|
33
|
+
def initialize(page)
|
34
|
+
@page = page
|
35
|
+
end
|
36
|
+
end
|
37
|
+
portlet.instance_variable_set(:@controller, MockController.new(page))
|
38
|
+
|
39
|
+
portlet.render
|
40
|
+
|
41
|
+
assert_equal page, portlet.instance_variable_get(:@page)
|
42
|
+
assert_equal 2.5, portlet.instance_variable_get(:@average_rank)
|
43
|
+
assert_not_nil portlet.instance_variable_get(:@page_ranking), "Should create an empoty PageRanking for the form."
|
44
|
+
assert_equal rankings, portlet.instance_variable_get(:@rankings), "Should load all the rankings for the form."
|
45
|
+
end
|
46
|
+
|
47
|
+
test "Calculate average with no rankings" do
|
48
|
+
portlet = RankThisPagePortlet.new
|
49
|
+
|
50
|
+
assert_equal 0, portlet.average_ranking([])
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bcms_rankings
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- BrowserMedia
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-07-02 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: A Page ranking Module for BrowserCMS
|
17
|
+
email: github@browsermedia.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.markdown
|
25
|
+
files:
|
26
|
+
- app/controllers/application_controller.rb
|
27
|
+
- app/controllers/cms/page_rankings_controller.rb
|
28
|
+
- app/controllers/page_rankings_controller.rb
|
29
|
+
- app/helpers/application_helper.rb
|
30
|
+
- app/models/page_ranking.rb
|
31
|
+
- app/portlets/highest_ranked_pages_portlet.rb
|
32
|
+
- app/portlets/rank_this_page_portlet.rb
|
33
|
+
- app/views/cms/page_rankings/_form.html.erb
|
34
|
+
- app/views/cms/page_rankings/render.html.erb
|
35
|
+
- app/views/portlets/highest_ranked_pages/_form.html.erb
|
36
|
+
- app/views/portlets/highest_ranked_pages/render.html.erb
|
37
|
+
- app/views/portlets/rank_this_page/_form.html.erb
|
38
|
+
- app/views/portlets/rank_this_page/render.html.erb
|
39
|
+
- db/migrate/20090430194533_create_page_rankings.rb
|
40
|
+
- lib/bcms_rankings.rb
|
41
|
+
- lib/bcms_rankings/routes.rb
|
42
|
+
- rails/init.rb
|
43
|
+
- LICENSE.txt
|
44
|
+
- README.markdown
|
45
|
+
has_rdoc: true
|
46
|
+
homepage: http://browsercms.org
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options:
|
49
|
+
- --charset=UTF-8
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
version:
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project: browsercms
|
67
|
+
rubygems_version: 1.3.1
|
68
|
+
signing_key:
|
69
|
+
specification_version: 2
|
70
|
+
summary: A Page ranking Module for BrowserCMS
|
71
|
+
test_files:
|
72
|
+
- test/functional/page_rankings_controller_test.rb
|
73
|
+
- test/performance/browsing_test.rb
|
74
|
+
- test/test_helper.rb
|
75
|
+
- test/unit/highest_ranked_pages_portlet_test.rb
|
76
|
+
- test/unit/page_ranking_test.rb
|
77
|
+
- test/unit/rank_this_page_portlet_test.rb
|