Skip to content

Commit 4124981

Browse files
k1mmehJeffrey Dettmann
authored andcommitted
[LH346] - Modifications to connectable -> page relationship
1 parent 32023f1 commit 4124981

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

app/models/page.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,21 @@ class Page < ActiveRecord::Base
4141
:conditions => ['connectors.connectable_id = ? and connectors.connectable_type = ?', obj.id, obj.class.base_class.name] }
4242
end
4343
}
44+
45+
# currently_connected_to tightens the scope of connected_to by restricting to the
46+
# results to matches on current versions of pages only. This renders obj versions
47+
# useless, as the older objects will very likely have older versions of pages and
48+
# thus return no results.
49+
named_scope :currently_connected_to, lambda { |obj|
50+
ver = obj.class.versioned? ? obj.version : nil
51+
if ver
52+
{ :include => :connectors,
53+
:conditions => ['connectors.connectable_id = ? and connectors.connectable_type = ? and connectors.connectable_version = ? and connectors.page_version = pages.version', obj.id, obj.class.base_class.name, ver] }
54+
else
55+
{ :include => :connectors,
56+
:conditions => ['connectors.connectable_id = ? and connectors.connectable_type = ? and connectors.page_version = pages.version', obj.id, obj.class.base_class.name] }
57+
end
58+
}
4459

4560
has_one :section_node, :as => :node, :dependent => :destroy
4661

lib/cms/behaviors/connecting.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ def display_name_plural
3939
module InstanceMethods
4040

4141
def connected_pages
42-
Page.connected_to(self)
42+
Page.currently_connected_to(self)
4343
end
4444

4545
def connected_page_count
46-
Page.connected_to(self).count
46+
Page.currently_connected_to(self).count
4747
end
4848

4949
def content_block_type

test/functional/cms/html_blocks_controller_test.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ def test_usages
150150
@page = Factory(:page, :section => root_section, :name => "Included")
151151
@page2 = Factory(:page, :section => root_section, :path => "/other_path", :name => "Excluded")
152152
@block = Factory(:html_block, :connect_to_page_id => @page.id, :connect_to_container => "main")
153-
153+
@page.publish! # usages are only relevant when page is published
154+
154155
get :usages, :id => @block.id
155156

156157
assert_response :success
@@ -160,4 +161,4 @@ def test_usages
160161
assert_select "h3", "Content Types"
161162
end
162163

163-
end
164+
end

test/functional/cms/portlets_controller_test.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def test_usages
5050
@page = Factory(:page, :section => root_section, :name => "Test Page", :path => "test")
5151
@page.create_connector(@block, "main")
5252
@page.reload
53+
@page.publish! # usages are only relevant when page is published
5354

5455
get :usages, :id => @block.id
5556

@@ -64,4 +65,4 @@ def test_form_helpers_which_use_instructions
6465
assert_select "div.instructions", "Leave blank to send the user to the page they were trying to access"
6566

6667
end
67-
end
68+
end

0 commit comments

Comments
 (0)