status-manager 0.8.1 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YWJlN2RkZjA2NmY0OTdiNWIyYWJmM2YxNzgwNGVhYjg3MDI5NTVkZQ==
5
- data.tar.gz: !binary |-
6
- MDg5ZWNkZDZlMWM0ZWE2MmZjNTM0OTAzNjcwNTEzMmJmY2U2MmFlMw==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- NDNjNzdhNzNjOTk0NTY2N2ZkZmNlMWY1NjA4MzNjMTUyMzBkZWM0MDkyNDQ3
10
- NzAwYWQyNzdhYzllODVmMjhlZmYyYjM4YTNjY2NjMmYwZDE2ZWJiZDRmZjBj
11
- NTZiYTY1MmMxYTczOTQzZmNiNDM4YWQ3OTg4MmMxMjA1YjBjNGQ=
12
- data.tar.gz: !binary |-
13
- NWI5ZWJlMmEzNGQ1NjQzZTNjZjY5NzBhMzA2MGJmMmY3OTQyMTg4ZTc2YmRk
14
- MTNiNWEwMGI4ZTU2MTM1NzMzYmEwMDM1OTA3NmI0NmYxNjQzYTY4MDYyZjRm
15
- ZTNkYWY5MjE4ZjU0Mzg4MWRmMWY3YzIwMmM0MDllZDNiNWNlNTg=
2
+ SHA1:
3
+ metadata.gz: 48d814f9533ce9e07a91e5b07510619551f1f2c3
4
+ data.tar.gz: 53f76760593ce0b882f30e2a078e62e267704e5b
5
+ SHA512:
6
+ metadata.gz: b1c682886b99ab3fc04eb6c992bdfda67b2b1e697ce2fd3429d48b264bdc7c218e4e0da56254ed0f08bd2b4d3c56d7dd300da501454fbc08a4d7f3551a0d4df5
7
+ data.tar.gz: 240863dab42f535ebec142e2cb1ef695018300358aba18b7bbf71df99f08bb9221a635b3ebd1a38737f9438f0d9a72a2311e0fc7fa963a4c927b0d3dd4c32ef0
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+ gemspec
3
+
4
+ gem "rake"
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 keepcosmos
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  ## Description
2
- ActiveRecord Model Status Manager, It provides easy ways managing model that have many statuses.
2
+ ActiveRecord Model Status Manager, It provides easy ways managing models that have many statuses.
3
+
4
+ www.myrealtrip.com uses status-manager
3
5
 
4
6
  ## Usage
5
7
 
@@ -17,8 +19,16 @@ class Product < ActiveRecord::Base
17
19
  attr_accessible :title, :sale_status
18
20
 
19
21
  # attr_as_status :status_attribute in model, {:status_value => 'status_value that is saved in database'}
20
- attr_as_status :sale_status, {:onsale => 'onsale', :reject => 'reject', :pending => 'pending', :soldout => 'soldout'}
21
- status_group :sale_status, {:close => [:reject, :pending], :open => [:onsale, :soldout]}
22
+ attr_as_status :sale_status, {
23
+ :onsale => 'onsale',
24
+ :reject => 'reject',
25
+ :pending => 'pending',
26
+ :soldout => 'soldout'
27
+ }
28
+ status_group :sale_status, {
29
+ :close => [:reject, :pending], # :close works as status
30
+ :open => [:onsale, :soldout]
31
+ }
22
32
  end
23
33
  ```
24
34
 
@@ -31,21 +41,21 @@ Product.sale_statuses #=> {:onsale => 'onsale', :reject => 'reject', :pending =>
31
41
  @onsale_product = Product.sale_status_onsale.first
32
42
  @closed_product = Product.sale_status_close.first
33
43
  #or using symbol
34
- Product.sale_status(:onsale)
44
+ Product.sale_status(:open)
35
45
  #or multiple statuses (with group statuses)
36
- Product.sale_status(:onsale, :pending)
46
+ Product.sale_status([:soldout, :close]) # use array
37
47
 
38
48
  @onsale_product.sale_status_onsale? #=> true
39
49
  #or
40
50
  @closed_product.sale_status?(:close) #=> true
41
51
 
42
52
 
43
- ## change attribute value
53
+ ## change status
44
54
  @closed_product.sale_status_to(:onsale)
45
55
  #or
46
56
  @closed_product.sale_status_to_onsale
47
57
 
48
- ## update value with database
58
+ ## update status
49
59
  @closed_product.update_sale_status_to(:onsale)
50
60
  #or
51
61
  @closed_product.update_sale_status_to_onsale
@@ -55,10 +65,11 @@ Product.sale_status(:onsale, :pending)
55
65
  ```ruby
56
66
  pending_product = Product.sale_status(:pending).first
57
67
  pending_product.sale_status_to(:onsale)
68
+
58
69
  pending_product.sale_status_changed? #=> true
59
70
  pending_product.sale_status_changed?(:from => :pending, :to => :onsale) #=> true
60
- pending_product.sale_Status_changed?(:to => onsale) #=>true
61
- pending_product.sale_Status_changed?(:from => onsale) #=> true
71
+ pending_product.sale_status_changed?(:to => :onsale) #=>true
72
+ pending_product.sale_status_changed?(:from => :onsale) #=> true
62
73
  ```
63
74
 
64
75
  #### Callback
@@ -89,5 +100,3 @@ class Product < ActiveRecord::Base
89
100
  end
90
101
 
91
102
  ```
92
-
93
- www.myrealtrip.com uses status-manager
data/Rakefile CHANGED
@@ -1,13 +1,13 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'rake'
3
3
  require 'rake/testtask'
4
+ require 'rspec/core/rake_task'
5
+ Bundler::GemHelper.install_tasks
4
6
 
5
7
  desc "Default: run unit tests."
6
- task :default => :test
8
+ task :default => :spec
7
9
 
8
- desc "Test Status Manager"
9
- Rake::TestTask.new(:test) do |t|
10
- t.libs << %w[lib test]
11
- t.pattern = 'test/**/*_test.rb'
12
- t.verbose = true
13
- end
10
+ desc "Run Status Manager RSpec"
11
+ RSpec::Core::RakeTask.new do |t|
12
+ t.verbose = false
13
+ end
@@ -1,3 +1,3 @@
1
1
  module StatusManager
2
- VERSION = '0.7.0'
2
+ VERSION = '0.8.3'
3
3
  end
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'active_record'
3
+ require 'active_record/fixtures'
4
+ require 'status-manager'
5
+
6
+ lib = File.expand_path(__dir__)
7
+ ActiveRecord::Base.configurations = YAML::load_file("#{lib}/config/database.yml")['test']
8
+ ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations)
9
+ load("#{lib}/config/schema.rb")
10
+
11
+ ActiveRecord::Fixtures.create_fixtures 'spec/fixtures', 'products'
12
+
13
+ RSpec.configure do |config|
14
+
15
+ end
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+ require 'models/product'
3
+
4
+ describe StatusManager do
5
+
6
+ it "should check chages with hash" do
7
+ product = Product.sale_status(:onsale).first
8
+ product.should_not be_sale_status_changed
9
+ product.sale_status_to(:pending)
10
+ product.should be_sale_status_changed
11
+ product.should be_sale_status_changed(:from => :display, :to => :close)
12
+ product.should be_sale_status_changed(:from => :onsale)
13
+ product.should be_sale_status_changed(:to => :close)
14
+
15
+ product.save
16
+ product.should_not be_sale_status_changed
17
+ end
18
+
19
+ it "should update status" do
20
+ product = Product.sale_status(:pending).first
21
+ product.should be_sale_status(:pending)
22
+ product.update_sale_status_to_onsale
23
+ product.should be_sale_status(:onsale)
24
+ end
25
+
26
+ it "should work with scope" do
27
+ Product.sale_status([:display, :reject]).size.should equal(Product.all.size - Product.sale_status(:pending).size)
28
+ end
29
+
30
+ it "should check current status" do
31
+ products = Product.sale_status_onsale
32
+ products.each do |product|
33
+ product.should be_sale_status_onsale
34
+ product.should be_sale_status(:onsale)
35
+ end
36
+
37
+ rejected_products = Product.sale_status_reject
38
+ rejected_products.each do |product|
39
+ product.should be_sale_status_reject
40
+ product.should be_sale_status(:reject)
41
+ end
42
+
43
+ end
44
+
45
+ it "should update status" do
46
+ product = Product.sale_status_onsale.first
47
+ product.sale_status_to(:reject)
48
+ product.should be_sale_status(:reject)
49
+
50
+ product.update_sale_status_to(:soldout)
51
+ Product.find(product.id).should be_sale_status(:soldout)
52
+
53
+ product.update_sale_status_to(:onsale)
54
+ Product.find(product.id).should be_sale_status(:onsale)
55
+ end
56
+
57
+ it "should work with status group" do
58
+ closed_products = Product.sale_status_close
59
+ _closed_products = Product.sale_status(:close)
60
+ closed_products.size.should equal(_closed_products.size)
61
+ closed_products.each do |product|
62
+ product.should be_sale_status(:close)
63
+ end
64
+
65
+ displayed_products = Product.sale_status_display
66
+ displayed_products.each do |product|
67
+ product.should be_sale_status(:display)
68
+ end
69
+ end
70
+
71
+ end
@@ -1,16 +1,24 @@
1
- Gem::Specification.new do |s|
2
- s.name = 'status-manager'
3
- s.version = '0.8.1'
4
- s.date = '2013-12-21'
5
- s.summary = "ActiveRecord Model Status Manager"
6
- s.description = "ActiveRecord Model Status Manager, It provides easy ways for managing ActiveModels that have many statuses."
7
- s.authors = ["Keepcosmos"]
8
- s.email = 'keepcosmos@gmail.com'
9
- s.licenses = 'MIT'
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'status-manager/version'
10
5
 
11
- s.files = `git ls-files`.split("\n")
12
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
13
- s.require_paths = ["lib"]
14
-
15
- s.homepage = 'https://github.com/keepcosmos/status-manager'
16
- end
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "status-manager"
8
+ spec.version = StatusManager::VERSION
9
+ spec.date = "2014-04-10"
10
+ spec.authors = ["keepcosmos"]
11
+ spec.email = ["keepcosmos@gmail.com"]
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."
14
+ spec.homepage = "https://github.com/keepcosmos/status-manager"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ end
Binary file
metadata CHANGED
@@ -1,22 +1,53 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: status-manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.3
5
5
  platform: ruby
6
6
  authors:
7
- - Keepcosmos
7
+ - keepcosmos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-21 00:00:00.000000000 Z
12
- dependencies: []
13
- description: ActiveRecord Model Status Manager, It provides easy ways for managing
14
- ActiveModels that have many statuses.
15
- email: keepcosmos@gmail.com
11
+ date: 2014-04-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: ActiveRecord Model Status Manager
42
+ email:
43
+ - keepcosmos@gmail.com
16
44
  executables: []
17
45
  extensions: []
18
46
  extra_rdoc_files: []
19
47
  files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
20
51
  - README.md
21
52
  - Rakefile
22
53
  - lib/status-manager.rb
@@ -25,16 +56,14 @@ files:
25
56
  - lib/status-manager/status_update_callback.rb
26
57
  - lib/status-manager/status_validation.rb
27
58
  - lib/status-manager/version.rb
28
- - status-manager-0.1.3.gem
29
- - status-manager-0.7.0.gem
59
+ - spec/config/database.yml
60
+ - spec/config/schema.rb
61
+ - spec/fixtures/products.yml
62
+ - spec/models/product.rb
63
+ - spec/spec_helper.rb
64
+ - spec/status-manager_spec.rb
30
65
  - status-manager.gemspec
31
66
  - status_manager_test.sqlite3
32
- - test/config/database.yml
33
- - test/config/schema.rb
34
- - test/fixtures/products.yml
35
- - test/models/product.rb
36
- - test/status-manager_test.rb
37
- - test/test_initializer.rb
38
67
  homepage: https://github.com/keepcosmos/status-manager
39
68
  licenses:
40
69
  - MIT
@@ -45,24 +74,25 @@ require_paths:
45
74
  - lib
46
75
  required_ruby_version: !ruby/object:Gem::Requirement
47
76
  requirements:
48
- - - ! '>='
77
+ - - '>='
49
78
  - !ruby/object:Gem::Version
50
79
  version: '0'
51
80
  required_rubygems_version: !ruby/object:Gem::Requirement
52
81
  requirements:
53
- - - ! '>='
82
+ - - '>='
54
83
  - !ruby/object:Gem::Version
55
84
  version: '0'
56
85
  requirements: []
57
86
  rubyforge_project:
58
- rubygems_version: 2.0.7
87
+ rubygems_version: 2.0.9
59
88
  signing_key:
60
89
  specification_version: 4
61
- summary: ActiveRecord Model Status Manager
90
+ summary: ActiveRecord Model Status Manager, It provides easy ways for managing ActiveModels
91
+ that have many statuses.
62
92
  test_files:
63
- - test/config/database.yml
64
- - test/config/schema.rb
65
- - test/fixtures/products.yml
66
- - test/models/product.rb
67
- - test/status-manager_test.rb
68
- - test/test_initializer.rb
93
+ - spec/config/database.yml
94
+ - spec/config/schema.rb
95
+ - spec/fixtures/products.yml
96
+ - spec/models/product.rb
97
+ - spec/spec_helper.rb
98
+ - spec/status-manager_spec.rb
Binary file
Binary file
@@ -1,74 +0,0 @@
1
- require 'test_initializer'
2
- require 'models/product'
3
-
4
- class StatusManagerTest < Test::Unit::TestCase
5
-
6
- def test_change
7
- product = Product.sale_status(:onsale).first
8
- assert !product.sale_status_changed?
9
- product.sale_status_to(:pending)
10
- assert product.sale_status_changed?
11
- assert product.sale_status_changed?(:from => :display, :to => :close)
12
- assert product.sale_status_changed?(:from => :onsale)
13
- assert product.sale_status_changed?(:to => :close)
14
- product.save
15
- assert !product.sale_status_changed?
16
- end
17
-
18
- def test_status_update
19
- product = Product.sale_status(:pending).first
20
- assert product.sale_status?(:pending)
21
- product.update_sale_status_to_onsale
22
- assert product.sale_status?(:onsale)
23
- end
24
-
25
- def test_multiple_status_scope
26
- assert Product.sale_status(Product.sale_statuses.keys).size == Product.all.size
27
- assert Product.sale_status([:display, :reject]).size == (Product.all.size - Product.sale_status(:pending).size)
28
- end
29
-
30
- def test_current_status
31
- products = Product.sale_status_onsale
32
- products.each do |product|
33
- assert product.sale_status_onsale?
34
- assert product.sale_status? :onsale
35
- end
36
-
37
- rejected_products = Product.sale_status_reject
38
- rejected_products.each do |product|
39
- assert product.sale_status_reject?
40
- assert product.sale_status? :reject
41
- end
42
- end
43
-
44
- def test_status_update
45
- product = Product.sale_status_onsale.first
46
- product.sale_status_to :reject
47
- product.sale_status_to_reject
48
- assert product.sale_status_reject?
49
- assert product.sale_status? :reject
50
-
51
- product.update_sale_status_to :soldout
52
- assert Product.find(product.id).sale_status_soldout?
53
-
54
- product.update_sale_status_to_onsale
55
- assert Product.find(product.id).sale_status_onsale?
56
- end
57
-
58
- def test_group_status
59
- closed_products = Product.sale_status_close
60
- _closed_products = Product.sale_status(:close)
61
- assert closed_products.size == _closed_products.size
62
- closed_products.each do |product|
63
- assert product.sale_status_close?
64
- assert product.sale_status? :close
65
- end
66
-
67
- displayed_products = Product.sale_status_display
68
- displayed_products.each do |product|
69
- assert product.sale_status_display?
70
- assert product.sale_status? :display
71
- end
72
- end
73
-
74
- end
@@ -1,15 +0,0 @@
1
- $:.unshift(File.dirname(__FILE__) + '/../..')
2
- $:.unshift(File.dirname(__FILE__) + '/../../lib')
3
-
4
- require 'rubygems'
5
- require 'test/unit'
6
- require 'active_record'
7
- require 'active_record/fixtures'
8
-
9
- require 'status-manager'
10
-
11
- ActiveRecord::Base.configurations = YAML::load_file("#{File.dirname(__FILE__)}/config/database.yml")['test']
12
- ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations)
13
- load("#{File.dirname(__FILE__)}/config/schema.rb")
14
-
15
- ActiveRecord::Fixtures.create_fixtures 'test/fixtures', 'products'