characterizable 0.0.11 → 0.0.12

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.
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ begin
12
12
  gem.authors = ["Andy Rossmeissl", "Seamus Abshere"]
13
13
  gem.add_dependency 'blockenspiel', '>=0.3.2'
14
14
  gem.add_dependency 'activesupport', '>=2.3.5'
15
- gem.add_dependency 'to_json_fix', '>=0.0.1'
15
+ gem.add_development_dependency 'to_json_fix', '>=0.0.1'
16
16
  gem.add_development_dependency "shoulda", ">= 0"
17
17
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
18
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.11
1
+ 0.0.12
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{characterizable}
8
- s.version = "0.0.11"
8
+ s.version = "0.0.12"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andy Rossmeissl", "Seamus Abshere"]
12
- s.date = %q{2010-07-16}
12
+ s.date = %q{2010-07-21}
13
13
  s.description = %q{Characterize the relationship between "attributes" (getters/setters) of instances of a class}
14
14
  s.email = %q{seamus@abshere.net}
15
15
  s.extra_rdoc_files = [
@@ -45,7 +45,7 @@ Gem::Specification.new do |s|
45
45
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
46
  s.add_runtime_dependency(%q<blockenspiel>, [">= 0.3.2"])
47
47
  s.add_runtime_dependency(%q<activesupport>, [">= 2.3.5"])
48
- s.add_runtime_dependency(%q<to_json_fix>, [">= 0.0.1"])
48
+ s.add_development_dependency(%q<to_json_fix>, [">= 0.0.1"])
49
49
  s.add_development_dependency(%q<shoulda>, [">= 0"])
50
50
  else
51
51
  s.add_dependency(%q<blockenspiel>, [">= 0.3.2"])
@@ -9,11 +9,9 @@ require 'active_support/version'
9
9
  active_support/core_ext/array/wrap
10
10
  active_support/core_ext/module/aliasing
11
11
  active_support/core_ext/module/delegation
12
- active_support/json
13
12
  }.each do |active_support_3_requirement|
14
13
  require active_support_3_requirement
15
14
  end if ActiveSupport::VERSION::MAJOR == 3
16
- require 'to_json_fix'
17
15
 
18
16
  module Characterizable
19
17
  def self.included(klass)
@@ -125,6 +123,9 @@ module Characterizable
125
123
  delegate :characteristics, :to => :characterizable_base
126
124
  end
127
125
 
126
+ class CharacteristicAlreadyDefined < ArgumentError
127
+ end
128
+
128
129
  class Base
129
130
  attr_reader :klass
130
131
  def initialize(klass)
@@ -135,6 +136,7 @@ module Characterizable
135
136
  end
136
137
  include Blockenspiel::DSL
137
138
  def has(name, options = {}, &block)
139
+ raise CharacteristicAlreadyDefined, "The characteristic #{name} has already been defined on #{klass}!" if characteristics.has_key?(name)
138
140
  characteristics[name] = Characteristic.new(self, name, options, &block)
139
141
  begin
140
142
  # quacks like an activemodel
@@ -1,5 +1,9 @@
1
1
  require 'helper'
2
2
 
3
+ # just to see if it hurts
4
+ require 'active_support/json'
5
+ require 'to_json_fix'
6
+
3
7
  class Characterizable::Characteristic
4
8
  def hidden?
5
9
  !!options[:hidden]
@@ -370,12 +374,40 @@ class TestCharacterizable < Test::Unit::TestCase
370
374
  should 'be nice to active_support to_json for characteristics (i.e. BetterHashes)' do
371
375
  a = Automobile.new
372
376
  a.make = 'Ford'
373
- assert_equal "{\"make\":\"Ford\"}", a.characteristics.to_json
377
+ assert_nothing_raised do
378
+ a.characteristics.to_json
379
+ end
374
380
  end
375
381
 
376
382
  should 'be nice to active_support to_json for snapshots' do
377
383
  a = Automobile.new
378
384
  a.make = 'Ford'
379
- assert_equal "{\"make\":{\"trumps\":[],\"name\":\"make\",\"options\":{},\"prerequisite\":null}}", a.characteristics.effective.to_json
385
+ assert_nothing_raised do
386
+ a.characteristics.effective.to_json
387
+ end
388
+ end
389
+
390
+ should 'raise an exception if #has is called more than once in a single block' do
391
+ assert_raises ::Characterizable::CharacteristicAlreadyDefined do
392
+ class SimpleAutomobile3
393
+ include Characterizable
394
+ attr_accessor :make
395
+ characterize do
396
+ has :make
397
+ has :make
398
+ end
399
+ end
400
+ end
401
+ end
402
+
403
+ should 'raise an exception if #has is called more than once in a subclass' do
404
+ assert_raises ::Characterizable::CharacteristicAlreadyDefined do
405
+ class SimpleAutomobile2 < SimpleAutomobile
406
+ include Characterizable
407
+ characterize do
408
+ has :make
409
+ end
410
+ end
411
+ end
380
412
  end
381
413
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: characterizable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 11
10
- version: 0.0.11
9
+ - 12
10
+ version: 0.0.12
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andy Rossmeissl
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-07-16 00:00:00 -05:00
19
+ date: 2010-07-21 00:00:00 -05:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -65,7 +65,7 @@ dependencies:
65
65
  - 0
66
66
  - 1
67
67
  version: 0.0.1
68
- type: :runtime
68
+ type: :development
69
69
  version_requirements: *id003
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: shoulda