bcms_rankings 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYRIGHT.txt +23 -0
- data/GPL.txt +674 -0
- data/Gemfile +5 -0
- data/README.markdown +32 -2
- data/app/assets/javascripts/application.js +15 -0
- data/app/assets/javascripts/bcms_rankings/application.js +15 -0
- data/app/assets/stylesheets/application.css +13 -0
- data/app/assets/stylesheets/bcms_rankings/application.css +13 -0
- data/app/controllers/bcms_rankings/application_controller.rb +4 -0
- data/app/controllers/bcms_rankings/page_rankings_controller.rb +4 -0
- data/app/controllers/page_rankings_controller.rb +1 -1
- data/app/helpers/bcms_rankings/application_helper.rb +4 -0
- data/app/models/bcms_rankings/page_ranking.rb +16 -0
- data/app/portlets/highest_ranked_pages_portlet.rb +5 -5
- data/app/portlets/rank_this_page_portlet.rb +11 -4
- data/app/views/bcms_rankings/page_rankings/_form.html.erb +2 -0
- data/app/views/{cms → bcms_rankings}/page_rankings/render.html.erb +0 -0
- data/app/views/portlets/highest_ranked_pages/render.html.erb +1 -1
- data/app/views/portlets/rank_this_page/render.html.erb +1 -1
- data/config/routes.rb +3 -0
- data/db/bcms_rankings.seeds.rb +1 -0
- data/db/migrate/20090430194533_create_page_rankings.rb +1 -10
- data/db/migrate/20120703191943_page_ranking_v2_0_0.rb +7 -0
- data/lib/bcms_rankings.rb +5 -1
- data/lib/bcms_rankings/engine.rb +11 -0
- data/lib/bcms_rankings/route_extensions.rb +9 -0
- data/lib/bcms_rankings/version.rb +3 -0
- data/lib/generators/bcms_rankings/install/USAGE +3 -0
- data/lib/generators/bcms_rankings/install/install_generator.rb +19 -0
- data/lib/tasks/bcms_rankings_tasks.rake +4 -0
- metadata +80 -51
- data/app/controllers/application_controller.rb +0 -10
- data/app/controllers/cms/page_rankings_controller.rb +0 -2
- data/app/helpers/application_helper.rb +0 -3
- data/app/models/page_ranking.rb +0 -14
- data/app/views/cms/page_rankings/_form.html.erb +0 -2
- data/lib/bcms_rankings/routes.rb +0 -12
- data/rails/init.rb +0 -3
- data/test/functional/page_rankings_controller_test.rb +0 -24
- data/test/performance/browsing_test.rb +0 -9
- data/test/test_helper.rb +0 -38
- data/test/unit/highest_ranked_pages_portlet_test.rb +0 -41
- data/test/unit/page_ranking_test.rb +0 -33
- data/test/unit/rank_this_page_portlet_test.rb +0 -53
@@ -1,10 +0,0 @@
|
|
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
|
data/app/models/page_ranking.rb
DELETED
@@ -1,14 +0,0 @@
|
|
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
|
data/lib/bcms_rankings/routes.rb
DELETED
@@ -1,12 +0,0 @@
|
|
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
|
data/rails/init.rb
DELETED
@@ -1,24 +0,0 @@
|
|
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
DELETED
@@ -1,38 +0,0 @@
|
|
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
|
@@ -1,41 +0,0 @@
|
|
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
|
@@ -1,33 +0,0 @@
|
|
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
|
@@ -1,53 +0,0 @@
|
|
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
|