activable 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjEzNzhkOGE4NTU3ODVjMzY2ZDEyZTBkMzQ1ZmNiOTcxZjllYjhkMQ==
4
+ MzE4NzA2YzllOTRkODk0MzIwOTMwMmQ5ZDFlM2M5NGVmNDczMDUzNA==
5
5
  data.tar.gz: !binary |-
6
- NjE2NDRhODIyODRiYjRmNDcwMzljYjQxZjg3NGI3ZjEyNDQ1ZjAzMA==
6
+ M2EyMTQ0M2E4NjRiYzdkOGJjYmU1NGVhZWU3MDVjNTgzOTBhZWNjYg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NDI2NmIzNDMwZTU4YzIwYzE3ZmRjMGFmMGIzYWRlZTFlMTdjNGFkNDQ5OTRl
10
- MDcyM2FlZmQ1YWM2NjA5ODZiY2MxZGIxM2VjZGNiNjNhMjk0N2JhNzg1Y2Zi
11
- OTZlZjU4MDhmZjZmNTBiM2YyNTIzOTQ1OTNhYjk3YmE2YmIyNzM=
9
+ MzQyZGU4MjVhNzU1NDYwOTMyNTkxODNmNjdmNjdjY2RjZGZiYjQ0MzA0MTMy
10
+ YWE4NjZhODAyODc2MGVmMzlhZDgzNzI5OGE3NzI0NTEwYjMzNWRlNzViZWI1
11
+ ZTUwY2QyZTkxNWY3YmU2NzJmNmQ1NmM4YjExNDU0ZjVlZGVjY2E=
12
12
  data.tar.gz: !binary |-
13
- N2VjZmExMjgxNWJlOTg1NDQxMjZmNWQwZWMwZjI0ZTBjMjdkMDk2ZGQyOTUy
14
- YTU5ZDE5ZDZiNzEwYTdiYTliYjVmOTNhNDJjNTkzOTQ0NGYyYTY3MDE1ZDBi
15
- YzBiYTE1ZTlkZjQ0ZTk1ZTY3ZDQ4ZDdkYTBhODFmNmY1NzYxYzc=
13
+ ZmYxMTU5Yzk4YzE2NzMwNTI2NmU0Y2U4M2QwMjUxYWQwNzcwY2Y0Y2JmMzQ2
14
+ MzA1ODdkNDU5OTc2NTY5NWE0NzAxYTZkYjQxNWJhNTg4MDZkY2U2MzA2OTg4
15
+ MGEwZGVkODM4NjNiM2YxNGQwZTIyYzNiNTE3NmFjZjBiMjNmNjk=
@@ -0,0 +1,7 @@
1
+ ## 0.1.0
2
+
3
+ * First working version
4
+
5
+ ## 0.1.1
6
+
7
+ * Added two scopes: 'active' and 'inactive'.
data/README.md CHANGED
@@ -36,8 +36,7 @@ class Product < ActiveRecord::Base
36
36
  end
37
37
  ```
38
38
 
39
- Optionally, you can customize each model to have a differente configuration from
40
- the on in the initializer file:
39
+ Optionally, you can customize Activable configuration for each model:
41
40
 
42
41
  ```ruby
43
42
  class Product < ActiveRecord::Base
@@ -53,14 +52,14 @@ end
53
52
 
54
53
  ### Working with it
55
54
 
56
- By default, new objects of a "activable" model are active:
55
+ By default, new objects of an "activable" model are active:
57
56
 
58
57
  ```ruby
59
58
  p = Product.new
60
59
  p.active? # => true
61
60
  ```
62
61
 
63
- If your model has a responsible, you **must** provide it before saving your object:
62
+ If your record has a responsible, you **must** provide it before saving your object:
64
63
 
65
64
  ```ruby
66
65
  p = Product.new
@@ -71,22 +70,29 @@ p = Product.new
71
70
  p.activate responsible: current_user
72
71
  ```
73
72
 
74
- The same rule applies when deactivating an object:
73
+ The same rule applies when deactivating:
75
74
 
76
75
  ```ruby
77
76
  product.deactivate responsible: current_user
78
77
  ```
79
78
 
80
79
  You can check whether it is active or not whenever you want by calling the method
81
- `active?`. Another useful informations are stored and you can see them:
80
+ `active?`. Another useful informations are persisted and you can see them:
82
81
 
83
82
  ```ruby
84
83
  product.activated_at
85
84
  product.deactivated_at
86
85
 
87
86
  # And if it has a responsible:
88
- product.activated_by # if has responsible
89
- product.deactivated_by # if has responsible
87
+ product.activated_by
88
+ product.deactivated_by
89
+ ```
90
+
91
+ Also, this gem creates two useful scopes:
92
+
93
+ ```ruby
94
+ Product.active
95
+ Product.inactive
90
96
  ```
91
97
 
92
98
  ## Testing the gem
@@ -23,7 +23,7 @@ module Activable
23
23
 
24
24
  def active?
25
25
  return true unless self.activated_at && self.deactivated_at
26
- self.activated_at > self.deactivated_at
26
+ self.activated_at >= self.deactivated_at
27
27
  end
28
28
 
29
29
  def activate(options={})
@@ -51,6 +51,10 @@ module Activable
51
51
  included do
52
52
  after_initialize :init_active
53
53
  validates_presence_of :activated_at
54
+ scope :active, where('deactivated_at is null or activated_at is null or' +
55
+ ' activated_at >= deactivated_at')
56
+ scope :inactive, where('deactivated_at is not null and activated_at is not' +
57
+ ' null and activated_at < deactivated_at')
54
58
  if self.activable_config[:has_responsible]
55
59
  belongs_to :activated_by, :class_name => self.activable_config[:responsible]
56
60
  belongs_to :deactivated_by, :class_name => self.activable_config[:responsible]
@@ -1,3 +1,3 @@
1
1
  module Activable
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -18,24 +18,26 @@ describe Category do
18
18
  it 'can be activated with no responsible' do
19
19
  c = FactoryGirl.build(:category)
20
20
 
21
- c.activate
22
- c.save.should be_true, "Activated category with no responsible should be saved. " +
21
+ c.activate!.should be_true, "Activated category with no responsible should be saved. " +
23
22
  c.errors.full_messages.to_s
24
23
  c.active?.should be_true
25
24
  c.activated_by_id.should be_nil
26
25
  c.activated_at.should_not be_nil
27
26
  c.deactivated_by_id.should be_nil
28
27
  c.deactivated_at.should be_nil
28
+ Category.active.include?(c).should be_true
29
+ Category.inactive.include?(c).should_not be_true
29
30
  end
30
31
 
31
32
  it 'can be deactivated with no responsible' do
32
33
  c = FactoryGirl.build(:category)
33
34
 
34
- c.deactivate
35
- c.save.should be_true, "Deactivated category with no responsible should be saved. " +
35
+ c.deactivate!.should be_true, "Deactivated category with no responsible should be saved. " +
36
36
  c.errors.full_messages.to_s
37
37
  c.active?.should_not be_true
38
38
  c.deactivated_by_id.should be_nil
39
39
  c.deactivated_at.should_not be_nil
40
+ Category.active.include?(c).should_not be_true
41
+ Category.inactive.include?(c).should be_true
40
42
  end
41
43
  end
@@ -36,6 +36,8 @@ describe User do
36
36
  u.activated_at.should_not be_nil
37
37
  u.deactivated_by.should be_nil
38
38
  u.deactivated_at.should be_nil
39
+ User.active.include?(u).should be_true
40
+ User.inactive.include?(u).should_not be_true
39
41
  end
40
42
 
41
43
  it 'can be deactivated' do
@@ -50,5 +52,7 @@ describe User do
50
52
  u.active?.should_not be_true
51
53
  u.deactivated_by.should be_equal another_user
52
54
  u.deactivated_at.should_not be_nil
55
+ User.active.include?(u).should_not be_true
56
+ User.inactive.include?(u).should be_true
53
57
  end
54
58
  end
@@ -1,2 +1,2 @@
1
1
  db/*.sqlite3
2
- log/
2
+ /log/*
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diego Selzlein
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-04 00:00:00.000000000 Z
11
+ date: 2013-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -32,6 +32,7 @@ extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
34
  - .gitignore
35
+ - CHANGELOG.md
35
36
  - Gemfile
36
37
  - LICENSE.txt
37
38
  - README.md
@@ -86,9 +87,6 @@ files:
86
87
  - spec/test_app/db/seeds.rb
87
88
  - spec/test_app/lib/assets/.gitkeep
88
89
  - spec/test_app/lib/tasks/.gitkeep
89
- - spec/test_app/log/.gitkeep
90
- - spec/test_app/log/development.log
91
- - spec/test_app/log/test.log
92
90
  - spec/test_app/public/404.html
93
91
  - spec/test_app/public/422.html
94
92
  - spec/test_app/public/500.html
@@ -163,9 +161,6 @@ test_files:
163
161
  - spec/test_app/db/seeds.rb
164
162
  - spec/test_app/lib/assets/.gitkeep
165
163
  - spec/test_app/lib/tasks/.gitkeep
166
- - spec/test_app/log/.gitkeep
167
- - spec/test_app/log/development.log
168
- - spec/test_app/log/test.log
169
164
  - spec/test_app/public/404.html
170
165
  - spec/test_app/public/422.html
171
166
  - spec/test_app/public/500.html