state_objects 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
+ .rvmrc
6
7
  Gemfile.lock
7
8
  InstalledFiles
8
9
  _yardoc
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.0.8
2
+ Additional tests ported from selection_options gem
3
+
1
4
  ## 0.0.7
2
5
  Fixed typos
3
6
 
data/DOTrvmrc ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env bash
2
+
3
+ ruby_string="ruby-1.9.3-p194"
4
+ gemset_name="state-objects"
5
+
6
+ if rvm list strings | grep -q "${ruby_string}" ; then
7
+
8
+ # Load or create the specified environment
9
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
10
+ && -s "${rvm_path:-$HOME/.rvm}/environments/${ruby_string}@${gemset_name}" ]] ; then
11
+ \. "${rvm_path:-$HOME/.rvm}/environments/${ruby_string}@${gemset_name}"
12
+ else
13
+ rvm --create "${ruby_string}@${gemset_name}"
14
+ fi
15
+
16
+ else
17
+
18
+ # Notify the user to install the desired interpreter before proceeding.
19
+ echo "${ruby_string} was not found, please run 'rvm install ${ruby_string}' and then cd back into the project directory."
20
+
21
+ fi
data/README.md CHANGED
@@ -120,6 +120,7 @@ adds the following INSTANCE METHODS to WalkLight
120
120
 
121
121
  ### Example #4: adding scope with _occurs
122
122
  It's now easy to add scopes with using _occurs, which will generate your where statement for you.
123
+
123
124
  scope :red, where(WalkLight.color_state_red_occurs ) # => "(color_state ='R')"
124
125
  scope :green, where(WalkLight.color_state_green_occurs ) # => "(color_state ='G')"
125
126
 
@@ -130,3 +131,6 @@ It's now easy to add scopes with using _occurs, which will generate your where s
130
131
  3. Commit your changes (`git commit -am 'Add some feature'`)
131
132
  4. Push to the branch (`git push origin my-new-feature`)
132
133
  5. Create new Pull Request
134
+
135
+ ## Thanks To
136
+ * Scott Baron - for helping with the unit tests.
data/Rakefile CHANGED
@@ -1 +1,10 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'lib' << 'test'
6
+ test.pattern = 'test/**/*_test.rb'
7
+ test.verbose = true
8
+ end
9
+
10
+ task :default => :test
@@ -5,7 +5,11 @@ module StateObjects
5
5
  @model = model
6
6
  end
7
7
 
8
- def self.state_object_values(*opts) # :nodoc:
8
+ def self.state_object_values(*opts) # :nodoc:
9
+ unless opts.size == 3
10
+ raise @model.to_s + "#state_object_values Must have 3 arguments: symbol, db_value, label. For Example: state_object_values :red,'R','Dont Walk'"
11
+ end
12
+
9
13
  class_eval <<-EOF
10
14
  def self.symbol
11
15
  '#{opts[0]}'.to_sym
@@ -69,7 +69,7 @@ module StateObjects
69
69
  opts.each do |option_klass|
70
70
  [:symbol, :label, :db_value].each do |required_method|
71
71
  unless option_klass.respond_to?(required_method)
72
- raise "Invalid State class ["+ option_klass.to_s + "]. Must implement a class method named: ##{required_method}. I suggest using #state_object_values"
72
+ raise "Invalid State class ["+ option_klass.to_s + "]. Must implement a class method named: ##{required_method}. Use #state_object_values to setup StateObject"
73
73
  end
74
74
  end
75
75
 
@@ -1,3 +1,3 @@
1
1
  module StateObjects
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -20,8 +20,8 @@ Gem::Specification.new do |gem|
20
20
 
21
21
  # gem.add_development_dependency "supermodel" # TODO
22
22
  # gem.add_development_dependency "activerecord"
23
- gem.add_development_dependency "supermodel"
24
- gem.add_development_dependency "rspec-given"
25
- gem.add_runtime_dependency "activerecord"
23
+ gem.add_development_dependency 'supermodel'
24
+ gem.add_development_dependency 'rspec-given'
25
+ gem.add_runtime_dependency 'activerecord'
26
26
 
27
27
  end
@@ -1,4 +1,4 @@
1
- ## ruby -Itest -Ilib test/state_objects_methods_test.rb
1
+ ## ruby -Itest -Ilib test/methods_test.rb
2
2
  require 'test_helper'
3
3
 
4
4
  #
@@ -1,4 +1,4 @@
1
- ## ruby -Itest -Ilib test/state_objects_exceptions_test.rb
1
+ ## ruby -Itest -Ilib test/missing_event_ex_test.rb
2
2
  require 'test_helper'
3
3
 
4
4
  #
@@ -9,7 +9,7 @@ class LightGreenState < StateObjects::Base
9
9
  state_object_values :green, 'G', 'Walk'
10
10
  end
11
11
 
12
- class ModelUnderTest < SuperModel::Base
12
+ class MissingEventExModelUnderTest < SuperModel::Base
13
13
  extend StateObjects::ModelAdditions
14
14
  state_objects :color_state,
15
15
  LightGreenState
@@ -27,15 +27,15 @@ class ModelUnderTest < SuperModel::Base
27
27
 
28
28
  end
29
29
 
30
- class TranslateOptionsForExTest < Test::Unit::TestCase
30
+ class MissingEventExTest < Test::Unit::TestCase
31
31
  def setup
32
- @model = ModelUnderTest
32
+ @model = MissingEventExModelUnderTest
33
33
  end
34
34
 
35
35
  def test_exception_missing_event
36
- assert_equal RuntimeError, ModelUnderTest.exception_missing_event.class
36
+ assert_equal RuntimeError, MissingEventExModelUnderTest.exception_missing_event.class
37
37
  assert_equal "Invalid state class LightGreenState must implement #missing_event",
38
- ModelUnderTest.exception_missing_event.message
38
+ MissingEventExModelUnderTest.exception_missing_event.message
39
39
  end
40
40
 
41
41
  end
@@ -0,0 +1,29 @@
1
+ ## ruby -Itest -Ilib test/state_object_values_class_test.rb
2
+ require 'test_helper'
3
+
4
+ class StateObjectUnderTest < StateObjects::Base
5
+
6
+ begin
7
+ state_object_values :green, 'G'
8
+ rescue RuntimeError => ex
9
+ @@ex_incomplete_values = ex
10
+ end
11
+
12
+ def self.ex_incomplete_values
13
+ @@ex_incomplete_values
14
+ end
15
+
16
+ end
17
+
18
+ class StateObjectValuesClassTest < Test::Unit::TestCase
19
+ def setup
20
+ @model = StateObjectUnderTest
21
+ end
22
+
23
+ def test_ex_incomplete_values
24
+ assert_equal RuntimeError, StateObjectUnderTest.ex_incomplete_values.class
25
+ assert_equal "#state_object_values Must have 3 arguments: symbol, db_value, label. For Example: state_object_values :red,'R','Dont Walk'",
26
+ StateObjectUnderTest.ex_incomplete_values.message
27
+ end
28
+
29
+ end
@@ -0,0 +1,38 @@
1
+ ## ruby -Itest -Ilib test/state_object_values_test.rb
2
+ require 'test_helper'
3
+
4
+ #
5
+ # test bad data and exceptions
6
+ #
7
+
8
+ class NoStateObjectValues < StateObjects::Base
9
+ end
10
+
11
+ class ModelUnderTest < SuperModel::Base
12
+ extend StateObjects::ModelAdditions
13
+
14
+ begin
15
+ state_objects :no_state,
16
+ NoStateObjectValues
17
+ rescue RuntimeError => ex
18
+ @@ex_no_state_values = ex
19
+ end
20
+
21
+ def self.ex_no_state_values
22
+ @@ex_no_state_values
23
+ end
24
+
25
+ end
26
+
27
+ class StateObjectValuesTest < Test::Unit::TestCase
28
+ def setup
29
+ @model = ModelUnderTest
30
+ end
31
+
32
+ def test_no_state_values
33
+ assert_equal RuntimeError, ModelUnderTest.ex_no_state_values.class
34
+ assert_equal "Invalid State class [NoStateObjectValues]. Must implement a class method named: #symbol. Use #state_object_values to setup StateObject",
35
+ ModelUnderTest.ex_no_state_values.message
36
+ end
37
+
38
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: state_objects
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-07 00:00:00.000000000 Z
12
+ date: 2012-12-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: supermodel
@@ -70,6 +70,7 @@ extra_rdoc_files: []
70
70
  files:
71
71
  - .gitignore
72
72
  - CHANGELOG.md
73
+ - DOTrvmrc
73
74
  - Gemfile
74
75
  - LICENSE.txt
75
76
  - README.md
@@ -79,8 +80,10 @@ files:
79
80
  - lib/state_objects/model_additions.rb
80
81
  - lib/state_objects/version.rb
81
82
  - state_objects.gemspec
82
- - test/state_objects_exeptions_test.rb
83
- - test/state_objects_methods_test.rb
83
+ - test/methods_test.rb
84
+ - test/missing_event_ex_test.rb
85
+ - test/state_object_values_class_test.rb
86
+ - test/state_object_values_test.rb
84
87
  - test/test_helper.rb
85
88
  homepage: https://github.com/mwindholtz/state_objects
86
89
  licenses: []
@@ -107,6 +110,8 @@ signing_key:
107
110
  specification_version: 3
108
111
  summary: ! '''State'' Design Pattern from the Gang of Four book'
109
112
  test_files:
110
- - test/state_objects_exeptions_test.rb
111
- - test/state_objects_methods_test.rb
113
+ - test/methods_test.rb
114
+ - test/missing_event_ex_test.rb
115
+ - test/state_object_values_class_test.rb
116
+ - test/state_object_values_test.rb
112
117
  - test/test_helper.rb