mongo_mapper-strict_keys 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ require 'mongo_mapper/strict_keys'
2
+
3
+ MongoMapper::Document.plugin(MongoMapper::Plugins::StrictKeys)
4
+ MongoMapper::EmbeddedDocument.plugin(MongoMapper::Plugins::StrictKeys)
@@ -1,7 +1,7 @@
1
1
  module MongoMapper
2
2
  module Plugins
3
3
  module StrictKeys
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
6
6
  end
7
7
  end
@@ -11,7 +11,6 @@ module MongoMapper
11
11
 
12
12
  module InstanceMethods
13
13
  def ensure_key_exists(name)
14
- # Do nothing.
15
14
  unless respond_to?("#{name}=")
16
15
  raise ArgumentError.new("Attribute #{name} has not been explicitly defined as a key.")
17
16
  end
@@ -0,0 +1,50 @@
1
+ require File.expand_path("../spec_helper", File.dirname(__FILE__))
2
+
3
+ require 'mongo_mapper/strict_keys/force_plugin'
4
+
5
+ describe 'MongoMapper::Plugins::StrictKeys -- Forced Plugin' do
6
+ class ForcedModel
7
+ include MongoMapper::Document
8
+
9
+ key :string_key, String
10
+ end
11
+
12
+ describe 'Instance attributes' do
13
+ before(:each) do
14
+ @fm = ForcedModel.new
15
+ end
16
+
17
+ context 'attributes-as-methods' do
18
+ it 'should accept attributes-as-methods for pre-defined keys' do
19
+ lambda {
20
+ @fm.string_key = "I work!"
21
+ }.should_not raise_error
22
+
23
+ @fm.string_key.should == "I work!"
24
+ end
25
+
26
+ it 'should reject attributes-as-methods for never-defined keys' do
27
+ lambda {
28
+ @fm.not_defined = 'blowed up'
29
+ }.should raise_error(NoMethodError)
30
+ end
31
+ end
32
+
33
+ context 'attributes-in-brackets' do
34
+ it 'should accept attributes-in-brackets for pre-defined keys' do
35
+ lambda {
36
+ @fm[:string_key] = "I work!"
37
+ }.should_not raise_error
38
+
39
+ @fm[:string_key].should == "I work!"
40
+ end
41
+
42
+ it 'should reject attributes-in-brackets for never-defined keys' do
43
+ lambda {
44
+ @fm[:not_defined] = 'blowed up'
45
+ }.should raise_error(ArgumentError)
46
+ end
47
+ end
48
+
49
+ end
50
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Scott Gonyea
@@ -102,8 +102,10 @@ files:
102
102
  - Rakefile
103
103
  - lib/mongo_mapper-strict_keys.rb
104
104
  - lib/mongo_mapper/strict_keys.rb
105
+ - lib/mongo_mapper/strict_keys/force_plugin.rb
105
106
  - lib/mongo_mapper/strict_keys/version.rb
106
107
  - mongo_mapper-strict_keys.gemspec
108
+ - spec/mongo_mapper/force_plugin_spec.rb
107
109
  - spec/mongo_mapper/strict_keys_spec.rb
108
110
  - spec/spec_helper.rb
109
111
  has_rdoc: true
@@ -139,5 +141,6 @@ signing_key:
139
141
  specification_version: 3
140
142
  summary: Mongo Mapper Strict Keys Plugin
141
143
  test_files:
144
+ - spec/mongo_mapper/force_plugin_spec.rb
142
145
  - spec/mongo_mapper/strict_keys_spec.rb
143
146
  - spec/spec_helper.rb