rails_core_extensions 0.6.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +2 -7
- data/CHANGELOG.md +22 -0
- data/gemfiles/rails5.gemfile +1 -1
- data/gemfiles/rails6.gemfile +1 -1
- data/lib/rails_core_extensions.rb +9 -13
- data/lib/rails_core_extensions/action_view_extensions.rb +0 -36
- data/lib/rails_core_extensions/active_record_extensions.rb +0 -67
- data/lib/rails_core_extensions/active_record_liquid_extensions.rb +1 -1
- data/lib/rails_core_extensions/sortable.rb +2 -2
- data/lib/rails_core_extensions/version.rb +1 -1
- data/rails_core_extensions.gemspec +0 -4
- data/spec/action_controller_sortable_spec.rb +1 -1
- data/spec/active_record_extensions_spec.rb +0 -54
- data/spec/support/coverage_loader.rb +2 -1
- metadata +3 -38
- data/lib/rails_core_extensions/action_view_currency_extensions.rb +0 -26
- data/lib/rails_core_extensions/active_record_cache_all_attributes.rb +0 -39
- data/lib/rails_core_extensions/breadcrumb.rb +0 -170
- data/lib/rails_core_extensions/caches_action_without_host.rb +0 -17
- data/spec/breadcrumb_spec.rb +0 -86
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 0e350102d147909780d1a0cda311d00efad4d810d9d0c4c65fcc2fb50407ac30
         | 
| 4 | 
            +
              data.tar.gz: 1480421b9f8759d15921eebf9686561e2a606c09f4506d0f48e29e0f4ad1ce71
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: cb72133b0667c523995e50acc4c086ff9d356570900507dd2d41b98bd3da57569024ebec1e5bd41dcc6c26e9848d3da2631842c1d64a70a5d94da490b1915730
         | 
| 7 | 
            +
              data.tar.gz: 9b44c7559c1a0d6594f7458672f0c7cb7aa63f55caa889ef7d2b80d79fceacacb41253d0c32dd026193bde537ede9d2446eefc83932e236ff64e479a0cccfbb1
         | 
    
        data/.ruby-version
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            2. | 
| 1 | 
            +
            2.7.1
         | 
    
        data/.travis.yml
    CHANGED
    
    | @@ -1,11 +1,7 @@ | |
| 1 1 | 
             
            language: ruby
         | 
| 2 2 | 
             
            rvm:
         | 
| 3 | 
            -
              - 2. | 
| 4 | 
            -
              - 2. | 
| 5 | 
            -
            matrix:
         | 
| 6 | 
            -
              exclude:
         | 
| 7 | 
            -
                - rvm: 2.4
         | 
| 8 | 
            -
                  gemfile: gemfiles/rails6.gemfile
         | 
| 3 | 
            +
              - 2.6
         | 
| 4 | 
            +
              - 2.7
         | 
| 9 5 |  | 
| 10 6 | 
             
            script: "bundle exec rake spec"
         | 
| 11 7 | 
             
            gemfile:
         | 
| @@ -13,7 +9,6 @@ gemfile: | |
| 13 9 | 
             
              - gemfiles/rails6.gemfile
         | 
| 14 10 | 
             
            sudo: false
         | 
| 15 11 | 
             
            cache: bundler
         | 
| 16 | 
            -
            # Due to this issue, stil not resolved: travis-ci/travis-ci#8969
         | 
| 17 12 | 
             
            before_install:
         | 
| 18 13 | 
             
              - gem update --system
         | 
| 19 14 | 
             
              - gem install bundler
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -1,5 +1,27 @@ | |
| 1 1 | 
             
            # Changelog
         | 
| 2 2 |  | 
| 3 | 
            +
            ## 0.9.0
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            * [TT-6727] Fix usage of symbolize_keys in sortable
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            ## 0.8.0
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            * [TT-6539] Remove cache_all_attributes and other unused methods
         | 
| 10 | 
            +
            * [TT-5384] Remove validates_presence_of_parent method (Use rails optional flag instead)
         | 
| 11 | 
            +
            * [TT-6293] Drop breadcrumbs / cache without host and some unused view helpers
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            ## 0.7.1
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            * [TT-5745] Fix passing of symbol to liquid template parse
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            ## 0.7.0
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            * [TT-5745] Update Liquid validate to be v4 compatible
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            ## 0.6.1
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            * [TT-5671] More fixes to sortable
         | 
| 24 | 
            +
             | 
| 3 25 | 
             
            ## 0.6.0
         | 
| 4 26 |  | 
| 5 27 | 
             
            * [TT-5542] Remove Rails 4 support
         | 
    
        data/gemfiles/rails5.gemfile
    CHANGED
    
    
    
        data/gemfiles/rails6.gemfile
    CHANGED
    
    
| @@ -1,9 +1,5 @@ | |
| 1 1 | 
             
            module RailsCoreExtensions
         | 
| 2 2 | 
             
              require 'rails_core_extensions/sortable'
         | 
| 3 | 
            -
              require 'rails_core_extensions/action_view_currency_extensions'
         | 
| 4 | 
            -
              require 'rails_core_extensions/action_view_has_many_extensions'
         | 
| 5 | 
            -
              require 'rails_core_extensions/action_view_extensions'
         | 
| 6 | 
            -
              require 'rails_core_extensions/breadcrumb'
         | 
| 7 3 | 
             
              require 'rails_core_extensions/position_initializer'
         | 
| 8 4 | 
             
              require 'rails_core_extensions/time_with_zone'
         | 
| 9 5 | 
             
              require 'rails_core_extensions/transfer_records'
         | 
| @@ -13,32 +9,32 @@ module RailsCoreExtensions | |
| 13 9 | 
             
              require 'rails_core_extensions/railtie' if defined?(Rails)
         | 
| 14 10 |  | 
| 15 11 | 
             
              if defined? ActionController
         | 
| 16 | 
            -
                require 'rails_core_extensions/caches_action_without_host'
         | 
| 17 12 | 
             
                require 'rails_core_extensions/activatable'
         | 
| 18 13 | 
             
                require 'rails_core_extensions/action_controller_sortable'
         | 
| 19 14 |  | 
| 20 | 
            -
                ActionController::Base.send(:include, CachesActionWithoutHost)
         | 
| 21 15 | 
             
                ActionController::Base.send(:include, Activatable)
         | 
| 22 16 | 
             
                ActionController::Base.send(:include, ActionControllerSortable)
         | 
| 23 17 | 
             
              end
         | 
| 24 18 |  | 
| 19 | 
            +
              if defined? ActionView
         | 
| 20 | 
            +
                require 'rails_core_extensions/action_view_extensions'
         | 
| 21 | 
            +
                require 'rails_core_extensions/action_view_has_many_extensions'
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                ActionView::Base.send(:include, RailsCoreExtensions::ActionViewExtensions)
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
             | 
| 25 26 | 
             
              if defined? ActiveRecord
         | 
| 26 27 | 
             
                require 'rails_core_extensions/active_record_cloning'
         | 
| 27 | 
            -
                require 'rails_core_extensions/active_record_cache_all_attributes'
         | 
| 28 28 | 
             
                require 'rails_core_extensions/active_record_extensions'
         | 
| 29 29 | 
             
                require 'rails_core_extensions/active_record_liquid_extensions'
         | 
| 30 30 | 
             
                require 'rails_core_extensions/translations'
         | 
| 31 | 
            +
                require 'rails_core_extensions/active_model_extensions'
         | 
| 31 32 |  | 
| 32 33 | 
             
                ActiveRecord::Base.send(:include, ActiveRecordCloning)
         | 
| 33 34 | 
             
                ActiveRecord::Base.send(:include, ActiveRecordExtensions)
         | 
| 34 35 | 
             
                ActiveRecord::Base.send(:include, RailsCoreExtensions::ActiveRecordLiquidExtensions)
         | 
| 35 36 | 
             
                ActiveRecord::Base.send(:include, ActiveRecordExtensions::InstanceMethods)
         | 
| 36 37 | 
             
                ActiveRecord::Base.send(:include, RailsCoreExtensions::Translations)
         | 
| 37 | 
            -
             | 
| 38 | 
            -
                if ActiveRecord::VERSION::MAJOR >= 3
         | 
| 39 | 
            -
                  require 'rails_core_extensions/active_model_extensions'
         | 
| 40 | 
            -
                  ActiveRecord::Base.send(:include, ActiveModelExtensions::Validations)
         | 
| 41 | 
            -
                end
         | 
| 38 | 
            +
                ActiveRecord::Base.send(:include, ActiveModelExtensions::Validations)
         | 
| 42 39 | 
             
              end
         | 
| 43 40 | 
             
            end
         | 
| 44 | 
            -
             | 
| @@ -4,25 +4,6 @@ module RailsCoreExtensions | |
| 4 4 | 
             
                  super(h(content)).html_safe
         | 
| 5 5 | 
             
                end
         | 
| 6 6 |  | 
| 7 | 
            -
                # Will recursively parse a Hash and any sub hashes to be normal hashes
         | 
| 8 | 
            -
                # This is useful when exporting hashes to non ruby systems, which don't understand HashWithIndifferentAccess
         | 
| 9 | 
            -
                def hashify(element)
         | 
| 10 | 
            -
                  if element.is_a? Hash
         | 
| 11 | 
            -
                    element = element.to_hash if element.is_a?(HashWithIndifferentAccess)
         | 
| 12 | 
            -
                    element.each_pair do |key, value|
         | 
| 13 | 
            -
                      element[key] = hashify(value)
         | 
| 14 | 
            -
                    end
         | 
| 15 | 
            -
                  else
         | 
| 16 | 
            -
                    # Must hashify enumerables encase their sub items are hashes
         | 
| 17 | 
            -
                    # Can't enumerate through string as it returns strings, which are also enumerable (stack level too deep)
         | 
| 18 | 
            -
                    if element.respond_to?(:each) && !element.is_a?(String)
         | 
| 19 | 
            -
                      element.map{ |sub| hashify(sub) }
         | 
| 20 | 
            -
                    else
         | 
| 21 | 
            -
                      element
         | 
| 22 | 
            -
                    end
         | 
| 23 | 
            -
                  end
         | 
| 24 | 
            -
                end
         | 
| 25 | 
            -
             | 
| 26 7 | 
             
                # Generates a tooltip with given text
         | 
| 27 8 | 
             
                # text is textilized before display
         | 
| 28 9 | 
             
                def tooltip(hover_element_id, text, title='')
         | 
| @@ -34,21 +15,6 @@ module RailsCoreExtensions | |
| 34 15 | 
             
                  "</script>"
         | 
| 35 16 | 
             
                end
         | 
| 36 17 |  | 
| 37 | 
            -
                def expandable_list_for(objects, show = 4)
         | 
| 38 | 
            -
                  first, others = objects[0..(show-1)], objects[show..(objects.size-1)]
         | 
| 39 | 
            -
                  first.each do |o|
         | 
| 40 | 
            -
                    yield o
         | 
| 41 | 
            -
                  end
         | 
| 42 | 
            -
                  if others
         | 
| 43 | 
            -
                    content_tag 'div', :id => 'others', :style => 'display: none' do
         | 
| 44 | 
            -
                      others.each do |o|
         | 
| 45 | 
            -
                        yield o
         | 
| 46 | 
            -
                      end
         | 
| 47 | 
            -
                    end
         | 
| 48 | 
            -
                    "#{others.size} Others - ".html_safe + link_to_function("Show/Hide", "$('others').toggle()")
         | 
| 49 | 
            -
                  end
         | 
| 50 | 
            -
                end
         | 
| 51 | 
            -
             | 
| 52 18 | 
             
                def boolean_select_tag(name, *args)
         | 
| 53 19 | 
             
                  options = args.extract_options!
         | 
| 54 20 | 
             
                  options ||= {}
         | 
| @@ -58,5 +24,3 @@ module RailsCoreExtensions | |
| 58 24 | 
             
                end
         | 
| 59 25 | 
             
              end
         | 
| 60 26 | 
             
            end
         | 
| 61 | 
            -
             | 
| 62 | 
            -
            ActionView::Base.send(:include, RailsCoreExtensions::ActionViewExtensions) if defined?(ActionView::Base)
         | 
| @@ -11,37 +11,6 @@ module ActiveRecordExtensions | |
| 11 11 | 
             
                  establish_connection("#{key}_#{Rails.env}")
         | 
| 12 12 | 
             
                end
         | 
| 13 13 |  | 
| 14 | 
            -
                def cache_all_attributes(options = {})
         | 
| 15 | 
            -
                  method = options[:by] || 'id'
         | 
| 16 | 
            -
                  class_eval <<-CACHE
         | 
| 17 | 
            -
                    after_save :clear_attribute_cache
         | 
| 18 | 
            -
                    after_destroy :clear_attribute_cache
         | 
| 19 | 
            -
                    cattr_accessor :cache_attributes_by
         | 
| 20 | 
            -
                    self.cache_attributes_by = '#{method}'
         | 
| 21 | 
            -
                  CACHE
         | 
| 22 | 
            -
                  extend ActiveRecordCacheAllAttributes::ClassMethods
         | 
| 23 | 
            -
                  include ActiveRecordCacheAllAttributes::InstanceMethods
         | 
| 24 | 
            -
                end
         | 
| 25 | 
            -
             | 
| 26 | 
            -
                # Create a new object from the attributes passed in
         | 
| 27 | 
            -
                # OR update an existing
         | 
| 28 | 
            -
                #
         | 
| 29 | 
            -
                # If an :id attribute is present it will assume it's an existing record, and needs update
         | 
| 30 | 
            -
                def new_or_update!(hash={}, options = {:hard_update => true})
         | 
| 31 | 
            -
                  hash.symbolize_keys!
         | 
| 32 | 
            -
                  if hash[:id].blank?
         | 
| 33 | 
            -
                    self.new(hash)
         | 
| 34 | 
            -
                  else
         | 
| 35 | 
            -
                    rec = self.find(hash[:id])
         | 
| 36 | 
            -
                    if options[:hard_update]
         | 
| 37 | 
            -
                      rec.update_attributes!(hash.except(:id))
         | 
| 38 | 
            -
                    else
         | 
| 39 | 
            -
                      rec.update_attributes(hash.except(:id))
         | 
| 40 | 
            -
                    end
         | 
| 41 | 
            -
                    rec
         | 
| 42 | 
            -
                  end
         | 
| 43 | 
            -
                end
         | 
| 44 | 
            -
             | 
| 45 14 | 
             
                def enum_int(field, values, options = {})
         | 
| 46 15 | 
             
                  const_set("#{field.to_s.upcase}_OPTIONS", values)
         | 
| 47 16 |  | 
| @@ -108,42 +77,6 @@ module ActiveRecordExtensions | |
| 108 77 | 
             
                    EVAL
         | 
| 109 78 | 
             
                  end
         | 
| 110 79 | 
             
                end
         | 
| 111 | 
            -
             | 
| 112 | 
            -
                # Validates presence of -- but works on parent within accepts_nested_attributes
         | 
| 113 | 
            -
                #
         | 
| 114 | 
            -
                def validates_presence_of_parent(foreign_key)
         | 
| 115 | 
            -
                  after_save do |record|
         | 
| 116 | 
            -
                    unless record.send(foreign_key)
         | 
| 117 | 
            -
                      record.errors.add_on_blank(foreign_key)
         | 
| 118 | 
            -
                      raise ActiveRecord::ActiveRecordError, record.errors.full_messages.to_sentence
         | 
| 119 | 
            -
                    end
         | 
| 120 | 
            -
                  end
         | 
| 121 | 
            -
                end
         | 
| 122 | 
            -
             | 
| 123 | 
            -
                # Run a block, being respectful of connection pools
         | 
| 124 | 
            -
                #
         | 
| 125 | 
            -
                # Useful for when you're not in the standard rails request process,
         | 
| 126 | 
            -
                # since normally rails will take, then clear you're connection in the
         | 
| 127 | 
            -
                # processing of the request.
         | 
| 128 | 
            -
                #
         | 
| 129 | 
            -
                # If you don't do this in, say, a command line task with threads, then
         | 
| 130 | 
            -
                # you'll run out of connections after 5 x Threads are run simultaneously...
         | 
| 131 | 
            -
                def with_connection_pooling
         | 
| 132 | 
            -
                  # Verify active connections and remove and disconnect connections
         | 
| 133 | 
            -
                  # associated with stale threads.
         | 
| 134 | 
            -
                  ActiveRecord::Base.verify_active_connections!
         | 
| 135 | 
            -
             | 
| 136 | 
            -
                  yield
         | 
| 137 | 
            -
             | 
| 138 | 
            -
                  # This code checks in the connection being used by the current thread back
         | 
| 139 | 
            -
                  # into the connection pool. It repeats this if you are using multiple
         | 
| 140 | 
            -
                  # connection pools. It will not disconnect the connection.
         | 
| 141 | 
            -
                  #
         | 
| 142 | 
            -
                  # Returns any connections in use by the current thread back to the pool,
         | 
| 143 | 
            -
                  # and also returns connections to the pool cached by threads that are no
         | 
| 144 | 
            -
                  # longer alive.
         | 
| 145 | 
            -
                  ActiveRecord::Base.clear_active_connections!
         | 
| 146 | 
            -
                end
         | 
| 147 80 | 
             
              end
         | 
| 148 81 |  | 
| 149 82 | 
             
              module InstanceMethods
         | 
| @@ -10,7 +10,7 @@ module RailsCoreExtensions | |
| 10 10 | 
             
                  field = field.to_sym
         | 
| 11 11 | 
             
                  before_validation do |record|
         | 
| 12 12 | 
             
                    begin
         | 
| 13 | 
            -
                      Liquid::Template.parse(record.send(field))
         | 
| 13 | 
            +
                      Liquid::Template.parse(record.send(field), error_mode: :strict)
         | 
| 14 14 | 
             
                    rescue Liquid::SyntaxError => e
         | 
| 15 15 | 
             
                      record.errors.add(field, "Liquid Syntax Error: #{e}")
         | 
| 16 16 | 
             
                    end
         | 
| @@ -8,7 +8,7 @@ module RailsCoreExtensions | |
| 8 8 | 
             
                #   category_id (or whatever the name of scope is)
         | 
| 9 9 | 
             
                #   model_1_body (or whatever id of scope id)
         | 
| 10 10 | 
             
                def initialize(params, controller_name)
         | 
| 11 | 
            -
                  @params = params.symbolize_keys
         | 
| 11 | 
            +
                  @params = params.permit!.to_h.symbolize_keys
         | 
| 12 12 | 
             
                  @controller_name = controller_name
         | 
| 13 13 | 
             
                  @klass = controller_name.classify.constantize
         | 
| 14 14 | 
             
                end
         | 
| @@ -26,7 +26,7 @@ module RailsCoreExtensions | |
| 26 26 | 
             
                  collection = @klass.reorder(:position)
         | 
| 27 27 | 
             
                  collection = collection.where(@params.slice(scope)) unless scope.blank?
         | 
| 28 28 |  | 
| 29 | 
            -
                  sort_collection(collection, sorted_id_list.map(&:to_i))
         | 
| 29 | 
            +
                  sort_collection(collection.find(sorted_id_list.map(&:to_i)), sorted_id_list.map(&:to_i))
         | 
| 30 30 | 
             
                end
         | 
| 31 31 |  | 
| 32 32 | 
             
                private
         | 
| @@ -32,8 +32,4 @@ Gem::Specification.new do |spec| | |
| 32 32 | 
             
              spec.add_development_dependency 'rubocop'
         | 
| 33 33 | 
             
              spec.add_development_dependency 'sqlite3'
         | 
| 34 34 | 
             
              spec.add_development_dependency 'travis'
         | 
| 35 | 
            -
             | 
| 36 | 
            -
              # breadcrumbs optional dependencies
         | 
| 37 | 
            -
              spec.add_development_dependency 'make_resourceful'
         | 
| 38 | 
            -
              spec.add_development_dependency 'inherited_resources'
         | 
| 39 35 | 
             
            end
         | 
| @@ -26,7 +26,7 @@ describe RailsCoreExtensions::Sortable do | |
| 26 26 | 
             
                models.each(&:destroy)
         | 
| 27 27 | 
             
              end
         | 
| 28 28 |  | 
| 29 | 
            -
              subject { RailsCoreExtensions::Sortable.new(params, 'models') }
         | 
| 29 | 
            +
              subject { RailsCoreExtensions::Sortable.new(ActionController::Parameters.new(params), 'models') }
         | 
| 30 30 |  | 
| 31 31 | 
             
              RSpec.shared_examples 'unscoped' do
         | 
| 32 32 | 
             
                let(:scope) { Model.reorder(:position) }
         | 
| @@ -68,25 +68,6 @@ describe 'enum_int' do | |
| 68 68 | 
             
              end
         | 
| 69 69 | 
             
            end
         | 
| 70 70 |  | 
| 71 | 
            -
            describe "ActiveRecord::Base" do
         | 
| 72 | 
            -
              let(:mock_model) { double }
         | 
| 73 | 
            -
              let(:model_class) { Class.new(ActiveRecord::Base) }
         | 
| 74 | 
            -
              before { stub_const 'Model', model_class }
         | 
| 75 | 
            -
             | 
| 76 | 
            -
              it "should create a new record if new_or_update! is passed a hash without an :id" do
         | 
| 77 | 
            -
                attributes = {:fake_column => 'nothing really'}
         | 
| 78 | 
            -
                expect(Model).to receive(:new).with(attributes)
         | 
| 79 | 
            -
                Model.new_or_update!(attributes)
         | 
| 80 | 
            -
              end
         | 
| 81 | 
            -
             | 
| 82 | 
            -
              it "should update record if new_or_update! is passed hash with :id" do
         | 
| 83 | 
            -
                attributes = {:fake_column => 'nothing really', :id => 1}
         | 
| 84 | 
            -
                expect(Model).to receive(:find) { mock_model }
         | 
| 85 | 
            -
                expect(mock_model).to receive(:update_attributes!)
         | 
| 86 | 
            -
                Model.new_or_update!(attributes)
         | 
| 87 | 
            -
              end
         | 
| 88 | 
            -
            end
         | 
| 89 | 
            -
             | 
| 90 71 | 
             
            describe RailsCoreExtensions::ActionControllerSortable do
         | 
| 91 72 | 
             
              class NormalController < ActionController::Base
         | 
| 92 73 | 
             
              end
         | 
| @@ -101,38 +82,3 @@ describe RailsCoreExtensions::ActionControllerSortable do | |
| 101 82 | 
             
                expect(SortableController.new.methods.map(&:to_sym)).to include(:sort)
         | 
| 102 83 | 
             
              end
         | 
| 103 84 | 
             
            end
         | 
| 104 | 
            -
             | 
| 105 | 
            -
            describe ActiveRecordExtensions do
         | 
| 106 | 
            -
              let(:model_class) {
         | 
| 107 | 
            -
                Class.new(ActiveRecord::Base) do
         | 
| 108 | 
            -
                  cache_all_attributes :by => 'name'
         | 
| 109 | 
            -
                end
         | 
| 110 | 
            -
              }
         | 
| 111 | 
            -
              let(:first) { Model.create!(:name => 'First') }
         | 
| 112 | 
            -
              let(:second) { Model.create!(:name => 'Second') }
         | 
| 113 | 
            -
              let(:expected) {
         | 
| 114 | 
            -
                {
         | 
| 115 | 
            -
                  'First' => first.attributes,
         | 
| 116 | 
            -
                  'Second' => second.attributes
         | 
| 117 | 
            -
                }
         | 
| 118 | 
            -
              }
         | 
| 119 | 
            -
             | 
| 120 | 
            -
              before do
         | 
| 121 | 
            -
                connect_to_sqlite
         | 
| 122 | 
            -
                stub_const 'Model', model_class
         | 
| 123 | 
            -
                allow(Model).to receive(:cache) { ActiveSupport::Cache::MemoryStore.new }
         | 
| 124 | 
            -
                allow(Model).to receive(:should_cache?) { true }
         | 
| 125 | 
            -
                [first, second]
         | 
| 126 | 
            -
              end
         | 
| 127 | 
            -
             | 
| 128 | 
            -
              it 'should cache all attributes' do
         | 
| 129 | 
            -
                # Test underlying generate attributes hash method works
         | 
| 130 | 
            -
                expect(Model.generate_attributes_hash).to eq expected
         | 
| 131 | 
            -
                expect(Model.attribute_cache).to eq expected
         | 
| 132 | 
            -
             | 
| 133 | 
            -
                # Test after save/destroy it updates
         | 
| 134 | 
            -
                first.destroy
         | 
| 135 | 
            -
                expect(Model.attribute_cache).to eq 'Second' => second.attributes
         | 
| 136 | 
            -
                second.destroy # Clean up after
         | 
| 137 | 
            -
              end
         | 
| 138 | 
            -
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: rails_core_extensions
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.9.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Michael Noack
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date:  | 
| 12 | 
            +
            date: 2020-06-26 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: activerecord
         | 
| @@ -179,34 +179,6 @@ dependencies: | |
| 179 179 | 
             
                - - ">="
         | 
| 180 180 | 
             
                  - !ruby/object:Gem::Version
         | 
| 181 181 | 
             
                    version: '0'
         | 
| 182 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 183 | 
            -
              name: make_resourceful
         | 
| 184 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 185 | 
            -
                requirements:
         | 
| 186 | 
            -
                - - ">="
         | 
| 187 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 188 | 
            -
                    version: '0'
         | 
| 189 | 
            -
              type: :development
         | 
| 190 | 
            -
              prerelease: false
         | 
| 191 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 192 | 
            -
                requirements:
         | 
| 193 | 
            -
                - - ">="
         | 
| 194 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 195 | 
            -
                    version: '0'
         | 
| 196 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 197 | 
            -
              name: inherited_resources
         | 
| 198 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 199 | 
            -
                requirements:
         | 
| 200 | 
            -
                - - ">="
         | 
| 201 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 202 | 
            -
                    version: '0'
         | 
| 203 | 
            -
              type: :development
         | 
| 204 | 
            -
              prerelease: false
         | 
| 205 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 206 | 
            -
                requirements:
         | 
| 207 | 
            -
                - - ">="
         | 
| 208 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 209 | 
            -
                    version: '0'
         | 
| 210 182 | 
             
            description: Set of extensions to core rails libraries.
         | 
| 211 183 | 
             
            email:
         | 
| 212 184 | 
             
            - support@travellink.com.au
         | 
| @@ -229,18 +201,14 @@ files: | |
| 229 201 | 
             
            - gemfiles/rails6.gemfile
         | 
| 230 202 | 
             
            - lib/rails_core_extensions.rb
         | 
| 231 203 | 
             
            - lib/rails_core_extensions/action_controller_sortable.rb
         | 
| 232 | 
            -
            - lib/rails_core_extensions/action_view_currency_extensions.rb
         | 
| 233 204 | 
             
            - lib/rails_core_extensions/action_view_extensions.rb
         | 
| 234 205 | 
             
            - lib/rails_core_extensions/action_view_has_many_extensions.rb
         | 
| 235 206 | 
             
            - lib/rails_core_extensions/activatable.rb
         | 
| 236 207 | 
             
            - lib/rails_core_extensions/active_model_extensions.rb
         | 
| 237 | 
            -
            - lib/rails_core_extensions/active_record_cache_all_attributes.rb
         | 
| 238 208 | 
             
            - lib/rails_core_extensions/active_record_cloning.rb
         | 
| 239 209 | 
             
            - lib/rails_core_extensions/active_record_extensions.rb
         | 
| 240 210 | 
             
            - lib/rails_core_extensions/active_record_liquid_extensions.rb
         | 
| 241 211 | 
             
            - lib/rails_core_extensions/active_support_concern.rb
         | 
| 242 | 
            -
            - lib/rails_core_extensions/breadcrumb.rb
         | 
| 243 | 
            -
            - lib/rails_core_extensions/caches_action_without_host.rb
         | 
| 244 212 | 
             
            - lib/rails_core_extensions/concurrency.rb
         | 
| 245 213 | 
             
            - lib/rails_core_extensions/position_initializer.rb
         | 
| 246 214 | 
             
            - lib/rails_core_extensions/railtie.rb
         | 
| @@ -256,7 +224,6 @@ files: | |
| 256 224 | 
             
            - spec/active_model_extensions_spec.rb
         | 
| 257 225 | 
             
            - spec/active_record_cloning_spec.rb
         | 
| 258 226 | 
             
            - spec/active_record_extensions_spec.rb
         | 
| 259 | 
            -
            - spec/breadcrumb_spec.rb
         | 
| 260 227 | 
             
            - spec/concurrency_spec.rb
         | 
| 261 228 | 
             
            - spec/en.yml
         | 
| 262 229 | 
             
            - spec/position_initializer_spec.rb
         | 
| @@ -285,8 +252,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 285 252 | 
             
                - !ruby/object:Gem::Version
         | 
| 286 253 | 
             
                  version: '0'
         | 
| 287 254 | 
             
            requirements: []
         | 
| 288 | 
            -
             | 
| 289 | 
            -
            rubygems_version: 2.7.3
         | 
| 255 | 
            +
            rubygems_version: 3.1.2
         | 
| 290 256 | 
             
            signing_key: 
         | 
| 291 257 | 
             
            specification_version: 4
         | 
| 292 258 | 
             
            summary: Set of extensions to core rails libraries.
         | 
| @@ -296,7 +262,6 @@ test_files: | |
| 296 262 | 
             
            - spec/active_model_extensions_spec.rb
         | 
| 297 263 | 
             
            - spec/active_record_cloning_spec.rb
         | 
| 298 264 | 
             
            - spec/active_record_extensions_spec.rb
         | 
| 299 | 
            -
            - spec/breadcrumb_spec.rb
         | 
| 300 265 | 
             
            - spec/concurrency_spec.rb
         | 
| 301 266 | 
             
            - spec/en.yml
         | 
| 302 267 | 
             
            - spec/position_initializer_spec.rb
         | 
| @@ -1,26 +0,0 @@ | |
| 1 | 
            -
            module ActionView
         | 
| 2 | 
            -
              module Helpers
         | 
| 3 | 
            -
                module FormTagHelper
         | 
| 4 | 
            -
                  # Create currency selector tag -- see select_tag for options
         | 
| 5 | 
            -
                  def currency_select_tag(name, current_value, options={})
         | 
| 6 | 
            -
                    selectable_options = []
         | 
| 7 | 
            -
                    selectable_options << ["--", nil] if options[:include_blank]
         | 
| 8 | 
            -
                    selectable_options += EnabledCurrency.all.map(&:iso_code) unless EnabledCurrency.all.empty?
         | 
| 9 | 
            -
                    select_tag(name, options_for_select(selectable_options, current_value), options)
         | 
| 10 | 
            -
                  end
         | 
| 11 | 
            -
                end
         | 
| 12 | 
            -
             | 
| 13 | 
            -
                module DateHelper
         | 
| 14 | 
            -
                  def currency_select(object_name, method, options = {})
         | 
| 15 | 
            -
                    value = options[:object] || EnabledCurrency.base_currency
         | 
| 16 | 
            -
                    currency_select_tag("#{object_name}[#{method}]", value, options.merge(:id => "#{object_name}_#{method}")) 
         | 
| 17 | 
            -
                  end
         | 
| 18 | 
            -
                end
         | 
| 19 | 
            -
             | 
| 20 | 
            -
                class FormBuilder
         | 
| 21 | 
            -
                  def currency_select(method, options = {})
         | 
| 22 | 
            -
                    @template.currency_select(@object_name, method, options.merge(:object => @object.send(method)))
         | 
| 23 | 
            -
                  end
         | 
| 24 | 
            -
                end
         | 
| 25 | 
            -
              end
         | 
| 26 | 
            -
            end
         | 
| @@ -1,39 +0,0 @@ | |
| 1 | 
            -
            module ActiveRecordCacheAllAttributes
         | 
| 2 | 
            -
              def self.included(base)
         | 
| 3 | 
            -
                base.extend ClassMethods
         | 
| 4 | 
            -
              end
         | 
| 5 | 
            -
             | 
| 6 | 
            -
              module InstanceMethods
         | 
| 7 | 
            -
                def clear_attribute_cache
         | 
| 8 | 
            -
                  self.class.cache.delete("#{self.class.name}.attribute_cache")
         | 
| 9 | 
            -
                  self.class.clear_request_cache
         | 
| 10 | 
            -
                end
         | 
| 11 | 
            -
              end
         | 
| 12 | 
            -
             | 
| 13 | 
            -
              module ClassMethods
         | 
| 14 | 
            -
                def cache
         | 
| 15 | 
            -
                  Rails.cache
         | 
| 16 | 
            -
                end
         | 
| 17 | 
            -
             | 
| 18 | 
            -
                def clear_request_cache
         | 
| 19 | 
            -
                  @request_cache = nil
         | 
| 20 | 
            -
                end
         | 
| 21 | 
            -
             | 
| 22 | 
            -
                def attribute_cache
         | 
| 23 | 
            -
                  cache_key = "#{name}.attribute_cache"
         | 
| 24 | 
            -
                  @request_cache ||= cache.read(cache_key) || generate_cache(cache_key)
         | 
| 25 | 
            -
                end
         | 
| 26 | 
            -
             | 
| 27 | 
            -
                def generate_attributes_hash
         | 
| 28 | 
            -
                  scope = self
         | 
| 29 | 
            -
                  scope = scope.ordered if respond_to?(:ordered)
         | 
| 30 | 
            -
                  Hash[scope.all.map { |o| [o.send(cache_attributes_by), o.attributes] }]
         | 
| 31 | 
            -
                end
         | 
| 32 | 
            -
             | 
| 33 | 
            -
                def generate_cache(cache_key)
         | 
| 34 | 
            -
                  cache_value = generate_attributes_hash
         | 
| 35 | 
            -
                  cache.write(cache_key, cache_value)
         | 
| 36 | 
            -
                  cache_value
         | 
| 37 | 
            -
                end
         | 
| 38 | 
            -
              end
         | 
| 39 | 
            -
            end
         | 
| @@ -1,170 +0,0 @@ | |
| 1 | 
            -
            module RailsCoreExtensions
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              module Breadcrumb
         | 
| 4 | 
            -
             | 
| 5 | 
            -
                def breadcrumbs(object_or_nested_array = nil)
         | 
| 6 | 
            -
                  breadcrumbs_builder_for(object_or_nested_array).breadcrumbs
         | 
| 7 | 
            -
                end
         | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
                private
         | 
| 11 | 
            -
             | 
| 12 | 
            -
                def breadcrumbs_builder_for(object_or_nested_array)
         | 
| 13 | 
            -
                  BreadcrumbsBuilder.new(self, object_or_nested_array)
         | 
| 14 | 
            -
                end
         | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
                class BreadcrumbsBuilder
         | 
| 18 | 
            -
             | 
| 19 | 
            -
                  attr_reader :view, :object_or_nested_array, :path
         | 
| 20 | 
            -
             | 
| 21 | 
            -
                  def initialize(view, object_or_nested_array = nil)
         | 
| 22 | 
            -
                    @view                     =   view
         | 
| 23 | 
            -
                    @object_or_nested_array   =   object_or_nested_array ||   path_builder.nested_array
         | 
| 24 | 
            -
                    @path                     =   path_builder.collection_url
         | 
| 25 | 
            -
                  end
         | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
                  def breadcrumbs
         | 
| 29 | 
            -
                    view.content_tag :ul, :class =>'breadcrumb' do
         | 
| 30 | 
            -
                      (breadcrumb_for_parent + breadcrumb_for_collection + breadcrumb_for_action).html_safe
         | 
| 31 | 
            -
                    end
         | 
| 32 | 
            -
                  end
         | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 35 | 
            -
                  def breadcrumb_for_object_link
         | 
| 36 | 
            -
                    breadcrumb_for link_to_object
         | 
| 37 | 
            -
                  end
         | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
                  private
         | 
| 41 | 
            -
             | 
| 42 | 
            -
                  def breadcrumb_for_parent
         | 
| 43 | 
            -
                    parent = path_builder.parent
         | 
| 44 | 
            -
                    return ''.html_safe unless parent
         | 
| 45 | 
            -
                    BreadcrumbsBuilder.new(view, parent).breadcrumb_for_object_link
         | 
| 46 | 
            -
                  end
         | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 49 | 
            -
                  def breadcrumb_for_collection
         | 
| 50 | 
            -
                    breadcrumb_for view.link_to(object.class.table_name.titleize, path)
         | 
| 51 | 
            -
                  end
         | 
| 52 | 
            -
             | 
| 53 | 
            -
             | 
| 54 | 
            -
                  def breadcrumb_for_action
         | 
| 55 | 
            -
                    case action
         | 
| 56 | 
            -
                      when 'new'    then breadcrumb_for('New', :class => 'active')
         | 
| 57 | 
            -
                      when 'edit'   then breadcrumb_for_object + breadcrumb_for('Edit', :class => 'active')
         | 
| 58 | 
            -
                      else breadcrumb_for_object_name
         | 
| 59 | 
            -
                    end
         | 
| 60 | 
            -
                  end
         | 
| 61 | 
            -
             | 
| 62 | 
            -
             | 
| 63 | 
            -
                  def breadcrumb_for_object
         | 
| 64 | 
            -
                    if can_show?
         | 
| 65 | 
            -
                      breadcrumb_for_object_link
         | 
| 66 | 
            -
                    else
         | 
| 67 | 
            -
                      breadcrumb_for_object_name
         | 
| 68 | 
            -
                    end
         | 
| 69 | 
            -
                  end
         | 
| 70 | 
            -
             | 
| 71 | 
            -
             | 
| 72 | 
            -
                  def breadcrumb_for(content, options = {})
         | 
| 73 | 
            -
                    view.content_tag :li, content, options
         | 
| 74 | 
            -
                  end
         | 
| 75 | 
            -
             | 
| 76 | 
            -
             | 
| 77 | 
            -
                  def breadcrumb_for_object_name
         | 
| 78 | 
            -
                    breadcrumb_for object_name.html_safe
         | 
| 79 | 
            -
                  end
         | 
| 80 | 
            -
             | 
| 81 | 
            -
             | 
| 82 | 
            -
                  def link_to_object
         | 
| 83 | 
            -
                    view.link_to object_name.html_safe, object_or_nested_array
         | 
| 84 | 
            -
                  end
         | 
| 85 | 
            -
             | 
| 86 | 
            -
             | 
| 87 | 
            -
                  def can_show?
         | 
| 88 | 
            -
                    view.controller.respond_to?(:show)
         | 
| 89 | 
            -
                  end
         | 
| 90 | 
            -
             | 
| 91 | 
            -
             | 
| 92 | 
            -
                  def action
         | 
| 93 | 
            -
                    return 'new' if object.new_record?
         | 
| 94 | 
            -
                    view.params[:action]
         | 
| 95 | 
            -
                  end
         | 
| 96 | 
            -
             | 
| 97 | 
            -
             | 
| 98 | 
            -
                  def object_name
         | 
| 99 | 
            -
                    if object.respond_to?(:name) && object.name.present?
         | 
| 100 | 
            -
                      object.name
         | 
| 101 | 
            -
                    else
         | 
| 102 | 
            -
                      object.to_s
         | 
| 103 | 
            -
                    end
         | 
| 104 | 
            -
                  end
         | 
| 105 | 
            -
             | 
| 106 | 
            -
             | 
| 107 | 
            -
                  def object
         | 
| 108 | 
            -
                    @object ||= Array(object_or_nested_array).last
         | 
| 109 | 
            -
                  end
         | 
| 110 | 
            -
             | 
| 111 | 
            -
             | 
| 112 | 
            -
                  def path_builder
         | 
| 113 | 
            -
                    @path_builder ||= if inherited_resources?
         | 
| 114 | 
            -
                                        InheritedResourcesPathBuilder.new(view)
         | 
| 115 | 
            -
                                      else
         | 
| 116 | 
            -
                                        PathBuilder.new(view)
         | 
| 117 | 
            -
                                      end
         | 
| 118 | 
            -
                  end
         | 
| 119 | 
            -
             | 
| 120 | 
            -
             | 
| 121 | 
            -
                  def inherited_resources?
         | 
| 122 | 
            -
                    defined?(InheritedResources) && view.controller.responder == InheritedResources::Responder
         | 
| 123 | 
            -
                  end
         | 
| 124 | 
            -
             | 
| 125 | 
            -
                end
         | 
| 126 | 
            -
             | 
| 127 | 
            -
             | 
| 128 | 
            -
                PathBuilder = Struct.new(:view) do
         | 
| 129 | 
            -
                  def nested_array
         | 
| 130 | 
            -
                    (namespaces + [parent] + [view.current_object]).compact
         | 
| 131 | 
            -
                  end
         | 
| 132 | 
            -
             | 
| 133 | 
            -
                  def collection_url
         | 
| 134 | 
            -
                    view.objects_path
         | 
| 135 | 
            -
                  end
         | 
| 136 | 
            -
             | 
| 137 | 
            -
                  def parent
         | 
| 138 | 
            -
                    view.parent_object
         | 
| 139 | 
            -
                  end
         | 
| 140 | 
            -
             | 
| 141 | 
            -
                  def namespaces
         | 
| 142 | 
            -
                    return [] unless view.respond_to?(:namespaces)
         | 
| 143 | 
            -
                    Array(view.namespaces)
         | 
| 144 | 
            -
                  end
         | 
| 145 | 
            -
                end
         | 
| 146 | 
            -
             | 
| 147 | 
            -
             | 
| 148 | 
            -
                InheritedResourcesPathBuilder = Struct.new(:view) do
         | 
| 149 | 
            -
                  def nested_array
         | 
| 150 | 
            -
                    if view.respond_to? :calculate_nested_array
         | 
| 151 | 
            -
                      view.calculate_nested_array
         | 
| 152 | 
            -
                    else
         | 
| 153 | 
            -
                      [parent, view.resource].compact
         | 
| 154 | 
            -
                    end
         | 
| 155 | 
            -
                  end
         | 
| 156 | 
            -
             | 
| 157 | 
            -
                  def collection_url
         | 
| 158 | 
            -
                    view.collection_url
         | 
| 159 | 
            -
                  end
         | 
| 160 | 
            -
             | 
| 161 | 
            -
                  def parent
         | 
| 162 | 
            -
                    return view.parent.becomes(view.parent.class.base_class) if view.respond_to?(:parent)
         | 
| 163 | 
            -
                    view.parent_object
         | 
| 164 | 
            -
                  end
         | 
| 165 | 
            -
                end
         | 
| 166 | 
            -
             | 
| 167 | 
            -
              end
         | 
| 168 | 
            -
            end
         | 
| 169 | 
            -
             | 
| 170 | 
            -
            ActionView::Base.send(:include, RailsCoreExtensions::Breadcrumb) if defined?(ActionView::Base)
         | 
| @@ -1,17 +0,0 @@ | |
| 1 | 
            -
            module CachesActionWithoutHost
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              def self.included(controller)
         | 
| 4 | 
            -
                controller.extend(ClassMethods)
         | 
| 5 | 
            -
              end
         | 
| 6 | 
            -
             | 
| 7 | 
            -
              module ClassMethods
         | 
| 8 | 
            -
                def caches_action_without_host(*args)
         | 
| 9 | 
            -
                  options = args.extract_options!
         | 
| 10 | 
            -
                  options ||= {}
         | 
| 11 | 
            -
                  options[:cache_path] ||= proc{|c| c.url_for(c.params).split(/\//, 4).last}
         | 
| 12 | 
            -
                  args << options
         | 
| 13 | 
            -
                  caches_action(*args)
         | 
| 14 | 
            -
                end
         | 
| 15 | 
            -
              end
         | 
| 16 | 
            -
             | 
| 17 | 
            -
            end
         | 
    
        data/spec/breadcrumb_spec.rb
    DELETED
    
    | @@ -1,86 +0,0 @@ | |
| 1 | 
            -
            require 'rails_core_extensions/breadcrumb'
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            require 'action_view'
         | 
| 4 | 
            -
            require 'action_view/helpers'
         | 
| 5 | 
            -
             | 
| 6 | 
            -
            describe RailsCoreExtensions::Breadcrumb do
         | 
| 7 | 
            -
              before do
         | 
| 8 | 
            -
                class MockView
         | 
| 9 | 
            -
                  include ActionView::Helpers::TagHelper
         | 
| 10 | 
            -
                  include ActionView::Helpers::UrlHelper
         | 
| 11 | 
            -
                  include ActionView::Helpers::CaptureHelper
         | 
| 12 | 
            -
                  attr_accessor :output_buffer
         | 
| 13 | 
            -
                  include RailsCoreExtensions::Breadcrumb
         | 
| 14 | 
            -
             | 
| 15 | 
            -
                  attr_reader :params
         | 
| 16 | 
            -
             | 
| 17 | 
            -
                  def initialize(params)
         | 
| 18 | 
            -
                    @params = params
         | 
| 19 | 
            -
                  end
         | 
| 20 | 
            -
                end
         | 
| 21 | 
            -
              end
         | 
| 22 | 
            -
             | 
| 23 | 
            -
              after { Object.send(:remove_const, 'MockView') }
         | 
| 24 | 
            -
             | 
| 25 | 
            -
              subject { MockView.new(:action => action) }
         | 
| 26 | 
            -
             | 
| 27 | 
            -
              let(:objects_path) { '/users' }
         | 
| 28 | 
            -
              let(:parent) { nil }
         | 
| 29 | 
            -
             | 
| 30 | 
            -
              before do
         | 
| 31 | 
            -
                allow(subject).to receive(:objects_path) { objects_path }
         | 
| 32 | 
            -
                allow(subject).to receive(:collection_url) { objects_path }
         | 
| 33 | 
            -
             | 
| 34 | 
            -
                allow(subject).to receive(:parent) { parent }
         | 
| 35 | 
            -
                allow(subject).to receive(:parent_object) { parent }
         | 
| 36 | 
            -
             | 
| 37 | 
            -
                allow(subject).to receive(:controller) { double(:controller, :show => nil) }
         | 
| 38 | 
            -
              end
         | 
| 39 | 
            -
             | 
| 40 | 
            -
              context '#breadcrumbs (* = link)' do
         | 
| 41 | 
            -
                let(:user_class) { double(:table_name => 'users', :model_name => double(:singular_route_key => 'user')) }
         | 
| 42 | 
            -
                let(:user) { double(:to_s => 'Alice', :new_record? => new_record, :class => user_class) }
         | 
| 43 | 
            -
                context 'for a new record' do
         | 
| 44 | 
            -
                  let(:action) { 'new' }
         | 
| 45 | 
            -
                  let(:new_record) { true }
         | 
| 46 | 
            -
             | 
| 47 | 
            -
                  it 'should breadcrumb: *Users / New' do
         | 
| 48 | 
            -
                    result = subject.breadcrumbs(user)
         | 
| 49 | 
            -
                    expect(result).to be_html_safe
         | 
| 50 | 
            -
                    expect(result).to eq(
         | 
| 51 | 
            -
                      %q(<ul class="breadcrumb"><li><a href="/users">Users</a></li><li class="active">New</li></ul>)
         | 
| 52 | 
            -
                    )
         | 
| 53 | 
            -
                  end
         | 
| 54 | 
            -
                end
         | 
| 55 | 
            -
             | 
| 56 | 
            -
                context 'for a existing record' do
         | 
| 57 | 
            -
                  let(:new_record) { false }
         | 
| 58 | 
            -
             | 
| 59 | 
            -
                  context 'when editing' do
         | 
| 60 | 
            -
                    let(:action) { 'edit' }
         | 
| 61 | 
            -
                    it 'should breadcrumb: *Users / *Alice / Edit' do
         | 
| 62 | 
            -
                      expect(subject).to receive(:link_to).with('Users', '/users') {
         | 
| 63 | 
            -
                        '<a href="/users">Users</a>'.html_safe }
         | 
| 64 | 
            -
                      expect(subject).to receive(:link_to).with('Alice', user) {
         | 
| 65 | 
            -
                        '<a href="/users/1">Alice</a>'.html_safe }
         | 
| 66 | 
            -
                      result = subject.breadcrumbs(user)
         | 
| 67 | 
            -
                      expect(result).to be_html_safe
         | 
| 68 | 
            -
                      expect(result).to eq(
         | 
| 69 | 
            -
                        %q(<ul class="breadcrumb"><li><a href="/users">Users</a></li><li><a href="/users/1">Alice</a></li><li class="active">Edit</li></ul>)
         | 
| 70 | 
            -
                      )
         | 
| 71 | 
            -
                    end
         | 
| 72 | 
            -
                  end
         | 
| 73 | 
            -
             | 
| 74 | 
            -
                  context 'when showing' do
         | 
| 75 | 
            -
                    let(:action) { 'show' }
         | 
| 76 | 
            -
                    it 'should breadcrumb: *Users / Alice' do
         | 
| 77 | 
            -
                      result = subject.breadcrumbs(user)
         | 
| 78 | 
            -
                      expect(result).to be_html_safe
         | 
| 79 | 
            -
                      expect(result).to eq(
         | 
| 80 | 
            -
                        %q(<ul class="breadcrumb"><li><a href="/users">Users</a></li><li>Alice</li></ul>)
         | 
| 81 | 
            -
                      )
         | 
| 82 | 
            -
                    end
         | 
| 83 | 
            -
                  end
         | 
| 84 | 
            -
                end
         | 
| 85 | 
            -
              end
         | 
| 86 | 
            -
            end
         |