archivable 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a581532e3571dad19eb5bb88dc17e41172a7fff
4
- data.tar.gz: 355cd234b2a7fdb59f66efa7b16f23287b3259fa
3
+ metadata.gz: eac1946fb18e1f499eb2dc2dfb11c5c93a7e6ce3
4
+ data.tar.gz: aacbc41a2e6eb4b3550823f2b997442db7000b60
5
5
  SHA512:
6
- metadata.gz: 13f5da9d6cb18338324e2980b97791ac3052e16a127da3604c82226a0f1ff2c7997fb5098729019ee14e57e73602972bf486fb62e989ba3d41d4b841b9c471e4
7
- data.tar.gz: bf2b3328d0877ea513a0360f9c673f16a34f0a435a2db668037ff5eca30ee07094e28778868b8861a620bf010956102731a3ccbb65d53913300dc8de5b64abe8
6
+ metadata.gz: 72cecb92c850fbeac422cdfc54594b4c7e744e6852f73bf6ba2977611e209bab5dfd4f1d88ea0c1c9970f09e7d1342048d4184cc588ec04a4983ee9e418d8769
7
+ data.tar.gz: d9ba31b75168145f46b92daa721e6ca16d6790f145009eed2577aa5d007a19a43a75435f240574215e6d81b9a885c9ba2dce583c18622b9f915b20d7e858b791
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format=documentation
@@ -1,10 +1,11 @@
1
+ sudo: false
1
2
  language: ruby
2
- rvm:
3
- - 1.9
4
- - 2.0
5
- - 2.1
6
- - 2.2
7
3
 
8
- notifications:
9
- email:
10
- - johnotander@gmail.com
4
+ before_install:
5
+ - gem install bundler
6
+
7
+ rvm:
8
+ - '1.9'
9
+ - '2.0'
10
+ - '2.1'
11
+ - '2.2'
data/README.md CHANGED
@@ -1,10 +1,8 @@
1
- # Archivable
2
-
3
- [![Build Status](https://travis-ci.org/johnotander/archivable.svg?branch=master)](https://travis-ci.org/johnotander/archivable)
1
+ # archivable [![Build Status](https://travis-ci.org/johnotander/archivable.svg?branch=master)](https://travis-ci.org/johnotander/archivable)
4
2
 
5
3
  Archive your Rails models rather than delete them. This provides the archiving functionality app so you can do the following:
6
4
 
7
- ##### In your models:
5
+ ##### In your models
8
6
 
9
7
  ```ruby
10
8
  user.archived? #=> false
@@ -12,15 +10,9 @@ user.archive! #=> true
12
10
  user.archived? #=> true
13
11
  user.unarchive! #=> true
14
12
  user.archived? #=> false
15
-
16
- # With scopes available:
17
- User.archived
18
- User.unarchived
19
13
  ```
20
14
 
21
- ##### In your views:
22
-
23
- _This would typically be added to a view helper._
15
+ ##### In your views
24
16
 
25
17
  ```html+erb
26
18
  <% if user.archived? %>
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
2
  require 'rspec/core/rake_task'
3
3
 
4
- RSpec::Core::RakeTask.new
4
+ RSpec::Core::RakeTask.new(:spec)
5
5
 
6
6
  task default: :spec
7
7
  task test: :spec
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["johnotander@gmail.com"]
11
11
  spec.summary = %q{Archive your Rails models rather than delete them.}
12
12
  spec.description = %q{Archive your Rails models rather than delete them, with model and controller concerns.}
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/johnotander/archivable"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -19,10 +19,12 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency 'activesupport'
22
+ spec.add_dependency 'activerecord'
22
23
  spec.add_dependency 'meta_magic'
23
24
 
24
- spec.add_development_dependency 'bundler', '~> 1.5'
25
+ spec.add_development_dependency 'bundler', '~> 1.11'
25
26
  spec.add_development_dependency 'rake'
26
27
  spec.add_development_dependency 'rspec'
27
28
  spec.add_development_dependency 'actionpack'
29
+ spec.add_development_dependency 'sqlite3'
28
30
  end
@@ -1,17 +1,13 @@
1
1
  require 'active_support/concern'
2
+ require 'active_record'
2
3
 
3
4
  module Archivable
4
5
  module Model
5
6
  extend ActiveSupport::Concern
6
7
 
7
- module ClassMethods
8
- def archived
9
- scoped(conditions: { archived: true })
10
- end
11
-
12
- def unarchived
13
- scoped(conditions: { archived: false })
14
- end
8
+ included do
9
+ scope :archived, -> { where(archived: true) }
10
+ scope :unarchived, -> { where(archived: false) }
15
11
  end
16
12
 
17
13
  def archived?
@@ -1,3 +1,3 @@
1
1
  module Archivable
2
- VERSION = '1.3.1'
2
+ VERSION = '1.4.0'
3
3
  end
@@ -6,18 +6,18 @@ describe Archivable::Controller do
6
6
 
7
7
  subject { controller }
8
8
 
9
- it { should respond_to(:archive) }
9
+ it { is_expected.to respond_to(:archive) }
10
10
 
11
- describe '.archive' do
11
+ describe '#archive' do
12
12
 
13
- it 'should set the instance variable' do
13
+ it 'sets the instance variable' do
14
14
  subject.archive
15
15
  expect(subject.get_model_instance_variable).to eq(subject.fake)
16
16
  end
17
17
 
18
18
  context 'when successfully archived' do
19
19
 
20
- it 'should render the :show action' do
20
+ it 'renders the :show action' do
21
21
  expect(subject).to receive(:redirect_to).with(action: :show)
22
22
  subject.archive
23
23
  end
@@ -25,7 +25,7 @@ describe Archivable::Controller do
25
25
 
26
26
  context 'when unsuccessfully archived' do
27
27
 
28
- it 'should render the :show action' do
28
+ it 'renders the :show action' do
29
29
  allow_any_instance_of(Fake).to receive(:save).and_return(false)
30
30
  expect(subject).to receive(:render).with(:edit)
31
31
  subject.archive
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe Archivable::Model do
4
+
5
+ let(:model) { Fake.new }
6
+
7
+ subject { model }
8
+
9
+ it { is_expected.to respond_to(:archive!) }
10
+ it { is_expected.to respond_to(:unarchive!) }
11
+ it { is_expected.to respond_to(:is_archivable?) }
12
+
13
+ describe '#archive!' do
14
+
15
+ before { subject.archive! }
16
+
17
+ it 'sets archived to true' do
18
+ expect(model.archived?).to be_truthy
19
+ end
20
+
21
+ it 'saves' do
22
+ expect(subject).to receive(:save)
23
+ subject.archive!
24
+ end
25
+ end
26
+
27
+ describe '#unarchive!' do
28
+ let(:model) { Fake.new(archived: true) }
29
+
30
+ before { model.unarchive! }
31
+
32
+ it 'sets archived to false' do
33
+ expect(model.archived?).to be_falsey
34
+ end
35
+
36
+ it 'saves' do
37
+ expect(subject).to receive(:save)
38
+ subject.archive!
39
+ end
40
+ end
41
+
42
+ describe '.archived' do
43
+ let!(:archived_fake) { Fake.create(archived: true) }
44
+ let!(:unarchived_fake) { Fake.create(archived: false) }
45
+ it 'returns the archived object' do
46
+ expect(Fake.archived).to include(archived_fake)
47
+ end
48
+ it 'does not return the unarchievd object' do
49
+ expect(Fake.archived).to_not include(unarchived_fake)
50
+ end
51
+ end
52
+
53
+ describe '.unarchived' do
54
+ let!(:archived_fake) { Fake.create(archived: true) }
55
+ let!(:unarchived_fake) { Fake.create(archived: false) }
56
+ it 'does not return the archived object' do
57
+ expect(Fake.unarchived).to_not include(archived_fake)
58
+ end
59
+ it 'returns the unarchievd object' do
60
+ expect(Fake.unarchived).to include(unarchived_fake)
61
+ end
62
+ end
63
+ end
@@ -3,18 +3,30 @@ require 'bundler/setup'
3
3
  require 'rspec'
4
4
 
5
5
  require 'action_controller'
6
+ require 'active_record'
6
7
 
7
8
  require 'archivable'
8
9
 
9
- class Fake
10
- attr_accessor :archived
10
+ ActiveRecord::Base.establish_connection(adapter: 'sqlite3',
11
+ database: ':memory:')
12
+
13
+ ActiveRecord::Schema.define do
14
+ self.verbose = false
15
+
16
+ create_table :fakes, cascade: true do |t|
17
+ t.boolean :archived
18
+ end
19
+ end
20
+
21
+ class Fake < ActiveRecord::Base
22
+ include Archivable::Model
11
23
 
12
24
  def toggle(dont_care)
13
25
  self.archived = archived ? false : true
14
26
  end
15
27
 
16
- def save
17
- true
28
+ def archived?
29
+ !!archived
18
30
  end
19
31
  end
20
32
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: archivable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Otander
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-17 00:00:00.000000000 Z
11
+ date: 2016-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activerecord
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: meta_magic
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +58,14 @@ dependencies:
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '1.5'
61
+ version: '1.11'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '1.5'
68
+ version: '1.11'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +108,20 @@ dependencies:
94
108
  - - ">="
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: sqlite3
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
97
125
  description: Archive your Rails models rather than delete them, with model and controller
98
126
  concerns.
99
127
  email:
@@ -103,6 +131,7 @@ extensions: []
103
131
  extra_rdoc_files: []
104
132
  files:
105
133
  - ".gitignore"
134
+ - ".rspec"
106
135
  - ".travis.yml"
107
136
  - Gemfile
108
137
  - LICENSE.txt
@@ -116,7 +145,7 @@ files:
116
145
  - spec/archivable_controller_spec.rb
117
146
  - spec/archivable_model_spec.rb
118
147
  - spec/spec_helper.rb
119
- homepage: ''
148
+ homepage: https://github.com/johnotander/archivable
120
149
  licenses:
121
150
  - MIT
122
151
  metadata: {}
@@ -136,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
165
  version: '0'
137
166
  requirements: []
138
167
  rubyforge_project:
139
- rubygems_version: 2.4.3
168
+ rubygems_version: 2.5.1
140
169
  signing_key:
141
170
  specification_version: 4
142
171
  summary: Archive your Rails models rather than delete them.
@@ -144,4 +173,3 @@ test_files:
144
173
  - spec/archivable_controller_spec.rb
145
174
  - spec/archivable_model_spec.rb
146
175
  - spec/spec_helper.rb
147
- has_rdoc: