diff --git a/dryml/dryml.gemspec b/dryml/dryml.gemspec index 0e6aadf75..a406e6bfe 100644 --- a/dryml/dryml.gemspec +++ b/dryml/dryml.gemspec @@ -11,7 +11,7 @@ Gem::Specification.new do |s| s.summary = "The Don't Repeat Yourself Markup Language" s.description = "The Don't Repeat Yourself Markup Language" - s.add_runtime_dependency('actionpack') + s.add_runtime_dependency('actionpack', '~> 5') s.add_runtime_dependency('hobo_support', ["= #{version}"]) # s.add_development_dependency('rubydoctest', [">= 1.1.3"]) s.add_development_dependency('cucumber', '~> 1.1.0') diff --git a/dryml/lib/dryml/extensions/action_controller/dryml_methods.rb b/dryml/lib/dryml/extensions/action_controller/dryml_methods.rb index d10ff008f..e5c5bc91d 100644 --- a/dryml/lib/dryml/extensions/action_controller/dryml_methods.rb +++ b/dryml/lib/dryml/extensions/action_controller/dryml_methods.rb @@ -1,6 +1,6 @@ ActionController::Base.class_eval do - before_filter do + before_action do append_view_path Dryml::Railtie::PageTagResolver.new(self) end diff --git a/hobo/app/helpers/hobo_helper_base.rb b/hobo/app/helpers/hobo_helper_base.rb index 2f2c0c376..31493fbb9 100644 --- a/hobo/app/helpers/hobo_helper_base.rb +++ b/hobo/app/helpers/hobo_helper_base.rb @@ -2,7 +2,6 @@ module HoboHelperBase def add_to_controller(controller) controller.send(:include, self) - controller.hide_action(self.instance_methods) end end diff --git a/hobo/lib/generators/hobo/admin_subsite/templates/controller.rb.erb b/hobo/lib/generators/hobo/admin_subsite/templates/controller.rb.erb index e8ced495f..1694a467a 100644 --- a/hobo/lib/generators/hobo/admin_subsite/templates/controller.rb.erb +++ b/hobo/lib/generators/hobo/admin_subsite/templates/controller.rb.erb @@ -2,7 +2,7 @@ class <%= subsite_name %>::<%= subsite_name %>SiteController < ApplicationContro hobo_controller - before_filter :admin_required + before_action :admin_required private diff --git a/hobo/lib/generators/hobo/routes/routes_generator.rb b/hobo/lib/generators/hobo/routes/routes_generator.rb index ebe023ec4..b24789dbe 100644 --- a/hobo/lib/generators/hobo/routes/routes_generator.rb +++ b/hobo/lib/generators/hobo/routes/routes_generator.rb @@ -6,6 +6,7 @@ class RoutesGenerator < Rails::Generators::Base include Generators::HoboSupport::EvalTemplate + def self.banner "rails generate hobo:routes #{self.arguments.map(&:usage).join(' ')} [options]" end diff --git a/hobo/lib/generators/hobo/routes/templates/hobo_routes.rb.erb b/hobo/lib/generators/hobo/routes/templates/hobo_routes.rb.erb index 43c157c6a..03dfa9728 100644 --- a/hobo/lib/generators/hobo/routes/templates/hobo_routes.rb.erb +++ b/hobo/lib/generators/hobo/routes/templates/hobo_routes.rb.erb @@ -3,6 +3,17 @@ # which will override the routes in this file. <%= Rails.application.class.name %>.routes.draw do + begin + <%= + begin + ::GearsModel.emit_custom_routes + rescue => e + '' + end + %> + rescue ScriptError, StandardError => e + DT.p "Error in custom routes output, review hobo_routes.rb", e.message + end <% for subsite in subsites -%> <%- if subsite -%> diff --git a/hobo/lib/hobo/controller.rb b/hobo/lib/hobo/controller.rb index c2cf6c460..57185fcc2 100644 --- a/hobo/lib/hobo/controller.rb +++ b/hobo/lib/hobo/controller.rb @@ -16,7 +16,7 @@ def included(base) def included_in_class(klass) klass.extend(ClassMethods) klass.class_eval do - before_filter :login_from_cookie + before_action :login_from_cookie alias_method_chain :redirect_to, :object_url private def set_mailer_default_url_options @@ -25,7 +25,7 @@ def set_mailer_default_url_options Rails.application.config.action_mailer.default_url_options[:port] = request.port unless request.port == 80 end end - before_filter :set_mailer_default_url_options + before_action :set_mailer_default_url_options @included_taglibs = [] rescue_from ActionController::RoutingError, :with => :not_found unless Rails.env.development? end diff --git a/hobo/lib/hobo/controller/model.rb b/hobo/lib/hobo/controller/model.rb index bc9efda4c..e94da0948 100644 --- a/hobo/lib/hobo/controller/model.rb +++ b/hobo/lib/hobo/controller/model.rb @@ -4,7 +4,7 @@ module Model include Hobo::Controller - DONT_PAGINATE_FORMATS = [ Mime::CSV, Mime::YAML, Mime::JSON, Mime::XML, Mime::ATOM, Mime::RSS ] + DONT_PAGINATE_FORMATS = [ Mime[:csv], Mime[:yaml], Mime[:json], Mime[:xml], Mime[:atom], Mime[:rss] ] WILL_PAGINATE_OPTIONS = [ :page, :per_page, :total_entries, :count, :finder ] @@ -25,7 +25,7 @@ def included(base) helper_method :model, :current_user - before_filter :set_no_cache_headers + before_action :set_no_cache_headers rescue_from ActiveRecord::RecordNotFound, :with => :not_found unless Rails.env.development? diff --git a/hobo/lib/hobo/controller/user_base.rb b/hobo/lib/hobo/controller/user_base.rb index a55e014fb..713f9bbef 100644 --- a/hobo/lib/hobo/controller/user_base.rb +++ b/hobo/lib/hobo/controller/user_base.rb @@ -12,7 +12,7 @@ class << self alias_method_chain :def_auto_actions, :user_actions end - skip_before_filter :login_required, :only => [:login, :signup, :do_signup, :forgot_password, :reset_password, :do_reset_password, + skip_before_action :login_required, :only => [:login, :signup, :do_signup, :forgot_password, :reset_password, :do_reset_password, :accept_invitation, :do_accept_invitation] alias_method_chain :hobo_update, :account_flash diff --git a/hobo/lib/hobo/model.rb b/hobo/lib/hobo/model.rb index 0a2e71a60..754c77415 100644 --- a/hobo/lib/hobo/model.rb +++ b/hobo/lib/hobo/model.rb @@ -156,7 +156,9 @@ def belongs_to_with_test_methods(name, *args, &block) end belongs_to_without_test_methods(name, *args, &block) refl = reflections[name.to_s] - id_method = refl.options[:primary_key] || refl.klass.primary_key + id_method = refl.options[:primary_key] + id_method = refl.klass.primary_key if id_method.blank? + id_method = :id if id_method.blank? if options[:polymorphic] # TODO: the class lookup in _is? below is incomplete; a polymorphic association to an STI base class # will fail to match an object of a derived type @@ -185,7 +187,6 @@ def #{name}_changed? end end - def attr_accessor_with_creator_metadata(*args) options = args.extract_options! if options.delete(:creator) @@ -199,24 +200,20 @@ def attr_accessor_with_creator_metadata(*args) attr_accessor_without_creator_metadata(*args) end - def has_one_with_new_method(name, options={}, &block) has_one_without_new_method(name, options, &block) class_eval "def new_#{name}(attributes={}); build_#{name}(attributes, false); end" end - def set_default_order(order) @default_order = order end - def never_show(*fields) @hobo_never_show ||= [] @hobo_never_show.concat(fields.*.to_sym) end - def set_search_columns(*columns) class_eval %{ def self.search_columns @@ -225,39 +222,32 @@ def self.search_columns } end - public - def never_show?(field) (@hobo_never_show && field.to_sym.in?(@hobo_never_show)) || (superclass < Hobo::Model && superclass.never_show?(field)) end - def find(*args) result = super result.member_class = self if result.is_a?(Array) result end - def find_by_sql(*args) result = super result end - def creator_type attr_type(creator_attribute) end - def search_columns column_names = columns.*.name SEARCH_COLUMNS_GUESS.select{|c| c.in?(column_names) } end - def reverse_reflection(association_name) refl = reflections[association_name.to_s] or raise "No reverse reflection for #{name}.#{association_name}" return nil if refl.options[:conditions] || refl.options[:polymorphic] @@ -377,7 +367,6 @@ def set_creator(user) set_creator!(user) unless get_creator end - def set_creator!(user) attr = self.class.creator_attribute return unless attr @@ -397,17 +386,14 @@ def set_creator!(user) end end - def get_creator self.class.creator_attribute && send(self.class.creator_attribute) end - def typed_id "#{self.class.name.underscore}:#{self.id}" if id end - def to_s if self.class.name_attribute send self.class.name_attribute diff --git a/hobo/lib/hobo/model/accessible_associations.rb b/hobo/lib/hobo/model/accessible_associations.rb index f2c02189e..1d70e3dc4 100644 --- a/hobo/lib/hobo/model/accessible_associations.rb +++ b/hobo/lib/hobo/model/accessible_associations.rb @@ -185,7 +185,7 @@ def #{name}_with_finder=(record_or_string) # Add :accessible to the valid options so AR doesn't complain - ::ActiveRecord::Associations::Builder::Association.valid_options << :accessible + ::ActiveRecord::Associations::Builder::Association::VALID_OPTIONS << :accessible end end diff --git a/hobo/lib/hobo/model/scopes.rb b/hobo/lib/hobo/model/scopes.rb index e55a76a88..14b13b6c7 100644 --- a/hobo/lib/hobo/model/scopes.rb +++ b/hobo/lib/hobo/model/scopes.rb @@ -2,7 +2,7 @@ module Hobo module Model module Scopes - ::ActiveRecord::Associations::Builder::Association.valid_options << :scope + ::ActiveRecord::Associations::Builder::Association::VALID_OPTIONS << :scope def self.included_in_class(klass) klass.class_eval do diff --git a/hobo/lib/hobo/model/scopes/automatic_scopes.rb b/hobo/lib/hobo/model/scopes/automatic_scopes.rb index f69118c31..84b100cf3 100644 --- a/hobo/lib/hobo/model/scopes/automatic_scopes.rb +++ b/hobo/lib/hobo/model/scopes/automatic_scopes.rb @@ -5,6 +5,7 @@ module Scopes module AutomaticScopes def create_automatic_scope(name, check_only=false) + # check_only = true ScopeBuilder.new(self, name).create_scope(check_only) rescue ActiveRecord::StatementInvalid => e # Problem with the database? Don't try to create automatic @@ -32,6 +33,8 @@ def create_scope(check_only=false) matched_scope = true like_operator = ActiveRecord::Base.connection.adapter_name =~ /postg/i ? 'ILIKE' : 'LIKE' + klass = @klass + case # --- Association Queries --- # @@ -42,11 +45,11 @@ def create_scope(check_only=false) def_scope do |*records| if records.empty? - @klass.where exists_sql_condition(refl, true) + klass.where exists_sql_condition(refl, true) else records = records.flatten.compact.map {|r| find_if_named(refl, r) } exists_sql = ([exists_sql_condition(refl)] * records.length).join(" AND ") - @klass.where *([exists_sql] + records) + klass.where *([exists_sql] + records) end end @@ -57,7 +60,7 @@ def create_scope(check_only=false) exists_sql = exists_sql_condition(refl) def_scope do |record| record = find_if_named(refl, record) - @klass.where exists_sql, record + klass.where exists_sql, record end # any_of_players(player1, player2) @@ -66,11 +69,11 @@ def create_scope(check_only=false) def_scope do |*records| if records.empty? - @klass.where exists_sql_condition(refl, true) + klass.where exists_sql_condition(refl, true) else records = records.flatten.compact.map {|r| find_if_named(refl, r) } exists_sql = ([exists_sql_condition(refl)] * records.length).join(" OR ") - @klass.where *([exists_sql] + records) + klass.where *([exists_sql] + records) end end @@ -80,11 +83,11 @@ def create_scope(check_only=false) def_scope do |*records| if records.empty? - @klass.where "NOT (#{exists_sql_condition(refl, true)})" + klass.where "NOT (#{exists_sql_condition(refl, true)})" else records = records.flatten.compact.map {|r| find_if_named(refl, r) } exists_sql = ([exists_sql_condition(refl)] * records.length).join(" AND ") - @klass.where *(["NOT (#{exists_sql})"] + records) + klass.where *(["NOT (#{exists_sql})"] + records) end end @@ -95,7 +98,7 @@ def create_scope(check_only=false) exists_sql = exists_sql_condition(refl) def_scope do |record| record = find_if_named(refl, record) - @klass.where "NOT #{exists_sql}", record + klass.where "NOT #{exists_sql}", record end # team_is(a_team) @@ -105,12 +108,12 @@ def create_scope(check_only=false) if refl.options[:polymorphic] def_scope do |record| record = find_if_named(refl, record) - @klass.where "#{foreign_key_column refl} = ? AND #{$1}_type = ?", record, record.class.name + klass.where "#{foreign_key_column refl} = ? AND #{$1}_type = ?", record, record.class.name end else def_scope do |record| record = find_if_named(refl, record) - @klass.where "#{foreign_key_column refl} = ?", record + klass.where "#{foreign_key_column refl} = ?", record end end @@ -121,12 +124,12 @@ def create_scope(check_only=false) if refl.options[:polymorphic] def_scope do |record| record = find_if_named(refl, record) - @klass.where "#{foreign_key_column refl} <> ? OR #{name}_type <> ?", record, record.class.name + klass.where "#{foreign_key_column refl} <> ? OR #{name}_type <> ?", record, record.class.name end else def_scope do |record| record = find_if_named(refl, record) - @klass.where "#{foreign_key_column refl} <> ?", record + klass.where "#{foreign_key_column refl} <> ?", record end end @@ -137,117 +140,129 @@ def create_scope(check_only=false) when name =~ /^(.*)_is$/ && (col = column($1)) return true if check_only + scope_where = "#{column_sql(col)} = ?" def_scope do |str| - @klass.where "#{column_sql(col)} = ?", str + klass.where scope_where, str end # name_is_not(str) when name =~ /^(.*)_is_not$/ && (col = column($1)) return true if check_only + scope_where = "#{column_sql(col)} <> ?" def_scope do |str| - @klass.where "#{column_sql(col)} <> ?", str + klass.where scope_where, str end # name_contains(str) when name =~ /^(.*)_contains$/ && (col = column($1)) return true if check_only + scope_where = "#{column_sql(col)} #{like_operator} ?" def_scope do |str| - @klass.where "#{column_sql(col)} #{like_operator} ?", "%#{str}%" + klass.where scope_where, "%#{str}%" end # name_does_not_contain when name =~ /^(.*)_does_not_contain$/ && (col = column($1)) return true if check_only + scope_where = "#{column_sql(col)} NOT #{like_operator} ?" def_scope do |str| - @klass.where "#{column_sql(col)} NOT #{like_operator} ?", "%#{str}%" + klass.where scope_where, "%#{str}%" end # name_starts(str) when name =~ /^(.*)_starts$/ && (col = column($1)) return true if check_only + scope_where = "#{column_sql(col)} #{like_operator} ?" def_scope do |str| - @klass.where "#{column_sql(col)} #{like_operator} ?", "#{str}%" + klass.where scope_where, "#{str}%" end # name_does_not_start when name =~ /^(.*)_does_not_start$/ && (col = column($1)) return true if check_only + scope_where = "#{column_sql(col)} NOT #{like_operator} ?" def_scope do |str| - @klass.where "#{column_sql(col)} NOT #{like_operator} ?", "#{str}%" + klass.where scope_where, "#{str}%" end # name_ends(str) when name =~ /^(.*)_ends$/ && (col = column($1)) return true if check_only + scope_where = "#{column_sql(col)} #{like_operator} ?" def_scope do |str| - @klass.where "#{column_sql(col)} #{like_operator} ?", "%#{str}" + klass.where scope_where, "%#{str}" end # name_does_not_end(str) when name =~ /^(.*)_does_not_end$/ && (col = column($1)) return true if check_only + scope_where = "#{column_sql(col)} NOT #{like_operator} ?" def_scope do |str| - @klass.where "#{column_sql(col)} NOT #{like_operator} ?", "%#{str}" + klass.where scope_where, "%#{str}" end # published (a boolean column) when (col = column(name)) && (col.type == :boolean) return true if check_only + scope_where = "#{column_sql(col)} = ?" def_scope do - @klass.where "#{column_sql(col)} = ?", true + klass.where scope_where, true end # not_published when name =~ /^not_(.*)$/ && (col = column($1)) && (col.type == :boolean) return true if check_only - + scope_where = "#{column_sql(col)} <> ?" def_scope do - @klass.where "#{column_sql(col)} <> ?", true + klass.where scope_where, true end # published_before(time) when name =~ /^(.*)_before$/ && (col = column("#{$1}_at") || column("#{$1}_date") || column("#{$1}_on")) && col.type.in?([:date, :datetime, :time, :timestamp]) return true if check_only + scope_where = "#{column_sql(col)} < ?" def_scope do |time| - @klass.where "#{column_sql(col)} < ?", time + klass.where scope_where, time end # published_after(time) when name =~ /^(.*)_after$/ && (col = column("#{$1}_at") || column("#{$1}_date") || column("#{$1}_on")) && col.type.in?([:date, :datetime, :time, :timestamp]) return true if check_only + scope_where = "#{column_sql(col)} > ?" def_scope do |time| - @klass.where "#{column_sql(col)} > ?", time + klass.where scope_where, time end # published_between(time1, time2) when name =~ /^(.*)_between$/ && (col = column("#{$1}_at") || column("#{$1}_date") || column("#{$1}_on")) && col.type.in?([:date, :datetime, :time, :timestamp]) return true if check_only + scope_where = "#{column_sql(col)} >= ? AND #{column_sql(col)} <= ?" def_scope do |time1, time2| - @klass.where "#{column_sql(col)} >= ? AND #{column_sql(col)} <= ?", time1, time2 + klass.where scope_where, time1, time2 end # active (a lifecycle state) - when @klass.has_lifecycle? && name.to_sym.in?(@klass::Lifecycle.state_names) + when klass.has_lifecycle? && name.to_sym.in?(klass::Lifecycle.state_names) return true if check_only - if @klass::Lifecycle.state_names.length == 1 + if klass::Lifecycle.state_names.length == 1 # nothing to check for - create a dummy scope - def_scope { @klass.scoped } + def_scope { klass.scoped } true else def_scope do - @klass.where "#{@klass.table_name}.#{@klass::Lifecycle.state_field} = ?", name + klass.where "#{klass.table_name}.#{klass::Lifecycle.state_field} = ?", name end end @@ -256,14 +271,14 @@ def create_scope(check_only=false) return true if check_only def_scope do |record| - @klass.where "#{@klass.table_name}.#{@klass.primary_key} = ?", record + klass.where "#{klass.table_name}.#{klass.primary_key} = ?", record end when name == "is_not" return true if check_only def_scope do |record| - @klass.where "#{@klass.table_name}.#{@klass.primary_key} <> ?", record + klass.where "#{klass.table_name}.#{klass.primary_key} <> ?", record end @@ -271,16 +286,16 @@ def create_scope(check_only=false) return true if check_only def_scope do - @klass.order "#{@klass.table_name}.created_at DESC" + klass.order "#{klass.table_name}.created_at DESC" end when name == "recent" return true if check_only - if "created_at".in?(@klass.columns.*.name) + if "created_at".in?(klass.columns.*.name) def_scope do |*args| count = args.first || 6 - @klass.order("#{@klass.table_name}.created_at DESC").limit(count) + klass.order("#{klass.table_name}.created_at DESC").limit(count) end else def_scope do |*args| @@ -292,7 +307,6 @@ def create_scope(check_only=false) when name == "order_by" return true if check_only - klass = @klass def_scope do |*args| field, asc = args field ||= "" @@ -305,7 +319,7 @@ def create_scope(check_only=false) else colspec = "#{klass.table_name}.#{field}" end - @klass.includes(include).order("#{colspec} #{asc._?.upcase}") + klass.includes(include).order("#{colspec} #{asc._?.upcase}") end when name == "include" @@ -315,7 +329,7 @@ def create_scope(check_only=false) return true if check_only def_scope do |inclusions| - @klass.includes(inclusions) + klass.includes(inclusions) end when name == "search" @@ -329,9 +343,9 @@ def create_scope(check_only=false) word_queries = words.map do |word| field_query = '(' + fields.map { |field| if using_postgresql - casted_field = "CAST(#{@klass.table_name}.#{field} AS TEXT)" + casted_field = "CAST(#{klass.table_name}.#{field} AS TEXT)" else - casted_field = "#{@klass.table_name}.#{field}" + casted_field = "#{klass.table_name}.#{field}" end field = "#{casted_field}" unless field =~ /\./ "(#{field} #{match_keyword} ?)" @@ -340,7 +354,7 @@ def create_scope(check_only=false) field_query end - @klass.where *([word_queries.join(" AND ")] + args) + klass.where *([word_queries.join(" AND ")] + args) end else diff --git a/hobo_fields/lib/hobo_fields/model.rb b/hobo_fields/lib/hobo_fields/model.rb index 7b77cfeca..f97f0c385 100644 --- a/hobo_fields/lib/hobo_fields/model.rb +++ b/hobo_fields/lib/hobo_fields/model.rb @@ -219,7 +219,7 @@ def self.attr_type(name) end end or - (col = column(name.to_s) and HoboFields::PLAIN_TYPES[col.type] || col.klass) + (col = column(name.to_s) and HoboFields::PLAIN_TYPES[col.type] || String) end diff --git a/hobo_rapid/app/controllers/dev_controller.rb b/hobo_rapid/app/controllers/dev_controller.rb index e6a59b97c..7a79de1fd 100644 --- a/hobo_rapid/app/controllers/dev_controller.rb +++ b/hobo_rapid/app/controllers/dev_controller.rb @@ -2,7 +2,7 @@ class DevController < ActionController::Base hobo_controller - before_filter :developer_modes_only + before_action :developer_modes_only def set_current_user model = params[:model] || Hobo::Model::UserBase.default_user_model diff --git a/hobo_support/hobo_support.gemspec b/hobo_support/hobo_support.gemspec index 65b20b572..880119c18 100644 --- a/hobo_support/hobo_support.gemspec +++ b/hobo_support/hobo_support.gemspec @@ -11,7 +11,7 @@ Gem::Specification.new do |s| s.summary = 'Core Ruby extensions from the Hobo project' s.description = 'Core Ruby extensions from the Hobo project' - s.add_runtime_dependency('rails', [">= 4.2.7.1", '< 5.0']) + s.add_runtime_dependency('rails', ["~> 5"]) # s.add_development_dependency('rubydoctest', [">= 0"]) s.files = `git ls-files -x #{name}/* -z`.split("\0")