status-manager 0.8.5 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 395030fa5ab54f040bca94d41057376e3ab925f7
4
- data.tar.gz: 01c3b7bfd0341680a6ae21d383dc84e680ffcfac
3
+ metadata.gz: b73bfd02d46f00498307b2e35508a4e416728510
4
+ data.tar.gz: 73b66a06ce8eb75b1b0b7d4405864c2fc0164eef
5
5
  SHA512:
6
- metadata.gz: b1bdef37a2ea4b70c887926e2aa709ae969575836c57a816ac9a119a0d9bd3acb0d97f8c2d6dd52875aad7880c82ec066daad36a99ed5610156f14029c3aad88
7
- data.tar.gz: 53d592551c7d446b1d71a4a84b54389ad627fabfaa6bca75029badccf0638d5c416b3b15bd25c8c959c99086b032fd925906f7552817967ee82ece5e153b67a5
6
+ metadata.gz: de7eaad75cbd9615c883b28aa73611d8505f3447f7910bac68c03b18b6bf1fcb67dfe9583e4fefa8aaae2ade03f80ebca1be8b93c766147c1634b38e18be4a9b
7
+ data.tar.gz: 34e5ffa18d4771cc954f57ec4fa970e79bc4c9588be8325082b61269a791c234998c816c10d54db730cc35049164e0f20fd885f36937cdbb8097152a3177fb25
data/.gitignore CHANGED
@@ -16,4 +16,5 @@ spec/reports
16
16
  test/tmp
17
17
  test/version_tmp
18
18
  tmp
19
- coverage
19
+ coverage
20
+ status_manager_test.sqlite3
data/Gemfile CHANGED
@@ -1,6 +1,8 @@
1
- source "http://rubygems.org"
1
+ source 'http://rubygems.org'
2
2
  gemspec
3
3
 
4
- gem "rake"
5
- gem "simplecov", :require => false, :group => :test
6
-
4
+ gem 'rake'
5
+ gem 'simplecov', require: false, group: :test
6
+ gem 'sqlite3'
7
+ gem 'rails', '4.0.0'
8
+ gem 'rspec'
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  ## Description
2
+ [![Gem Version](https://badge.fury.io/rb/status-manager.svg)](http://badge.fury.io/rb/status-manager)
3
+
2
4
  ActiveRecord Model Status Manager, It provides easy ways managing models that have many statuses.
3
5
 
4
6
  www.myrealtrip.com uses status-manager
@@ -14,6 +16,25 @@ gem 'status-manager'
14
16
  ### Example
15
17
 
16
18
  #### Define
19
+
20
+ ```ruby
21
+ class Product < ActiveRecord::Base
22
+ attr_accessible :title, :sale_status
23
+
24
+ attr_as_status :sale_status,
25
+ [:onsale, :reject, :pending, :soldout],
26
+ :default => :pending,
27
+ :group => {
28
+ :close => [:reject, :pending],
29
+ :open => [:onsale, :soldout]
30
+ }
31
+ # 1. :default and :group are optional
32
+ # 2. :group element :close and :open work as status
33
+ # 3. If you want to specify status value that save in database, use Hash instead of Array.
34
+ # ex) {:onsale => "ONSALE", :pending => "PENDING" ...} or {:onsale => 1, :pending => 2 ...}
35
+ end
36
+ ```
37
+ or
17
38
  ```ruby
18
39
  class Product < ActiveRecord::Base
19
40
  attr_accessible :title, :sale_status
@@ -78,8 +99,14 @@ class Product < ActiveRecord::Base
78
99
  attr_accessible :title, :sale_status
79
100
 
80
101
  # attr_as_status :status_attribute in model, {:status_value => 'status_value that is saved in database'}
81
- attr_as_status :sale_status, :onsale => 'onsale', :reject => 'reject', :pending => 'pending', :soldout => 'soldout'
82
- status_group :sale_status, :close => [:reject, :pending], :open => [:onsale, :soldout]
102
+ attr_as_status :sale_status,
103
+ [:onsale, :reject, :pending, :soldout],
104
+ :default => :pending
105
+ :group => {
106
+ close: [:reject, :pending],
107
+ open: [:onsale, :soldout]
108
+ }
109
+
83
110
 
84
111
  #callback update status from specific status
85
112
  before_status_update :sale_status, :onsale => :close do |product|
data/Rakefile CHANGED
@@ -4,10 +4,10 @@ require 'rake/testtask'
4
4
  require 'rspec/core/rake_task'
5
5
  Bundler::GemHelper.install_tasks
6
6
 
7
- desc "Default: run unit tests."
8
- task :default => :spec
7
+ desc 'Default: run unit tests.'
8
+ task default: :spec
9
9
 
10
- desc "Run Status Manager RSpec"
10
+ desc 'Run Status Manager RSpec'
11
11
  RSpec::Core::RakeTask.new do |t|
12
12
  t.verbose = false
13
13
  end
@@ -4,123 +4,128 @@ require 'status-manager/status_validation'
4
4
  require 'status-manager/status_store'
5
5
  require 'active_support/inflector'
6
6
 
7
+ # Base Module
7
8
  module StatusManager
8
-
9
- def self.included(base)
10
- base.extend ClassMethods
11
- base.extend StatusManager::StatusGroupManager
12
- base.extend StatusManager::StatusUpdateCallback
13
- base.extend StatusManager::StatusValidation
14
- end
15
-
16
- module ClassMethods
17
- def attr_as_status(status_attribute, status_sets, options={})
18
- register_status_sets(status_attribute, status_sets)
19
- status_group(status_attribute, options[:group]) if options.key?(:group)
20
- set_default_status(status_attribute, options[:default]) if options.key?(:default)
21
- end
22
-
23
- def register_status_sets(status_attribute, status_sets, default_status=nil)
24
- # if status_sets parameter is array.
25
- # ex) register_status_sets(status, [:onsale, :soldout, :reject])
26
- raise "Not defined statuses" if status_sets.empty?
27
- if status_sets.instance_of?(Array)
28
- raise Exception, "#{status_attribute} column type must be :string or :text in this case, if you want to specify column value use Hash class" unless [:string, :text].include?(self.columns_hash[status_attribute.to_s].type)
29
- _status_sets = {}
30
- status_sets.each { |status_set| _status_sets[status_set] = status_set.to_s }
31
- status_sets = _status_sets
32
- end
33
-
34
- status_store = StatusStore.new(status_attribute, status_sets)
35
- status_store_list.add(status_store)
36
-
37
- scope "#{status_store.attribute_name}", lambda{ | statuses | where("#{self.table_name}.#{status_store.attribute_name.to_s}" => status_store.values(statuses)) }
38
-
39
- status_store.status_sets.each do |key, value|
40
- #active_record scope setting
41
- scope "#{status_store.attribute_name}_#{key}", where("#{self.table_name}.#{status_store.attribute_name}" => value)
42
-
43
- #status check method
44
- define_method "#{status_store.attribute_name}_#{key}?" do
45
- self.send("#{status_store.attribute_name}") == value
46
- end
47
-
48
- define_method "#{status_store.attribute_name}_was_#{key}?" do
49
- self.send("#{status_store.attribute_name}_was") == value
50
- end
51
-
52
- #update status
53
- define_method "update_#{status_store.attribute_name}_to_#{key}" do
54
- self.update_attributes("#{status_store.attribute_name}" => "#{value}")
55
- end
56
-
57
- define_method "#{status_store.attribute_name}_to_#{key}" do
58
- self.send("#{status_store.attribute_name}=", value)
59
- end
60
- end
61
-
62
- #status check method
63
- define_method "#{status_store.attribute_name}?" do |status|
64
- self.send("#{status_store.attribute_name}_#{status}?")
65
- end
66
-
67
- define_method "#{status_store.attribute_name}_was?" do |status|
68
- self.send("#{status_store.attribute_name}_was_#{status}?")
69
- end
70
-
71
- #status setter (do not override attr_accessible)
72
- define_method "#{status_store.attribute_name}_to" do |status|
73
- raise "#{status} is undefined status or it is group status" unless status_store.status?(status)
74
- status_value = self.class.status_store_list.get(status_store.attribute_name).value(status)
75
- self.send("#{status_store.attribute_name}=", status_value)
76
- end
77
-
78
- # update status
79
- define_method "update_#{status_store.attribute_name}_to" do |status|
80
- raise "#{status} is undefined status or it is group status" unless status_store.status?(status)
81
- self.update_attributes(status_attribute.to_sym => self.class.status_store_list.get(status_store.attribute_name).value(status))
82
- end
83
-
84
- define_method("#{status_store.attribute_name}_changed?") do |options={}|
85
- statuses = self.send("#{status_store.attribute_name}_change")
86
- if statuses
87
- if statuses[0] == statuses[1]
88
- return false
89
- elsif options[:from] && options[:to]
90
- self.send("#{status_store.attribute_name}_was?", options[:from]) && self.send("#{status_store.attribute_name}?", options[:to])
91
- elsif options[:to]
92
- self.send("#{status_store.attribute_name}?", options[:to])
93
- elsif options[:from]
94
- self.send("#{status_store.attribute_name}_was?", options[:from])
95
- else
96
- return true
97
- end
98
- else
99
- return false
100
- end
101
- end
102
-
103
- #get status list
104
- define_singleton_method "#{status_store.attribute_name.to_s.pluralize}" do
105
- self.status_store_list.get(status_store.attribute_name).status_sets
106
- end
107
- end
108
-
109
- def set_default_status(status_attribute, status)
110
- before_create do |obj|
111
- obj.send("#{status_attribute.to_s}=", obj.class.send(status_attribute.to_s.pluralize)[status]) unless obj.send(status_attribute.to_s)
112
- end
113
- end
114
-
115
- def status_store_list
116
- if self.class_variable_defined?(:@@status_store_list)
117
- self.class_variable_get(:@@status_store_list)
118
- else
119
- self.class_variable_set(:@@status_store_list, StatusStoreList.new)
120
- end
121
- end
122
-
123
- end
9
+ def self.included(base)
10
+ base.extend ClassMethods
11
+ base.extend StatusManager::StatusGroupManager
12
+ base.extend StatusManager::StatusUpdateCallback
13
+ base.extend StatusManager::StatusValidation
14
+ end
15
+
16
+ # Class Methods
17
+ module ClassMethods
18
+ # assign attributes as status
19
+ def attr_as_status(status_attribute, status_sets, options = {})
20
+ register_status_sets(status_attribute, status_sets)
21
+ status_group(status_attribute, options[:group]) if options.key?(:group)
22
+ set_default_status(status_attribute, options[:default]) if options.key?(:default)
23
+ end
24
+
25
+ def register_status_sets(status_attribute, status_sets)
26
+ # if status_sets parameter is array.
27
+ # ex) register_status_sets(status, [:onsale, :soldout, :reject])
28
+ fail 'Not defined statuses' if status_sets.empty?
29
+
30
+ if status_sets.instance_of?(Array)
31
+ status_hash = {}
32
+ status_sets.each do |status_set|
33
+ status_hash[status_set] = status_set.to_s
34
+ end
35
+ status_sets = status_hash
36
+ end
37
+
38
+ status_store = StatusStore.new(status_attribute, status_sets)
39
+ status_store_list.add(status_store)
40
+
41
+ scope("#{status_store.attribute_name}",
42
+ -> (statuses) { where("#{table_name}.#{status_store.attribute_name}" => status_store.values(statuses)) })
43
+
44
+ status_store.status_sets.each do |key, value|
45
+ # active_record scope setting
46
+ scope("#{status_store.attribute_name}_#{key}",
47
+ -> { where("#{table_name}.#{status_store.attribute_name}" => value) })
48
+
49
+ # status check method
50
+ define_method "#{status_store.attribute_name}_#{key}?" do
51
+ send("#{status_store.attribute_name}") == value
52
+ end
53
+
54
+ define_method "#{status_store.attribute_name}_was_#{key}?" do
55
+ send("#{status_store.attribute_name}_was") == value
56
+ end
57
+
58
+ # update status
59
+ define_method "update_#{status_store.attribute_name}_to_#{key}" do
60
+ update_attributes("#{status_store.attribute_name}" => "#{value}")
61
+ end
62
+
63
+ define_method "#{status_store.attribute_name}_to_#{key}" do
64
+ send("#{status_store.attribute_name}=", value)
65
+ end
66
+ end
67
+
68
+ # status check method
69
+ define_method "#{status_store.attribute_name}?" do |status|
70
+ send("#{status_store.attribute_name}_#{status}?")
71
+ end
72
+
73
+ define_method "#{status_store.attribute_name}_was?" do |status|
74
+ send("#{status_store.attribute_name}_was_#{status}?")
75
+ end
76
+
77
+ # status setter (do not override attr_accessible)
78
+ define_method "#{status_store.attribute_name}_to" do |status|
79
+ fail "#{status} is undefined status or it is group status" unless status_store.status?(status)
80
+ status_value = self.class.status_store_list.get(status_store.attribute_name).value(status)
81
+ send("#{status_store.attribute_name}=", status_value)
82
+ end
83
+
84
+ # update status
85
+ define_method "update_#{status_store.attribute_name}_to" do |status|
86
+ fail "#{status} is undefined status or it is group status" unless status_store.status?(status)
87
+ update_attributes(status_attribute.to_sym => self.class.status_store_list.get(status_store.attribute_name).value(status))
88
+ end
89
+
90
+ define_method("#{status_store.attribute_name}_changed?") do |options = {}|
91
+ statuses = send("#{status_store.attribute_name}_change")
92
+ if statuses
93
+ if statuses[0] == statuses[1]
94
+ return false
95
+ elsif options[:from] && options[:to]
96
+ send("#{status_store.attribute_name}_was?", options[:from]) && send("#{status_store.attribute_name}?", options[:to])
97
+ elsif options[:to]
98
+ send("#{status_store.attribute_name}?", options[:to])
99
+ elsif options[:from]
100
+ send("#{status_store.attribute_name}_was?", options[:from])
101
+ else
102
+ return true
103
+ end
104
+ else
105
+ return false
106
+ end
107
+ end
108
+
109
+ # get status list
110
+ define_singleton_method "#{status_store.attribute_name.to_s.pluralize}" do
111
+ status_store_list.get(status_store.attribute_name).status_sets
112
+ end
113
+ end
114
+
115
+ def set_default_status(status_attribute, status)
116
+ before_create do |obj|
117
+ obj.send("#{status_attribute}=", obj.class.send(status_attribute.to_s.pluralize)[status]) unless obj.send(status_attribute.to_s)
118
+ end
119
+ end
120
+
121
+ def status_store_list
122
+ if self.class_variable_defined?(:@@status_store_list)
123
+ class_variable_get(:@@status_store_list)
124
+ else
125
+ class_variable_set(:@@status_store_list, StatusStoreList.new)
126
+ end
127
+ end
128
+ end
124
129
  end
125
130
 
126
- ActiveRecord::Base.send(:include, StatusManager) if defined? ActiveRecord
131
+ ActiveRecord::Base.send(:include, StatusManager) if defined? ActiveRecord
@@ -1,25 +1,27 @@
1
1
  module StatusManager
2
- module StatusGroupManager
3
- def status_group (status_attribute_name, group_status_set={})
4
- status_store = self.status_store_list.get(status_attribute_name.to_sym)
5
- raise "undefined #{status_attribute_name}" unless status_store
6
-
7
- group_status_set.each do |group_status_name, group_statuses|
8
- raise "#{status_attribute_name}-#{group_status_name} is not a group, group must have statuses" if group_statuses.size < 1
9
- status_store.add_group_status(group_status_name, group_statuses)
2
+ module StatusGroupManager
3
+ def status_group(status_attribute_name, group_status_set = {})
4
+ status_store = self.status_store_list.get(status_attribute_name.to_sym)
5
+ raise "undefined #{status_attribute_name}" unless status_store
6
+
7
+ group_status_set.each do |group_status_name, group_statuses|
8
+ raise "#{status_attribute_name}-#{group_status_name} is not a group, group must have statuses" if group_statuses.size < 1
9
+ status_store.add_group_status(group_status_name, group_statuses)
10
10
 
11
- # set scope
12
- scope "#{status_store.attribute_name}_#{group_status_name}", where("#{self.table_name}.#{status_store.attribute_name} in (?)", status_store.get_group_status(group_status_name).values)
11
+ # set scope
12
+ scope "#{status_store.attribute_name}_#{group_status_name}", -> {
13
+ where("#{self.table_name}.#{status_store.attribute_name} in (?)", status_store.get_group_status(group_status_name).values)
14
+ }
13
15
 
14
- # status check method
15
- define_method "#{status_attribute_name}_#{group_status_name}?" do
16
- status_store.get_group_status(group_status_name).values.include? self.send(status_attribute_name)
17
- end
16
+ # status check method
17
+ define_method "#{status_attribute_name}_#{group_status_name}?" do
18
+ status_store.get_group_status(group_status_name).values.include? self.send(status_attribute_name)
19
+ end
18
20
 
19
- define_method "#{status_attribute_name}_was_#{group_status_name}?" do
20
- status_store.get_group_status(group_status_name).values.include? self.send("#{status_attribute_name}_was")
21
- end
22
- end
23
- end
24
- end
25
- end
21
+ define_method "#{status_attribute_name}_was_#{group_status_name}?" do
22
+ status_store.get_group_status(group_status_name).values.include? self.send("#{status_attribute_name}_was")
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,78 +1,77 @@
1
1
  module StatusManager
2
- class StatusStoreList
3
- attr_accessor :status_stores
2
+ class StatusStoreList
3
+ attr_accessor :status_stores
4
4
 
5
- def initialize
6
- @status_stores = []
7
- end
5
+ def initialize
6
+ @status_stores = []
7
+ end
8
8
 
9
- def add(status_store)
10
- @status_stores << status_store
11
- end
9
+ def add(status_store)
10
+ @status_stores << status_store
11
+ end
12
12
 
13
- def get(attribute)
14
- @status_stores.select {|status_store| status_store.attribute_name == attribute}.first
15
- end
16
- end
13
+ def get(attribute)
14
+ @status_stores.select { |status_store| status_store.attribute_name == attribute }.first
15
+ end
16
+ end
17
17
 
18
- class StatusStore
19
- attr_accessor :attribute_name, :status_sets, :group_statuses
18
+ class StatusStore
19
+ attr_accessor :attribute_name, :status_sets, :group_statuses
20
20
 
21
- def initialize(attribute_name, status_sets=nil )
22
- @attribute_name = attribute_name
23
- @status_sets = status_sets || {}
24
- @group_statuses = {}
25
- end
21
+ def initialize(attribute_name, status_sets = nil)
22
+ @attribute_name = attribute_name
23
+ @status_sets = status_sets || {}
24
+ @group_statuses = {}
25
+ end
26
26
 
27
- def statuses
28
- @status_sets.keys
29
- end
27
+ def statuses
28
+ @status_sets.keys
29
+ end
30
30
 
31
- def status?(status)
32
- @status_sets.key?(status)
33
- end
31
+ def status?(status)
32
+ @status_sets.key?(status)
33
+ end
34
34
 
35
- def value(status)
36
- @status_sets[status]
37
- end
35
+ def value(status)
36
+ @status_sets[status]
37
+ end
38
38
 
39
- def group_status?(group_status)
40
- @group_statuses.key?(group_status)
41
- end
39
+ def group_status?(group_status)
40
+ @group_statuses.key?(group_status)
41
+ end
42
42
 
43
- #scope에 array 파라미터 넣기 적용
44
- def values(statuses=[])
45
- if statuses.nil?
46
- return @statuse_sets.values
47
- elsif status? statuses
48
- return [value(statuses)]
49
- elsif group_status? statuses
50
- return get_group_status(statuses).values
51
- elsif statuses.instance_of?(Array)
52
- results = []
53
- statuses.each do |_status|
54
- if status?(_status)
55
- results << value(_status)
56
- elsif group_status?(_status)
57
- results |= get_group_status(_status).values
58
- end
59
- end
60
- return results.uniq
61
- else
62
- return []
63
- end
64
- end
43
+ def add_group_status(group_status_name, statuses)
44
+ @group_statuses.merge!(group_status_name => statuses)
45
+ end
65
46
 
66
- def add_group_status(group_status_name, statuses)
67
- @group_statuses.merge!({group_status_name => statuses})
68
- end
47
+ def get_group_status(group_status_name)
48
+ statuses = {}
49
+ @group_statuses[group_status_name].each do |status|
50
+ statuses[status] = value(status)
51
+ end
52
+ statuses
53
+ end
69
54
 
70
- def get_group_status(group_status_name)
71
- statuses = {}
72
- @group_statuses[group_status_name].each do |status|
73
- statuses[status] = self.value(status)
74
- end
75
- statuses
76
- end
77
- end
78
- end
55
+ def values(statuses = [])
56
+ if statuses.nil?
57
+ return @statuse_sets.values
58
+ elsif status? statuses
59
+ return [value(statuses)]
60
+ elsif group_status? statuses
61
+ return get_group_status(statuses).values
62
+ elsif statuses.instance_of?(Array)
63
+ results = []
64
+ statuses.each do |_status|
65
+ if status?(_status)
66
+ results << value(_status)
67
+ elsif group_status?(_status)
68
+ results |= get_group_status(_status).values
69
+ end
70
+ end
71
+ return results.uniq
72
+ else
73
+ return []
74
+ end
75
+ end
76
+ end
77
+ end
@@ -1,3 +1,3 @@
1
1
  module StatusManager
2
- VERSION = '0.8.5'
3
- end
2
+ VERSION = '0.9.0'
3
+ end
@@ -1,34 +1,30 @@
1
1
  class Product < ActiveRecord::Base
2
- attr_accessible :title, :sale_status
2
+ # acts_as_status :status_attribute in model, {status_value: 'status_value that is saved in database'}
3
3
 
4
- # acts_as_status :status_attribute in model, {:status_value => 'status_value that is saved in database'}
5
-
6
- # attr_as_status :sale_status, :onsale => 'onsale', :reject => 'reject', :pending => 'pending', :soldout => 'soldout'
7
- # attr_as_status :sale_status, [:onsale, :reject, :pending, :soldout]
8
-
9
- attr_as_status :sale_status,
10
- [:onsale, :reject, :pending, :soldout],
11
- :default => :onsale,
12
- :group => {
13
- :close => [:pending, :reject],
14
- :open => [:soldout, :onsale],
15
- :display => [:onsale, :soldout]
16
- }
4
+ # attr_as_status :sale_status, onsale: 'onsale', reject: 'reject', pending: 'pending', soldout: 'soldout'
5
+ # attr_as_status :sale_status, [:onsale, :reject, :pending, :soldout]
17
6
 
18
- before_status_update :sale_status, :close => :onsale do |product|
19
- puts "display #{product.title}"
20
- end
7
+ attr_as_status :sale_status,
8
+ [:onsale, :reject, :pending, :soldout],
9
+ default: :onsale,
10
+ group: { close: [:pending, :reject],
11
+ open: [:soldout, :onsale],
12
+ display: [:onsale, :soldout]
13
+ }
21
14
 
22
- after_status_update :sale_status, :pending => :onsale do |product|
23
- puts "release #{product.title}"
24
- end
15
+ before_status_update :sale_status, close: :onsale do |product|
16
+ puts "display #{product.title}"
17
+ end
25
18
 
26
- after_status_update :sale_status, :onsale do |product|
27
- puts "onsale #{product.title}"
28
- end
19
+ after_status_update :sale_status, pending: :onsale do |product|
20
+ puts "release #{product.title}"
21
+ end
29
22
 
30
- after_status_update :sale_status, :display => :close do |product|
31
- puts "close #{product.title}"
32
- end
23
+ after_status_update :sale_status, :onsale do |product|
24
+ puts "onsale #{product.title}"
25
+ end
33
26
 
27
+ after_status_update :sale_status, display: :close do |product|
28
+ puts "close #{product.title}"
29
+ end
34
30
  end
@@ -3,75 +3,75 @@ require 'models/product'
3
3
 
4
4
  describe StatusManager do
5
5
 
6
- it "should set default status" do
7
- product = Product.new
8
- product.save
9
- product.should be_sale_status(:onsale)
10
- end
6
+ it 'should set default status' do
7
+ product = Product.new(sale_status: 'onsale')
8
+ product.save
9
+ puts Product.sale_statuses
10
+ product.should be_sale_status(:onsale)
11
+ end
11
12
 
12
- it "should check chages with hash" do
13
- product = Product.sale_status(:onsale).first
14
- product.should_not be_sale_status_changed
15
- product.sale_status_to(:pending)
16
- product.should be_sale_status_changed
17
- product.should be_sale_status_changed(:from => :display, :to => :close)
18
- product.should be_sale_status_changed(:from => :onsale)
19
- product.should be_sale_status_changed(:to => :close)
13
+ it 'should check chages with hash' do
14
+ product = Product.sale_status(:onsale).first
15
+ product.should_not be_sale_status_changed
16
+ product.sale_status_to(:pending)
17
+ product.should be_sale_status_changed
18
+ product.should be_sale_status_changed(from: :display, to: :close)
19
+ product.should be_sale_status_changed(from: :onsale)
20
+ product.should be_sale_status_changed(to: :close)
20
21
 
21
- product.save
22
- product.should_not be_sale_status_changed
23
- end
22
+ product.save
23
+ product.should_not be_sale_status_changed
24
+ end
24
25
 
25
- it "should update status" do
26
- product = Product.sale_status(:pending).first
27
- product.should be_sale_status(:pending)
28
- product.update_sale_status_to_onsale
29
- product.should be_sale_status(:onsale)
30
- end
26
+ it 'should update status' do
27
+ product = Product.sale_status(:pending).first
28
+ product.should be_sale_status(:pending)
29
+ product.update_sale_status_to_onsale
30
+ product.should be_sale_status(:onsale)
31
+ end
31
32
 
32
- it "should work with scope" do
33
- Product.sale_status([:display, :reject]).size.should equal(Product.all.size - Product.sale_status(:pending).size)
34
- end
33
+ it 'should work with scope' do
34
+ Product.sale_status([:display, :reject]).size.should equal(Product.all.size - Product.sale_status(:pending).size)
35
+ end
35
36
 
36
- it "should check current status" do
37
- products = Product.sale_status_onsale
38
- products.each do |product|
39
- product.should be_sale_status_onsale
40
- product.should be_sale_status(:onsale)
41
- end
37
+ it 'should check current status' do
38
+ products = Product.sale_status_onsale
39
+ products.each do |product|
40
+ product.should be_sale_status_onsale
41
+ product.should be_sale_status(:onsale)
42
+ end
42
43
 
43
- rejected_products = Product.sale_status_reject
44
- rejected_products.each do |product|
45
- product.should be_sale_status_reject
46
- product.should be_sale_status(:reject)
47
- end
44
+ rejected_products = Product.sale_status_reject
45
+ rejected_products.each do |product|
46
+ product.should be_sale_status_reject
47
+ product.should be_sale_status(:reject)
48
+ end
48
49
 
49
- end
50
+ end
50
51
 
51
- it "should update status" do
52
- product = Product.sale_status_onsale.first
53
- product.sale_status_to(:reject)
54
- product.should be_sale_status(:reject)
52
+ it 'should update status' do
53
+ product = Product.sale_status_onsale.first
54
+ product.sale_status_to(:reject)
55
+ product.should be_sale_status(:reject)
55
56
 
56
- product.update_sale_status_to(:soldout)
57
- Product.find(product.id).should be_sale_status(:soldout)
57
+ product.update_sale_status_to(:soldout)
58
+ Product.find(product.id).should be_sale_status(:soldout)
58
59
 
59
- product.update_sale_status_to(:onsale)
60
- Product.find(product.id).should be_sale_status(:onsale)
61
- end
60
+ product.update_sale_status_to(:onsale)
61
+ Product.find(product.id).should be_sale_status(:onsale)
62
+ end
62
63
 
63
- it "should work with status group" do
64
- closed_products = Product.sale_status_close
65
- _closed_products = Product.sale_status(:close)
66
- closed_products.size.should equal(_closed_products.size)
67
- closed_products.each do |product|
68
- product.should be_sale_status(:close)
69
- end
64
+ it 'should work with status group' do
65
+ closed_products = Product.sale_status_close
66
+ _closed_products = Product.sale_status(:close)
67
+ closed_products.size.should equal(_closed_products.size)
68
+ closed_products.each do |product|
69
+ product.should be_sale_status(:close)
70
+ end
70
71
 
71
- displayed_products = Product.sale_status_display
72
- displayed_products.each do |product|
73
- product.should be_sale_status(:display)
74
- end
75
- end
76
-
77
- end
72
+ displayed_products = Product.sale_status_display
73
+ displayed_products.each do |product|
74
+ product.should be_sale_status(:display)
75
+ end
76
+ end
77
+ end
@@ -6,11 +6,11 @@ require 'status-manager/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "status-manager"
8
8
  spec.version = StatusManager::VERSION
9
- spec.date = "2014-04-14"
9
+ spec.date = "2014-12-29"
10
10
  spec.authors = ["keepcosmos"]
11
11
  spec.email = ["keepcosmos@gmail.com"]
12
12
  spec.description = "ActiveRecord Model Status Manager"
13
- spec.summary = "ActiveRecord Model Status Manager, It provides easy ways for managing ActiveModels that have many statuses."
13
+ spec.summary = "ActiveRecord Model Status Manager, It provides easy ways for managing ActiveRecords that have many statuses."
14
14
  spec.homepage = "https://github.com/keepcosmos/status-manager"
15
15
  spec.license = "MIT"
16
16
 
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: status-manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.5
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - keepcosmos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-14 00:00:00.000000000 Z
11
+ date: 2014-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description: ActiveRecord Model Status Manager
@@ -45,7 +45,7 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
- - .gitignore
48
+ - ".gitignore"
49
49
  - Gemfile
50
50
  - LICENSE.txt
51
51
  - README.md
@@ -74,20 +74,20 @@ require_paths:
74
74
  - lib
75
75
  required_ruby_version: !ruby/object:Gem::Requirement
76
76
  requirements:
77
- - - '>='
77
+ - - ">="
78
78
  - !ruby/object:Gem::Version
79
79
  version: '0'
80
80
  required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  requirements:
82
- - - '>='
82
+ - - ">="
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  requirements: []
86
86
  rubyforge_project:
87
- rubygems_version: 2.0.9
87
+ rubygems_version: 2.4.5
88
88
  signing_key:
89
89
  specification_version: 4
90
- summary: ActiveRecord Model Status Manager, It provides easy ways for managing ActiveModels
90
+ summary: ActiveRecord Model Status Manager, It provides easy ways for managing ActiveRecords
91
91
  that have many statuses.
92
92
  test_files:
93
93
  - spec/config/database.yml
@@ -96,3 +96,4 @@ test_files:
96
96
  - spec/models/product.rb
97
97
  - spec/product1_spec.rb
98
98
  - spec/spec_helper.rb
99
+ has_rdoc: