kakurenbo 0.1.3 → 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/.travis.yml +2 -3
 - data/Gemfile +4 -0
 - data/README.md +24 -12
 - data/kakurenbo.gemspec +2 -2
 - data/lib/kakurenbo.rb +8 -1
 - data/lib/kakurenbo/{soft_delete_core.rb → core.rb} +76 -53
 - data/lib/kakurenbo/mixin_ar_base.rb +38 -15
 - data/lib/kakurenbo/mixin_ar_relation.rb +82 -0
 - data/lib/kakurenbo/version.rb +1 -1
 - data/spec/kakurenbo/cores/associations_spec.rb +178 -0
 - data/spec/kakurenbo/cores/callbacks_spec.rb +102 -0
 - data/spec/kakurenbo/cores/core_spec.rb +186 -0
 - data/spec/kakurenbo/cores/scopes_spec.rb +96 -0
 - data/spec/kakurenbo/mixin_ar_base_spec.rb +65 -46
 - data/spec/kakurenbo/mixin_ar_relation_spec.rb +117 -0
 - data/spec/spec_helper.rb +15 -2
 - metadata +19 -16
 - data/spec/kakurenbo/soft_delete_cores/associations_spec.rb +0 -270
 - data/spec/kakurenbo/soft_delete_cores/callbacks_spec.rb +0 -38
 - data/spec/kakurenbo/soft_delete_cores/core_spec.rb +0 -229
 - data/spec/kakurenbo/soft_delete_cores/scopes_spec.rb +0 -60
 
| 
         @@ -0,0 +1,96 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe Kakurenbo::Core::Scopes do
         
     | 
| 
      
 4 
     | 
    
         
            +
              create_temp_table(:paranoid_models){ |t| t.datetime :deleted_at }
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              let!(:existing_model) { ParanoidModel.create! }
         
     | 
| 
      
 7 
     | 
    
         
            +
              let!(:deleted_model)  { ParanoidModel.create!(deleted_at: Time.now) }
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
              describe 'default_scope' do
         
     | 
| 
      
 10 
     | 
    
         
            +
                subject do
         
     | 
| 
      
 11 
     | 
    
         
            +
                  ParanoidModel.find_by(id: model.id)
         
     | 
| 
      
 12 
     | 
    
         
            +
                end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                context 'when existing_model' do
         
     | 
| 
      
 15 
     | 
    
         
            +
                  let(:model) { existing_model }
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                  it 'can get.' do
         
     | 
| 
      
 18 
     | 
    
         
            +
                    expect(subject).not_to be_nil
         
     | 
| 
      
 19 
     | 
    
         
            +
                  end
         
     | 
| 
      
 20 
     | 
    
         
            +
                end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                context 'when deleted_model' do
         
     | 
| 
      
 23 
     | 
    
         
            +
                  let(:model) { deleted_model }
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                  it 'can not get.' do
         
     | 
| 
      
 26 
     | 
    
         
            +
                    expect(subject).to be_nil
         
     | 
| 
      
 27 
     | 
    
         
            +
                  end
         
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
              describe 'only_deleted' do
         
     | 
| 
      
 32 
     | 
    
         
            +
                subject do
         
     | 
| 
      
 33 
     | 
    
         
            +
                  ParanoidModel.only_deleted.find_by(id: model.id)
         
     | 
| 
      
 34 
     | 
    
         
            +
                end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                context 'when existing_model' do
         
     | 
| 
      
 37 
     | 
    
         
            +
                  let(:model) { existing_model }
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                  it 'can not get.' do
         
     | 
| 
      
 40 
     | 
    
         
            +
                    expect(subject).to be_nil
         
     | 
| 
      
 41 
     | 
    
         
            +
                  end
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                context 'when deleted_model' do
         
     | 
| 
      
 45 
     | 
    
         
            +
                  let(:model) { deleted_model }
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                  it 'can get.' do
         
     | 
| 
      
 48 
     | 
    
         
            +
                    expect(subject).not_to be_nil
         
     | 
| 
      
 49 
     | 
    
         
            +
                  end
         
     | 
| 
      
 50 
     | 
    
         
            +
                end
         
     | 
| 
      
 51 
     | 
    
         
            +
              end
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
              describe 'with_deleted' do
         
     | 
| 
      
 54 
     | 
    
         
            +
                subject do
         
     | 
| 
      
 55 
     | 
    
         
            +
                  ParanoidModel.with_deleted.find_by(id: model.id)
         
     | 
| 
      
 56 
     | 
    
         
            +
                end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                context 'when existing_model' do
         
     | 
| 
      
 59 
     | 
    
         
            +
                  let(:model) { existing_model }
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
                  it 'can get.' do
         
     | 
| 
      
 62 
     | 
    
         
            +
                    expect(subject).not_to be_nil
         
     | 
| 
      
 63 
     | 
    
         
            +
                  end
         
     | 
| 
      
 64 
     | 
    
         
            +
                end
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                context 'when deleted_model' do
         
     | 
| 
      
 67 
     | 
    
         
            +
                  let(:model) { deleted_model }
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                  it 'can get.' do
         
     | 
| 
      
 70 
     | 
    
         
            +
                    expect(subject).not_to be_nil
         
     | 
| 
      
 71 
     | 
    
         
            +
                  end
         
     | 
| 
      
 72 
     | 
    
         
            +
                end
         
     | 
| 
      
 73 
     | 
    
         
            +
              end
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
              describe 'without_deleted' do
         
     | 
| 
      
 76 
     | 
    
         
            +
                subject do
         
     | 
| 
      
 77 
     | 
    
         
            +
                  ParanoidModel.without_deleted.find_by(id: model.id)
         
     | 
| 
      
 78 
     | 
    
         
            +
                end
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
                context 'when existing_model' do
         
     | 
| 
      
 81 
     | 
    
         
            +
                  let(:model) { existing_model }
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
                  it 'can get.' do
         
     | 
| 
      
 84 
     | 
    
         
            +
                    expect(subject).not_to be_nil
         
     | 
| 
      
 85 
     | 
    
         
            +
                  end
         
     | 
| 
      
 86 
     | 
    
         
            +
                end
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
                context 'when deleted_model' do
         
     | 
| 
      
 89 
     | 
    
         
            +
                  let(:model) { deleted_model }
         
     | 
| 
      
 90 
     | 
    
         
            +
             
     | 
| 
      
 91 
     | 
    
         
            +
                  it 'can not get.' do
         
     | 
| 
      
 92 
     | 
    
         
            +
                    expect(subject).to be_nil
         
     | 
| 
      
 93 
     | 
    
         
            +
                  end
         
     | 
| 
      
 94 
     | 
    
         
            +
                end
         
     | 
| 
      
 95 
     | 
    
         
            +
              end
         
     | 
| 
      
 96 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,74 +1,93 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            describe Kakurenbo::MixinARBase do
         
     | 
| 
       4 
     | 
    
         
            -
               
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
                  expect(ActiveRecord::Base.methods).to include(:paranoid?)
         
     | 
| 
       12 
     | 
    
         
            -
                end
         
     | 
| 
      
 4 
     | 
    
         
            +
              describe ActiveRecord::Base do
         
     | 
| 
      
 5 
     | 
    
         
            +
                describe 'class_methods' do
         
     | 
| 
      
 6 
     | 
    
         
            +
                  subject { ActiveRecord::Base.methods }
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                  it 'has #paranoid?' do
         
     | 
| 
      
 9 
     | 
    
         
            +
                    expect(subject).to include(:paranoid?)
         
     | 
| 
      
 10 
     | 
    
         
            +
                  end
         
     | 
| 
       13 
11 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
      
 12 
     | 
    
         
            +
                  it 'has #acts_as_paranoid' do
         
     | 
| 
      
 13 
     | 
    
         
            +
                    expect(subject).to include(:acts_as_paranoid)
         
     | 
| 
      
 14 
     | 
    
         
            +
                  end
         
     | 
| 
       16 
15 
     | 
    
         
             
                end
         
     | 
| 
       17 
16 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
                 
     | 
| 
       19 
     | 
    
         
            -
                   
     | 
| 
      
 17 
     | 
    
         
            +
                describe 'instance_methods' do
         
     | 
| 
      
 18 
     | 
    
         
            +
                  subject { ActiveRecord::Base.instance_methods }
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                  it 'has #paranoid?' do
         
     | 
| 
      
 21 
     | 
    
         
            +
                    expect(subject).to include(:paranoid?)
         
     | 
| 
      
 22 
     | 
    
         
            +
                  end
         
     | 
| 
       20 
23 
     | 
    
         
             
                end
         
     | 
| 
       21 
24 
     | 
    
         
             
              end
         
     | 
| 
       22 
25 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
              describe 'class of HardDelete' do
         
     | 
| 
      
 28 
     | 
    
         
            +
                create_temp_table(:hard_deletes) {}
         
     | 
| 
      
 29 
     | 
    
         
            +
                subject { HardDelete }
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                it '#paranoid? return falsey.' do
         
     | 
| 
      
 32 
     | 
    
         
            +
                  expect(subject.paranoid?).to be_falsey
         
     | 
| 
       26 
33 
     | 
    
         
             
                end
         
     | 
| 
       27 
34 
     | 
    
         | 
| 
       28 
     | 
    
         
            -
                 
     | 
| 
       29 
     | 
    
         
            -
                   
     | 
| 
      
 35 
     | 
    
         
            +
                context 'when change SoftDelete into HardDelete' do
         
     | 
| 
      
 36 
     | 
    
         
            +
                  create_temp_table(:soft_deletes) {|t| t.datetime :deleted_at}
         
     | 
| 
      
 37 
     | 
    
         
            +
                  subject do
         
     | 
| 
      
 38 
     | 
    
         
            +
                    SoftDelete.tap do |c|
         
     | 
| 
      
 39 
     | 
    
         
            +
                      c.class_eval { self.table_name='hard_deletes' }
         
     | 
| 
      
 40 
     | 
    
         
            +
                    end
         
     | 
| 
      
 41 
     | 
    
         
            +
                  end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                  it '#paranoid? return falsey.' do
         
     | 
| 
      
 44 
     | 
    
         
            +
                    expect(subject.paranoid?).to be_falsey
         
     | 
| 
      
 45 
     | 
    
         
            +
                  end
         
     | 
| 
       30 
46 
     | 
    
         
             
                end
         
     | 
| 
       31 
47 
     | 
    
         
             
              end
         
     | 
| 
       32 
48 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
              context 'when define class of SoftDelete' do
         
     | 
| 
       34 
     | 
    
         
            -
                before :all do
         
     | 
| 
       35 
     | 
    
         
            -
                  class SoftDelete < ActiveRecord::Base; end
         
     | 
| 
       36 
     | 
    
         
            -
                end
         
     | 
| 
       37 
49 
     | 
    
         | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
      
 50 
     | 
    
         
            +
              describe 'class of SoftDelete' do
         
     | 
| 
      
 51 
     | 
    
         
            +
                create_temp_table(:soft_deletes) {|t| t.datetime :deleted_at}
         
     | 
| 
      
 52 
     | 
    
         
            +
                subject { SoftDelete }
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                it '#paranoid? return truthy.' do
         
     | 
| 
      
 55 
     | 
    
         
            +
                  expect(subject.paranoid?).to be_truthy
         
     | 
| 
       40 
56 
     | 
    
         
             
                end
         
     | 
| 
       41 
     | 
    
         
            -
              end
         
     | 
| 
       42 
57 
     | 
    
         | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
                   
     | 
| 
       46 
     | 
    
         
            -
                     
     | 
| 
      
 58 
     | 
    
         
            +
                context 'when set other column on kakurenbo_column' do
         
     | 
| 
      
 59 
     | 
    
         
            +
                  create_temp_table(:other_columns) {|t| t.datetime :destroyed_at}
         
     | 
| 
      
 60 
     | 
    
         
            +
                  subject do
         
     | 
| 
      
 61 
     | 
    
         
            +
                    OtherColumn.tap do |c|
         
     | 
| 
      
 62 
     | 
    
         
            +
                      c.class_eval { acts_as_paranoid :column => :destroyed_at }
         
     | 
| 
      
 63 
     | 
    
         
            +
                    end
         
     | 
| 
       47 
64 
     | 
    
         
             
                  end
         
     | 
| 
       48 
     | 
    
         
            -
                end
         
     | 
| 
       49 
65 
     | 
    
         | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
      
 66 
     | 
    
         
            +
                  it '#paranoid? return truthy.' do
         
     | 
| 
      
 67 
     | 
    
         
            +
                    expect(subject.paranoid?).to be_truthy
         
     | 
| 
      
 68 
     | 
    
         
            +
                  end
         
     | 
| 
       53 
69 
     | 
    
         | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
      
 70 
     | 
    
         
            +
                  it 'kakurenbo_column is `:destroyed_at`.' do
         
     | 
| 
      
 71 
     | 
    
         
            +
                    expect(subject.kakurenbo_column).to eq(:destroyed_at)
         
     | 
| 
      
 72 
     | 
    
         
            +
                  end
         
     | 
| 
       56 
73 
     | 
    
         
             
                end
         
     | 
| 
       57 
     | 
    
         
            -
              end
         
     | 
| 
       58 
74 
     | 
    
         | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
      
 75 
     | 
    
         
            +
                context 'when set other table_name on table_name.' do
         
     | 
| 
      
 76 
     | 
    
         
            +
                  before :all do
         
     | 
| 
      
 77 
     | 
    
         
            +
                    class HaiyoreNyarukoSan < ActiveRecord::Base
         
     | 
| 
      
 78 
     | 
    
         
            +
                      self.table_name='soft_deletes'
         
     | 
| 
      
 79 
     | 
    
         
            +
                    end
         
     | 
| 
       63 
80 
     | 
    
         
             
                  end
         
     | 
| 
       64 
     | 
    
         
            -
                end
         
     | 
| 
       65 
81 
     | 
    
         | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
                  expect(DiffTableName.table_name).to eq('other_table_name')
         
     | 
| 
       68 
     | 
    
         
            -
                end
         
     | 
| 
      
 82 
     | 
    
         
            +
                  subject { HaiyoreNyarukoSan }
         
     | 
| 
       69 
83 
     | 
    
         | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
      
 84 
     | 
    
         
            +
                  it '#table_name return soft_deletes' do
         
     | 
| 
      
 85 
     | 
    
         
            +
                    expect(subject.table_name).to eq('soft_deletes')
         
     | 
| 
      
 86 
     | 
    
         
            +
                  end
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
                  it '#paranoid? return truthy.' do
         
     | 
| 
      
 89 
     | 
    
         
            +
                    expect(subject.paranoid?).to be_truthy
         
     | 
| 
      
 90 
     | 
    
         
            +
                  end
         
     | 
| 
       72 
91 
     | 
    
         
             
                end
         
     | 
| 
       73 
92 
     | 
    
         
             
              end
         
     | 
| 
       74 
93 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,117 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe Kakurenbo::MixinARRelation do
         
     | 
| 
      
 4 
     | 
    
         
            +
              create_temp_table(:paranoid_models){ |t| t.datetime :deleted_at }
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              subject :subject_hard_delete do
         
     | 
| 
      
 7 
     | 
    
         
            +
                expect {
         
     | 
| 
      
 8 
     | 
    
         
            +
                  subject
         
     | 
| 
      
 9 
     | 
    
         
            +
                }.to change {
         
     | 
| 
      
 10 
     | 
    
         
            +
                  model_class.with_deleted.find_by(:id => model.id)
         
     | 
| 
      
 11 
     | 
    
         
            +
                }.to(nil)
         
     | 
| 
      
 12 
     | 
    
         
            +
              end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
              subject :subject_soft_delete do
         
     | 
| 
      
 15 
     | 
    
         
            +
                expect { subject }.to change { model.reload.destroyed? }.from(false).to(true)
         
     | 
| 
      
 16 
     | 
    
         
            +
              end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
              subject :subject_restore do
         
     | 
| 
      
 19 
     | 
    
         
            +
                expect { subject }.to change { model.reload.destroyed? }.from(true).to(false)
         
     | 
| 
      
 20 
     | 
    
         
            +
              end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
              let! :model do
         
     | 
| 
      
 23 
     | 
    
         
            +
                model_class.create!
         
     | 
| 
      
 24 
     | 
    
         
            +
              end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
              let :model_class do
         
     | 
| 
      
 27 
     | 
    
         
            +
                ParanoidModel
         
     | 
| 
      
 28 
     | 
    
         
            +
              end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
              describe '.delete' do
         
     | 
| 
      
 31 
     | 
    
         
            +
                subject { model_class.delete(model.id) }
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                it 'record will be soft-deleted.' do
         
     | 
| 
      
 34 
     | 
    
         
            +
                  subject_soft_delete
         
     | 
| 
      
 35 
     | 
    
         
            +
                end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                context 'when with hard-delete option' do
         
     | 
| 
      
 38 
     | 
    
         
            +
                  subject { model_class.delete(model.id, :hard => true) }
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                  it 'record will be hard-deleted.' do
         
     | 
| 
      
 41 
     | 
    
         
            +
                    subject_hard_delete
         
     | 
| 
      
 42 
     | 
    
         
            +
                  end
         
     | 
| 
      
 43 
     | 
    
         
            +
                end
         
     | 
| 
      
 44 
     | 
    
         
            +
              end
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
              describe '.delete_all' do
         
     | 
| 
      
 47 
     | 
    
         
            +
                subject { model_class.delete_all }
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                it 'record will be soft-deleted.' do
         
     | 
| 
      
 50 
     | 
    
         
            +
                  subject_soft_delete
         
     | 
| 
      
 51 
     | 
    
         
            +
                end
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                context 'when with hard-delete option' do
         
     | 
| 
      
 54 
     | 
    
         
            +
                  subject { model_class.delete_all(nil, :hard => true) }
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                  it 'record will be hard-deleted' do
         
     | 
| 
      
 57 
     | 
    
         
            +
                    subject_hard_delete
         
     | 
| 
      
 58 
     | 
    
         
            +
                  end
         
     | 
| 
      
 59 
     | 
    
         
            +
                end
         
     | 
| 
      
 60 
     | 
    
         
            +
              end
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
              describe '.destroy' do
         
     | 
| 
      
 63 
     | 
    
         
            +
                subject { model_class.destroy(model.id) }
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
                it 'record will be soft-deleted.' do
         
     | 
| 
      
 66 
     | 
    
         
            +
                  subject_soft_delete
         
     | 
| 
      
 67 
     | 
    
         
            +
                end
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                context 'when with hard-delete option' do
         
     | 
| 
      
 70 
     | 
    
         
            +
                  subject { model_class.destroy(model.id, :hard => true) }
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
                  it 'record will be hard-deleted.' do
         
     | 
| 
      
 73 
     | 
    
         
            +
                    subject_hard_delete
         
     | 
| 
      
 74 
     | 
    
         
            +
                  end
         
     | 
| 
      
 75 
     | 
    
         
            +
                end
         
     | 
| 
      
 76 
     | 
    
         
            +
              end
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
              describe '.destroy_all' do
         
     | 
| 
      
 79 
     | 
    
         
            +
                subject { model_class.destroy_all }
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
                it 'record will be soft-deleted.' do
         
     | 
| 
      
 82 
     | 
    
         
            +
                  subject_soft_delete
         
     | 
| 
      
 83 
     | 
    
         
            +
                end
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                context 'when with hard-delete option' do
         
     | 
| 
      
 86 
     | 
    
         
            +
                  subject { model_class.destroy_all(nil, :hard => true) }
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
                  it 'record will be hard-deleted' do
         
     | 
| 
      
 89 
     | 
    
         
            +
                    subject_hard_delete
         
     | 
| 
      
 90 
     | 
    
         
            +
                  end
         
     | 
| 
      
 91 
     | 
    
         
            +
                end
         
     | 
| 
      
 92 
     | 
    
         
            +
              end
         
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
      
 94 
     | 
    
         
            +
              describe '.restore' do
         
     | 
| 
      
 95 
     | 
    
         
            +
                before :each do
         
     | 
| 
      
 96 
     | 
    
         
            +
                  model.destroy
         
     | 
| 
      
 97 
     | 
    
         
            +
                end
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
                subject { model_class.restore(model.id) }
         
     | 
| 
      
 100 
     | 
    
         
            +
             
     | 
| 
      
 101 
     | 
    
         
            +
                it 'record will be restored.' do
         
     | 
| 
      
 102 
     | 
    
         
            +
                  subject_restore
         
     | 
| 
      
 103 
     | 
    
         
            +
                end
         
     | 
| 
      
 104 
     | 
    
         
            +
              end
         
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
      
 106 
     | 
    
         
            +
              describe '.restore_all' do
         
     | 
| 
      
 107 
     | 
    
         
            +
                before :each do
         
     | 
| 
      
 108 
     | 
    
         
            +
                  model.destroy
         
     | 
| 
      
 109 
     | 
    
         
            +
                end
         
     | 
| 
      
 110 
     | 
    
         
            +
             
     | 
| 
      
 111 
     | 
    
         
            +
                subject { model_class.restore_all }
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
                it 'record will be restored.' do
         
     | 
| 
      
 114 
     | 
    
         
            +
                  subject_restore
         
     | 
| 
      
 115 
     | 
    
         
            +
                end
         
     | 
| 
      
 116 
     | 
    
         
            +
              end
         
     | 
| 
      
 117 
     | 
    
         
            +
            end
         
     | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | 
         @@ -5,11 +5,13 @@ require "kakurenbo" 
     | 
|
| 
       5 
5 
     | 
    
         
             
            RSpec.configure do |config|
         
     | 
| 
       6 
6 
     | 
    
         
             
              config.mock_framework = :rspec
         
     | 
| 
       7 
7 
     | 
    
         
             
              config.before(:all) {
         
     | 
| 
       8 
     | 
    
         
            -
                 
     | 
| 
       9 
     | 
    
         
            -
                ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => 'tmp/rspec.sqlite')
         
     | 
| 
      
 8 
     | 
    
         
            +
                ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
         
     | 
| 
       10 
9 
     | 
    
         
             
              }
         
     | 
| 
       11 
10 
     | 
    
         
             
            end
         
     | 
| 
       12 
11 
     | 
    
         | 
| 
      
 12 
     | 
    
         
            +
            # Use ActiveSupport::Inflector#classify
         
     | 
| 
      
 13 
     | 
    
         
            +
            Inflector = Class.new.extend(ActiveSupport::Inflector)
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
       13 
15 
     | 
    
         
             
            # Create temp table for test.
         
     | 
| 
       14 
16 
     | 
    
         
             
            #
         
     | 
| 
       15 
17 
     | 
    
         
             
            # @param name   [Symbol]        Name of table.
         
     | 
| 
         @@ -17,15 +19,26 @@ end 
     | 
|
| 
       17 
19 
     | 
    
         
             
            def create_temp_table(name, &block)
         
     | 
| 
       18 
20 
     | 
    
         
             
              raise 'No block given!' unless block_given?
         
     | 
| 
       19 
21 
     | 
    
         | 
| 
      
 22 
     | 
    
         
            +
              class_name = Inflector.classify(name)
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
       20 
24 
     | 
    
         
             
              before :all do
         
     | 
| 
       21 
25 
     | 
    
         
             
                migration = ActiveRecord::Migration.new
         
     | 
| 
       22 
26 
     | 
    
         
             
                migration.verbose = false
         
     | 
| 
       23 
27 
     | 
    
         
             
                migration.create_table name, &block
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                mock_class = Class.new(ActiveRecord::Base) do
         
     | 
| 
      
 30 
     | 
    
         
            +
                  define_singleton_method(:name){ class_name }
         
     | 
| 
      
 31 
     | 
    
         
            +
                  reset_table_name
         
     | 
| 
      
 32 
     | 
    
         
            +
                end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                Object.const_set class_name, mock_class
         
     | 
| 
       24 
35 
     | 
    
         
             
              end
         
     | 
| 
       25 
36 
     | 
    
         | 
| 
       26 
37 
     | 
    
         
             
              after :all do
         
     | 
| 
       27 
38 
     | 
    
         
             
                migration = ActiveRecord::Migration.new
         
     | 
| 
       28 
39 
     | 
    
         
             
                migration.verbose = false
         
     | 
| 
       29 
40 
     | 
    
         
             
                migration.drop_table name
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                Object.class_eval { remove_const class_name }
         
     | 
| 
       30 
43 
     | 
    
         
             
              end
         
     | 
| 
       31 
44 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: kakurenbo
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - alfa-jpn
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2014- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2014-07-11 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     | 
| 
         @@ -44,14 +44,14 @@ dependencies: 
     | 
|
| 
       44 
44 
     | 
    
         
             
                requirements:
         
     | 
| 
       45 
45 
     | 
    
         
             
                - - ">="
         
     | 
| 
       46 
46 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       47 
     | 
    
         
            -
                    version:  
     | 
| 
      
 47 
     | 
    
         
            +
                    version: 3.0.0
         
     | 
| 
       48 
48 
     | 
    
         
             
              type: :development
         
     | 
| 
       49 
49 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       50 
50 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       51 
51 
     | 
    
         
             
                requirements:
         
     | 
| 
       52 
52 
     | 
    
         
             
                - - ">="
         
     | 
| 
       53 
53 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       54 
     | 
    
         
            -
                    version:  
     | 
| 
      
 54 
     | 
    
         
            +
                    version: 3.0.0
         
     | 
| 
       55 
55 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       56 
56 
     | 
    
         
             
              name: yard
         
     | 
| 
       57 
57 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
         @@ -86,14 +86,14 @@ dependencies: 
     | 
|
| 
       86 
86 
     | 
    
         
             
                requirements:
         
     | 
| 
       87 
87 
     | 
    
         
             
                - - ">="
         
     | 
| 
       88 
88 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       89 
     | 
    
         
            -
                    version:  
     | 
| 
      
 89 
     | 
    
         
            +
                    version: 4.0.2
         
     | 
| 
       90 
90 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       91 
91 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       92 
92 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       93 
93 
     | 
    
         
             
                requirements:
         
     | 
| 
       94 
94 
     | 
    
         
             
                - - ">="
         
     | 
| 
       95 
95 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       96 
     | 
    
         
            -
                    version:  
     | 
| 
      
 96 
     | 
    
         
            +
                    version: 4.0.2
         
     | 
| 
       97 
97 
     | 
    
         
             
            description: |2
         
     | 
| 
       98 
98 
     | 
    
         
             
                  provides soft delete.
         
     | 
| 
       99 
99 
     | 
    
         
             
                  Kakurenbo is a re-implementation of paranoia and acts_as_paranoid for Rails4 and 3.
         
     | 
| 
         @@ -115,14 +115,16 @@ files: 
     | 
|
| 
       115 
115 
     | 
    
         
             
            - Rakefile
         
     | 
| 
       116 
116 
     | 
    
         
             
            - kakurenbo.gemspec
         
     | 
| 
       117 
117 
     | 
    
         
             
            - lib/kakurenbo.rb
         
     | 
| 
      
 118 
     | 
    
         
            +
            - lib/kakurenbo/core.rb
         
     | 
| 
       118 
119 
     | 
    
         
             
            - lib/kakurenbo/mixin_ar_base.rb
         
     | 
| 
       119 
     | 
    
         
            -
            - lib/kakurenbo/ 
     | 
| 
      
 120 
     | 
    
         
            +
            - lib/kakurenbo/mixin_ar_relation.rb
         
     | 
| 
       120 
121 
     | 
    
         
             
            - lib/kakurenbo/version.rb
         
     | 
| 
      
 122 
     | 
    
         
            +
            - spec/kakurenbo/cores/associations_spec.rb
         
     | 
| 
      
 123 
     | 
    
         
            +
            - spec/kakurenbo/cores/callbacks_spec.rb
         
     | 
| 
      
 124 
     | 
    
         
            +
            - spec/kakurenbo/cores/core_spec.rb
         
     | 
| 
      
 125 
     | 
    
         
            +
            - spec/kakurenbo/cores/scopes_spec.rb
         
     | 
| 
       121 
126 
     | 
    
         
             
            - spec/kakurenbo/mixin_ar_base_spec.rb
         
     | 
| 
       122 
     | 
    
         
            -
            - spec/kakurenbo/ 
     | 
| 
       123 
     | 
    
         
            -
            - spec/kakurenbo/soft_delete_cores/callbacks_spec.rb
         
     | 
| 
       124 
     | 
    
         
            -
            - spec/kakurenbo/soft_delete_cores/core_spec.rb
         
     | 
| 
       125 
     | 
    
         
            -
            - spec/kakurenbo/soft_delete_cores/scopes_spec.rb
         
     | 
| 
      
 127 
     | 
    
         
            +
            - spec/kakurenbo/mixin_ar_relation_spec.rb
         
     | 
| 
       126 
128 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
       127 
129 
     | 
    
         
             
            homepage: https://github.com/alfa-jpn/kakurenbo
         
     | 
| 
       128 
130 
     | 
    
         
             
            licenses:
         
     | 
| 
         @@ -144,16 +146,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       144 
146 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       145 
147 
     | 
    
         
             
            requirements: []
         
     | 
| 
       146 
148 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       147 
     | 
    
         
            -
            rubygems_version: 2.2. 
     | 
| 
      
 149 
     | 
    
         
            +
            rubygems_version: 2.2.2
         
     | 
| 
       148 
150 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       149 
151 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       150 
152 
     | 
    
         
             
            summary: provides soft delete. Kakurenbo is a re-implementation of paranoia and acts_as_paranoid
         
     | 
| 
       151 
153 
     | 
    
         
             
              for Rails4 and 3. implemented a function that other gems are not enough.
         
     | 
| 
       152 
154 
     | 
    
         
             
            test_files:
         
     | 
| 
      
 155 
     | 
    
         
            +
            - spec/kakurenbo/cores/associations_spec.rb
         
     | 
| 
      
 156 
     | 
    
         
            +
            - spec/kakurenbo/cores/callbacks_spec.rb
         
     | 
| 
      
 157 
     | 
    
         
            +
            - spec/kakurenbo/cores/core_spec.rb
         
     | 
| 
      
 158 
     | 
    
         
            +
            - spec/kakurenbo/cores/scopes_spec.rb
         
     | 
| 
       153 
159 
     | 
    
         
             
            - spec/kakurenbo/mixin_ar_base_spec.rb
         
     | 
| 
       154 
     | 
    
         
            -
            - spec/kakurenbo/ 
     | 
| 
       155 
     | 
    
         
            -
            - spec/kakurenbo/soft_delete_cores/callbacks_spec.rb
         
     | 
| 
       156 
     | 
    
         
            -
            - spec/kakurenbo/soft_delete_cores/core_spec.rb
         
     | 
| 
       157 
     | 
    
         
            -
            - spec/kakurenbo/soft_delete_cores/scopes_spec.rb
         
     | 
| 
      
 160 
     | 
    
         
            +
            - spec/kakurenbo/mixin_ar_relation_spec.rb
         
     | 
| 
       158 
161 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
       159 
162 
     | 
    
         
             
            has_rdoc: 
         
     |