simple_slug 0.1.0 → 0.2.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/lib/simple_slug/version.rb +1 -1
- data/simple_slug.gemspec +1 -1
- data/spec/simple_slug/base_spec.rb +3 -3
- data/spec/simple_slug/history_spec.rb +14 -14
- data/spec/simple_slug/model_addition_spec.rb +17 -17
- metadata +5 -5
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: a288220a77771ee9ef0b7578d6831e83dfa9e8fe
         | 
| 4 | 
            +
              data.tar.gz: 9ecf9b7e5d4cabc46e09aff7dc2738533eb04029
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 8980a48ed1d7db74e82f1baf19ba7d2b2fed3380123b9cd44028771adbbb14346b8e7b7031c8bd5d25d03da136afe5458b4f5dab380352f4a01d7189aed31b6f
         | 
| 7 | 
            +
              data.tar.gz: 680168768188b1fd55f03010a2b660269347f72b1d38b5cda9dd5ec1a1fdfd0ffdcb0d5e049b71c6dee06076fd045976a80e5ba40522517dce319995c2791115
         | 
    
        data/lib/simple_slug/version.rb
    CHANGED
    
    
    
        data/simple_slug.gemspec
    CHANGED
    
    | @@ -19,7 +19,7 @@ Gem::Specification.new do |spec| | |
| 19 19 | 
             
              spec.require_paths = ['lib']
         | 
| 20 20 |  | 
| 21 21 | 
             
              spec.add_dependency 'activerecord', '>= 4.0.0', '< 5.0'
         | 
| 22 | 
            -
              spec.add_dependency 'i18n', '~> 0.6 | 
| 22 | 
            +
              spec.add_dependency 'i18n', '~> 0.6'
         | 
| 23 23 |  | 
| 24 24 | 
             
              spec.add_development_dependency 'bundler', '~> 1.5'
         | 
| 25 25 | 
             
              spec.add_development_dependency 'rake'
         | 
| @@ -3,15 +3,15 @@ require 'spec_helper' | |
| 3 3 | 
             
            describe SimpleSlug do
         | 
| 4 4 | 
             
              context 'defaults' do
         | 
| 5 5 | 
             
                it 'slug column' do
         | 
| 6 | 
            -
                  SimpleSlug.slug_column. | 
| 6 | 
            +
                  expect(SimpleSlug.slug_column).to eq 'slug'
         | 
| 7 7 | 
             
                end
         | 
| 8 8 |  | 
| 9 9 | 
             
                it 'excludes' do
         | 
| 10 | 
            -
                  SimpleSlug.excludes. | 
| 10 | 
            +
                  expect(SimpleSlug.excludes).to include('new', 'edit')
         | 
| 11 11 | 
             
                end
         | 
| 12 12 |  | 
| 13 13 | 
             
                it 'exclude regexps' do
         | 
| 14 | 
            -
             | 
| 14 | 
            +
                 expect( SimpleSlug.exclude_regexp).to eq /\A\d+\z/
         | 
| 15 15 | 
             
                end
         | 
| 16 16 | 
             
              end
         | 
| 17 17 | 
             
            end
         | 
| @@ -7,21 +7,21 @@ end | |
| 7 7 | 
             
            describe 'slug history' do
         | 
| 8 8 | 
             
              describe 'history records handling' do
         | 
| 9 9 | 
             
                before do
         | 
| 10 | 
            -
                  SlugHistoryRspecModel. | 
| 10 | 
            +
                  expect_any_instance_of(SlugHistoryRspecModel).to receive(:simple_slug_exists?).and_return(false)
         | 
| 11 11 | 
             
                end
         | 
| 12 12 |  | 
| 13 13 | 
             
                it 'create' do
         | 
| 14 14 | 
             
                  relation = double
         | 
| 15 | 
            -
                  ::SimpleSlug::HistorySlug. | 
| 16 | 
            -
                  relation. | 
| 15 | 
            +
                  expect(::SimpleSlug::HistorySlug).to receive(:where).once.ordered.with(sluggable_type: 'SlugHistoryRspecModel', sluggable_id: 1, slug: 'hello').and_return(relation)
         | 
| 16 | 
            +
                  expect(relation).to receive(:first_or_create)
         | 
| 17 17 | 
             
                  SlugHistoryRspecModel.create(id: 1, name: 'Hello')
         | 
| 18 18 | 
             
                end
         | 
| 19 19 |  | 
| 20 20 | 
             
                it 'cleanup' do
         | 
| 21 21 | 
             
                  relation = double
         | 
| 22 | 
            -
                  relation. | 
| 23 | 
            -
                  ::SimpleSlug::HistorySlug. | 
| 24 | 
            -
                  relation. | 
| 22 | 
            +
                  expect(relation).to receive(:first_or_create)
         | 
| 23 | 
            +
                  allow(::SimpleSlug::HistorySlug).to receive(:where).and_return(relation)
         | 
| 24 | 
            +
                  expect(relation).to receive(:delete_all)
         | 
| 25 25 | 
             
                  SlugHistoryRspecModel.create(name: 'Hello', id: 1).destroy
         | 
| 26 26 | 
             
                end
         | 
| 27 27 | 
             
              end
         | 
| @@ -29,24 +29,24 @@ describe 'slug history' do | |
| 29 29 | 
             
              describe 'conflicts' do
         | 
| 30 30 | 
             
                it 'history slug exists' do
         | 
| 31 31 | 
             
                  record = SlugGenerationRspecModel.new(name: 'Hi')
         | 
| 32 | 
            -
                  record. | 
| 33 | 
            -
                  record. | 
| 34 | 
            -
                  record. | 
| 32 | 
            +
                  allow(record).to receive(:simple_slug_base_exists?).and_return(false)
         | 
| 33 | 
            +
                  expect(record).to receive(:simple_slug_history_exists?).once.ordered.and_return(true)
         | 
| 34 | 
            +
                  expect(record).to receive(:simple_slug_history_exists?).once.ordered.and_return(false)
         | 
| 35 35 | 
             
                  record.save
         | 
| 36 | 
            -
                  record.slug. | 
| 36 | 
            +
                  expect(record.slug).to start_with('hi--')
         | 
| 37 37 | 
             
                end
         | 
| 38 38 | 
             
              end
         | 
| 39 39 |  | 
| 40 40 | 
             
              describe '#friendly_find' do
         | 
| 41 41 | 
             
                before do
         | 
| 42 | 
            -
                  SlugHistoryRspecModel. | 
| 42 | 
            +
                  allow(SlugHistoryRspecModel).to receive(:find_by)
         | 
| 43 43 | 
             
                end
         | 
| 44 44 |  | 
| 45 45 | 
             
                it 'find from history' do
         | 
| 46 46 | 
             
                  record = double('history')
         | 
| 47 | 
            -
                  record. | 
| 48 | 
            -
                  ::SimpleSlug::HistorySlug. | 
| 49 | 
            -
                  SlugHistoryRspecModel. | 
| 47 | 
            +
                  allow(record).to receive(:sluggable_id).and_return(1)
         | 
| 48 | 
            +
                  expect(::SimpleSlug::HistorySlug).to receive(:find_by!).with(slug: 'title').and_return(record)
         | 
| 49 | 
            +
                  expect(SlugHistoryRspecModel).to receive(:find).with(1).and_return(record)
         | 
| 50 50 | 
             
                  SlugHistoryRspecModel.friendly_find('title')
         | 
| 51 51 | 
             
                end
         | 
| 52 52 | 
             
              end
         | 
| @@ -7,71 +7,71 @@ end | |
| 7 7 | 
             
            describe SimpleSlug::ModelAddition do
         | 
| 8 8 | 
             
              describe 'slug generation' do
         | 
| 9 9 | 
             
                before do
         | 
| 10 | 
            -
                  SlugGenerationRspecModel. | 
| 10 | 
            +
                  allow_any_instance_of(SlugGenerationRspecModel). to receive(:simple_slug_exists?).and_return(false)
         | 
| 11 11 | 
             
                end
         | 
| 12 12 |  | 
| 13 13 | 
             
                it 'after save' do
         | 
| 14 | 
            -
                  SlugGenerationRspecModel.create(name: 'Hello').slug. | 
| 14 | 
            +
                  expect(SlugGenerationRspecModel.create(name: 'Hello').slug).to eq 'hello'
         | 
| 15 15 | 
             
                end
         | 
| 16 16 |  | 
| 17 17 | 
             
                it 'skip excludes' do
         | 
| 18 | 
            -
                  SlugGenerationRspecModel.new(name: 'new'). | 
| 18 | 
            +
                  expect(SlugGenerationRspecModel.new(name: 'new')).not_to be_valid
         | 
| 19 19 | 
             
                end
         | 
| 20 20 |  | 
| 21 21 | 
             
                it 'skip integers' do
         | 
| 22 | 
            -
                  SlugGenerationRspecModel.new(name: '123'). | 
| 22 | 
            +
                  expect(SlugGenerationRspecModel.new(name: '123')).not_to be_valid
         | 
| 23 23 | 
             
                end
         | 
| 24 24 |  | 
| 25 25 | 
             
                it 'skip slug generation' do
         | 
| 26 | 
            -
                  SlugGenerationRspecModel. | 
| 27 | 
            -
                  SlugGenerationRspecModel.create(name: 'Hello').slug. | 
| 26 | 
            +
                  allow_any_instance_of(SlugGenerationRspecModel).to receive(:should_generate_new_slug?).and_return(false)
         | 
| 27 | 
            +
                  expect(SlugGenerationRspecModel.create(name: 'Hello').slug).to be_blank
         | 
| 28 28 | 
             
                end
         | 
| 29 29 | 
             
              end
         | 
| 30 30 |  | 
| 31 31 | 
             
              describe 'resolve conflicts' do
         | 
| 32 32 | 
             
                it 'duplicate slug' do
         | 
| 33 33 | 
             
                  record = SlugGenerationRspecModel.new(name: 'Hi')
         | 
| 34 | 
            -
                  record. | 
| 35 | 
            -
                  record. | 
| 34 | 
            +
                  expect(record).to receive(:simple_slug_exists?).once.ordered.with('hi').and_return(true)
         | 
| 35 | 
            +
                  expect(record).to receive(:simple_slug_exists?).once.ordered.with(/hi--\d+/).and_return(false)
         | 
| 36 36 | 
             
                  record.save
         | 
| 37 | 
            -
                  record.slug. | 
| 37 | 
            +
                  expect(record.slug).to start_with('hi--')
         | 
| 38 38 | 
             
                end
         | 
| 39 39 |  | 
| 40 40 | 
             
                it 'numeric slug' do
         | 
| 41 41 | 
             
                  record = SlugGenerationRspecModel.new(name: '123')
         | 
| 42 | 
            -
                  record. | 
| 42 | 
            +
                  expect(record).to receive(:simple_slug_exists?).with('_123').and_return(false)
         | 
| 43 43 | 
             
                  record.save
         | 
| 44 | 
            -
                  record.slug. | 
| 44 | 
            +
                  expect(record.slug).to eq '_123'
         | 
| 45 45 | 
             
                end
         | 
| 46 46 | 
             
              end
         | 
| 47 47 |  | 
| 48 48 | 
             
              describe '#to_param' do
         | 
| 49 49 | 
             
                before do
         | 
| 50 | 
            -
                  SlugGenerationRspecModel. | 
| 50 | 
            +
                  allow_any_instance_of(SlugGenerationRspecModel).to receive(:simple_slug_exists?).and_return(false)
         | 
| 51 51 | 
             
                end
         | 
| 52 52 |  | 
| 53 53 | 
             
                it 'slug if exists' do
         | 
| 54 | 
            -
                  SlugGenerationRspecModel.create(name: 'Hello').to_param. | 
| 54 | 
            +
                  expect(SlugGenerationRspecModel.create(name: 'Hello').to_param).to eq 'hello'
         | 
| 55 55 | 
             
                end
         | 
| 56 56 |  | 
| 57 57 | 
             
                it 'id without slug' do
         | 
| 58 | 
            -
                  SlugGenerationRspecModel.create(id: 1).to_param. | 
| 58 | 
            +
                  expect(SlugGenerationRspecModel.create(id: 1).to_param).to eq '1'
         | 
| 59 59 | 
             
                end
         | 
| 60 60 | 
             
              end
         | 
| 61 61 |  | 
| 62 62 | 
             
              describe '#friendly_find' do
         | 
| 63 63 | 
             
                it '#find if integer like' do
         | 
| 64 | 
            -
                  SlugGenerationRspecModel. | 
| 64 | 
            +
                  expect(SlugGenerationRspecModel).to receive(:find).with(1)
         | 
| 65 65 | 
             
                  SlugGenerationRspecModel.friendly_find(1)
         | 
| 66 66 | 
             
                end
         | 
| 67 67 |  | 
| 68 68 | 
             
                it '#find if numeric string' do
         | 
| 69 | 
            -
                  SlugGenerationRspecModel. | 
| 69 | 
            +
                  expect(SlugGenerationRspecModel).to receive(:find).with('1')
         | 
| 70 70 | 
             
                  SlugGenerationRspecModel.friendly_find('1')
         | 
| 71 71 | 
             
                end
         | 
| 72 72 |  | 
| 73 73 | 
             
                it 'find by slug' do
         | 
| 74 | 
            -
                  SlugGenerationRspecModel. | 
| 74 | 
            +
                  expect(SlugGenerationRspecModel).to receive(:find_by!).with('slug' => 'title').and_return(double)
         | 
| 75 75 | 
             
                  SlugGenerationRspecModel.friendly_find('title')
         | 
| 76 76 | 
             
                end
         | 
| 77 77 | 
             
              end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: simple_slug
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.2.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Alex Leschenko
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2014- | 
| 11 | 
            +
            date: 2014-12-21 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: activerecord
         | 
| @@ -36,14 +36,14 @@ dependencies: | |
| 36 36 | 
             
                requirements:
         | 
| 37 37 | 
             
                - - "~>"
         | 
| 38 38 | 
             
                  - !ruby/object:Gem::Version
         | 
| 39 | 
            -
                    version: 0.6 | 
| 39 | 
            +
                    version: '0.6'
         | 
| 40 40 | 
             
              type: :runtime
         | 
| 41 41 | 
             
              prerelease: false
         | 
| 42 42 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 43 43 | 
             
                requirements:
         | 
| 44 44 | 
             
                - - "~>"
         | 
| 45 45 | 
             
                  - !ruby/object:Gem::Version
         | 
| 46 | 
            -
                    version: 0.6 | 
| 46 | 
            +
                    version: '0.6'
         | 
| 47 47 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 48 48 | 
             
              name: bundler
         | 
| 49 49 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 130 130 | 
             
                  version: '0'
         | 
| 131 131 | 
             
            requirements: []
         | 
| 132 132 | 
             
            rubyforge_project: 
         | 
| 133 | 
            -
            rubygems_version: 2. | 
| 133 | 
            +
            rubygems_version: 2.4.3
         | 
| 134 134 | 
             
            signing_key: 
         | 
| 135 135 | 
             
            specification_version: 4
         | 
| 136 136 | 
             
            summary: Friendly url generator with history.
         |