Skip to content

Commit a606b13

Browse files
committed
Updates bcms to ruby 2.3
1 parent 7314a8b commit a606b13

File tree

10 files changed

+32
-31
lines changed

10 files changed

+32
-31
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
source 'http://rubygems.org'
22

3-
ruby '2.0.0'
3+
ruby '2.3.0'
44

55
# Load this project as a gem.
66
gemspec

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ DEPENDENCIES
342342
yard
343343

344344
RUBY VERSION
345-
ruby 2.0.0p645
345+
ruby 2.3.0p0
346346

347347
BUNDLED WITH
348348
1.14.6

app/models/cms/content_type.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ def available_by_module
3232
modules[content_type.module_name] = [] unless modules[content_type.module_name]
3333
modules[content_type.module_name] << content_type
3434
end
35-
modules
35+
modules.compact
3636
end
37-
3837
# Returns a list of all ContentTypes in the system. Content Types can opt out of this list by specifying:
3938
#
4039
# class MyWidget < ActiveRecord::Base
@@ -54,7 +53,7 @@ def available
5453
unless klass < Cms::Portlet
5554
Cms::ContentType.new(name: klass.name)
5655
end
57-
end.compact.sort { |a, b| a.name <=> b.name }
56+
end.compact.sort { |a, b| a.name.to_s <=> b.name.to_s }
5857
end
5958

6059
def list
@@ -75,12 +74,12 @@ def default()
7574

7675
# Returns only user generated Content Blocks
7776
def user_generated_connectables()
78-
available.select { |content_type| !content_type.name.starts_with?("Cms::") }
77+
available.select { |content_type| !content_type&.name&.starts_with?("Cms::") }
7978
end
8079

8180
# Return content types that can be accessed as pages.
8281
def addressable()
83-
available.select { |content_type| content_type.model_class.addressable? }
82+
available.select { |content_type| content_type.model_class.try(:addressable?) }
8483
end
8584
end
8685

@@ -127,7 +126,7 @@ def self.create!
127126
# configured to specify this.
128127
# @return [Symbol]
129128
def module_name
130-
model_class.content_module
129+
model_class&.content_module
131130
end
132131

133132
# Returns the partial used to render the form fields for a given block.
@@ -144,12 +143,12 @@ def display_name_plural
144143
end
145144

146145
def model_class
147-
name.constantize
146+
name.try(:constantize)
148147
end
149148

150149
# Determines if the content can be connected to other pages.
151150
def connectable?
152-
model_class.connectable?
151+
model_class.try(:connectable?)
153152
end
154153

155154
# Cms::HtmlBlock -> html_block

app/portlets/dynamic_portlet.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ def render
44
eval(@portlet.code) unless @portlet.code.blank?
55
end
66

7+
def attributes=(new_attributes, guard_protected_attributes = true)
8+
self.assign_attributes(new_attributes)
9+
end
10+
711
end

app/views/layouts/cms/_content_types.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<%= divider_tag %>
55
<% end %>
66
<% modules = Cms::ContentType.available_by_module
7-
modules.keys.sort.each_with_index do |module_name, i| %>
7+
modules.keys.compact.sort.each_with_index do |module_name, i| %>
88
<%= divider_tag(i) %>
99
<% modules[module_name].each do |type| %>
1010
<%= nav_link_to h(type.display_name), engine_aware_path(type) %>

app/views/layouts/cms/_main_menu.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<ul class="dropdown-menu pull-right">
6565
<%= render 'cms/toolbar/new_pages_menu' %>
6666
<% modules = Cms::ContentType.available_by_module
67-
modules.keys.sort.each_with_index do |module_name, i| %>
67+
modules.keys.compact.sort.each_with_index do |module_name, i| %>
6868
<%= divider_tag(i) %>
6969
<% modules[module_name].each do |type| %>
7070
<%= nav_link_to h(type.display_name), new_engine_aware_path(type), id: "create_new_#{type.param_key}" %>

lib/cms/content_rendering_support.rb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def handle_server_error_on_page(exception)
4444
end
4545

4646
private
47-
4847
# This is the method all error handlers delegate to
4948
def handle_error_with_cms_page(error_page_path, exception, status, options={})
5049

@@ -61,16 +60,18 @@ def handle_error_with_cms_page(error_page_path, exception, status, options={})
6160
logger.debug "Rendering Error Page: #{@page.inspect}"
6261
@mode = "view"
6362
@show_page_toolbar = false
63+
if @template.present?
64+
# copy new instance variables to the template
65+
%w[page mode show_page_toolbar].each do |v|
66+
@template.instance_variable_set("@#{v}", instance_variable_get("@#{v}"))
67+
end
68+
6469

65-
# copy new instance variables to the template
66-
%w[page mode show_page_toolbar].each do |v|
67-
@template.instance_variable_set("@#{v}", instance_variable_get("@#{v}"))
68-
end
69-
70-
# clear out any content already captured
71-
# by previous attempts to render the page within this request
72-
@template.instance_variables.select { |v| v =~ /@content_for_/ }.each do |v|
73-
@template.instance_variable_set("#{v}", nil)
70+
# clear out any content already captured
71+
# by previous attempts to render the page within this request
72+
@template.instance_variables.select { |v| v =~ /@content_for_/ }.each do |v|
73+
@template.instance_variable_set("#{v}", nil)
74+
end
7475
end
7576

7677
prepare_connectables_for_render

spec/cms/content_type_spec.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ class AAAFirstBlock < ActiveRecord::Base
3636
JustHasContentType.content_type.module_name.must_equal :widgets
3737
end
3838
end
39-
4039
describe '.available_by_module' do
4140
it "should return a list of modules in alphabetical order" do
4241
modules = Cms::ContentType.available_by_module
43-
modules.keys.sort.first.must_equal :categorization
42+
modules.keys.compact.sort.first.must_equal :categorization
4443
modules[:core].map { |t| t.name }.must_include 'Cms::HtmlBlock'
4544
end
4645

@@ -142,10 +141,9 @@ class AAAFirstBlock < ActiveRecord::Base
142141
types = Cms::ContentType.available
143142
types.first.class.must_equal Cms::ContentType
144143
end
145-
146144
it "should be ordered alphabetically" do
147-
content_type_names.first.must_equal "AAAFirstBlock"
148-
content_type_names.last.must_equal "Widget"
145+
content_type_names.compact.first.must_equal "AAAFirstBlock"
146+
content_type_names.compact.last.must_equal "Widget"
149147
end
150148

151149

test/unit/models/namespaces_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66

77
class NamespacesTest < ActiveSupport::TestCase
88

9-
9+
1010
# Fetches all of the subclasses from a given module by grabbing the defined constants
1111
# and seeing if they are a Class or something else. Does not check to see if it is an
1212
# AR class or if it has a blueprint.
1313
def self.subclasses_from_module(module_name)
1414
subclasses = []
1515
mod = module_name.constantize
1616
if mod.class == Module
17-
mod.constants.each do |module_const_name|
17+
mod.constants.map do |module_const_name|
1818
begin
1919
klass_name = "#{module_name}::#{module_const_name}"
2020
klass = klass_name.constantize
2121
if klass.class == Class
2222
subclasses << klass
23-
subclasses += klass.send(:descendants).collect{|x| x.respond_to?(:constantize) ? x.constantize : x}
23+
subclasses += klass.send(:descendants).collect{|x| !x.singleton_class? && x.respond_to?(:constantize) ? x.constantize : x}
2424
else
2525
subclasses += subclasses_from_module(klass_name)
2626
end

test/unit/models/portlet_test.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ def setup
8181
@portlet.update_attributes(:b => "whatever")
8282
assert_equal "whatever", @portlet.b
8383
end
84-
8584
test "attributes=" do
8685
@portlet.attributes=({:b => "b"})
8786
assert_equal "b", @portlet.b

0 commit comments

Comments
 (0)