Skip to content

Commit

Permalink
Updates bcms to ruby 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
jtwohiou committed Mar 26, 2017
1 parent 7314a8b commit a606b13
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Gemfile
@@ -1,6 +1,6 @@
source 'http://rubygems.org'

ruby '2.0.0'
ruby '2.3.0'

# Load this project as a gem.
gemspec
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Expand Up @@ -342,7 +342,7 @@ DEPENDENCIES
yard

RUBY VERSION
ruby 2.0.0p645
ruby 2.3.0p0

BUNDLED WITH
1.14.6
15 changes: 7 additions & 8 deletions app/models/cms/content_type.rb
Expand Up @@ -32,9 +32,8 @@ def available_by_module
modules[content_type.module_name] = [] unless modules[content_type.module_name]
modules[content_type.module_name] << content_type
end
modules
modules.compact
end

# Returns a list of all ContentTypes in the system. Content Types can opt out of this list by specifying:
#
# class MyWidget < ActiveRecord::Base
Expand All @@ -54,7 +53,7 @@ def available
unless klass < Cms::Portlet
Cms::ContentType.new(name: klass.name)
end
end.compact.sort { |a, b| a.name <=> b.name }
end.compact.sort { |a, b| a.name.to_s <=> b.name.to_s }
end

def list
Expand All @@ -75,12 +74,12 @@ def default()

# Returns only user generated Content Blocks
def user_generated_connectables()
available.select { |content_type| !content_type.name.starts_with?("Cms::") }
available.select { |content_type| !content_type&.name&.starts_with?("Cms::") }
end

# Return content types that can be accessed as pages.
def addressable()
available.select { |content_type| content_type.model_class.addressable? }
available.select { |content_type| content_type.model_class.try(:addressable?) }
end
end

Expand Down Expand Up @@ -127,7 +126,7 @@ def self.create!
# configured to specify this.
# @return [Symbol]
def module_name
model_class.content_module
model_class&.content_module
end

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

def model_class
name.constantize
name.try(:constantize)
end

# Determines if the content can be connected to other pages.
def connectable?
model_class.connectable?
model_class.try(:connectable?)
end

# Cms::HtmlBlock -> html_block
Expand Down
4 changes: 4 additions & 0 deletions app/portlets/dynamic_portlet.rb
Expand Up @@ -4,4 +4,8 @@ def render
eval(@portlet.code) unless @portlet.code.blank?
end

def attributes=(new_attributes, guard_protected_attributes = true)
self.assign_attributes(new_attributes)
end

end
2 changes: 1 addition & 1 deletion app/views/layouts/cms/_content_types.html.erb
Expand Up @@ -4,7 +4,7 @@
<%= divider_tag %>
<% end %>
<% modules = Cms::ContentType.available_by_module
modules.keys.sort.each_with_index do |module_name, i| %>
modules.keys.compact.sort.each_with_index do |module_name, i| %>
<%= divider_tag(i) %>
<% modules[module_name].each do |type| %>
<%= nav_link_to h(type.display_name), engine_aware_path(type) %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/cms/_main_menu.html.erb
Expand Up @@ -64,7 +64,7 @@
<ul class="dropdown-menu pull-right">
<%= render 'cms/toolbar/new_pages_menu' %>
<% modules = Cms::ContentType.available_by_module
modules.keys.sort.each_with_index do |module_name, i| %>
modules.keys.compact.sort.each_with_index do |module_name, i| %>
<%= divider_tag(i) %>
<% modules[module_name].each do |type| %>
<%= nav_link_to h(type.display_name), new_engine_aware_path(type), id: "create_new_#{type.param_key}" %>
Expand Down
21 changes: 11 additions & 10 deletions lib/cms/content_rendering_support.rb
Expand Up @@ -44,7 +44,6 @@ def handle_server_error_on_page(exception)
end

private

# This is the method all error handlers delegate to
def handle_error_with_cms_page(error_page_path, exception, status, options={})

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


# copy new instance variables to the template
%w[page mode show_page_toolbar].each do |v|
@template.instance_variable_set("@#{v}", instance_variable_get("@#{v}"))
end

# clear out any content already captured
# by previous attempts to render the page within this request
@template.instance_variables.select { |v| v =~ /@content_for_/ }.each do |v|
@template.instance_variable_set("#{v}", nil)
# clear out any content already captured
# by previous attempts to render the page within this request
@template.instance_variables.select { |v| v =~ /@content_for_/ }.each do |v|
@template.instance_variable_set("#{v}", nil)
end
end

prepare_connectables_for_render
Expand Down
8 changes: 3 additions & 5 deletions spec/cms/content_type_spec.rb
Expand Up @@ -36,11 +36,10 @@ class AAAFirstBlock < ActiveRecord::Base
JustHasContentType.content_type.module_name.must_equal :widgets
end
end

describe '.available_by_module' do
it "should return a list of modules in alphabetical order" do
modules = Cms::ContentType.available_by_module
modules.keys.sort.first.must_equal :categorization
modules.keys.compact.sort.first.must_equal :categorization
modules[:core].map { |t| t.name }.must_include 'Cms::HtmlBlock'
end

Expand Down Expand Up @@ -142,10 +141,9 @@ class AAAFirstBlock < ActiveRecord::Base
types = Cms::ContentType.available
types.first.class.must_equal Cms::ContentType
end

it "should be ordered alphabetically" do
content_type_names.first.must_equal "AAAFirstBlock"
content_type_names.last.must_equal "Widget"
content_type_names.compact.first.must_equal "AAAFirstBlock"
content_type_names.compact.last.must_equal "Widget"
end


Expand Down
6 changes: 3 additions & 3 deletions test/unit/models/namespaces_test.rb
Expand Up @@ -6,21 +6,21 @@

class NamespacesTest < ActiveSupport::TestCase


# Fetches all of the subclasses from a given module by grabbing the defined constants
# and seeing if they are a Class or something else. Does not check to see if it is an
# AR class or if it has a blueprint.
def self.subclasses_from_module(module_name)
subclasses = []
mod = module_name.constantize
if mod.class == Module
mod.constants.each do |module_const_name|
mod.constants.map do |module_const_name|
begin
klass_name = "#{module_name}::#{module_const_name}"
klass = klass_name.constantize
if klass.class == Class
subclasses << klass
subclasses += klass.send(:descendants).collect{|x| x.respond_to?(:constantize) ? x.constantize : x}
subclasses += klass.send(:descendants).collect{|x| !x.singleton_class? && x.respond_to?(:constantize) ? x.constantize : x}
else
subclasses += subclasses_from_module(klass_name)
end
Expand Down
1 change: 0 additions & 1 deletion test/unit/models/portlet_test.rb
Expand Up @@ -81,7 +81,6 @@ def setup
@portlet.update_attributes(:b => "whatever")
assert_equal "whatever", @portlet.b
end

test "attributes=" do
@portlet.attributes=({:b => "b"})
assert_equal "b", @portlet.b
Expand Down

0 comments on commit a606b13

Please sign in to comment.