dm-is-read_only 0.1.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.
- data/.gitignore +11 -0
- data/.specopts +1 -0
- data/.yardopts +1 -0
- data/ChangeLog.md +9 -0
- data/Gemfile +97 -0
- data/LICENSE.txt +21 -0
- data/README.md +85 -0
- data/Rakefile +36 -0
- data/VERSION +1 -0
- data/dm-is-read_only.gemspec +76 -0
- data/lib/dm-is-read_only/is/read_only.rb +84 -0
- data/lib/dm-is-read_only.rb +4 -0
- data/spec/classes/backend_model.rb +15 -0
- data/spec/classes/read_only_model.rb +15 -0
- data/spec/integration/read_only_spec.rb +83 -0
- data/spec/spec_helper.rb +22 -0
- metadata +160 -0
data/.gitignore
ADDED
data/.specopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour --format specdoc
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--markup markdown --title 'dm-is-read_only Documentation' --protected --files ChangeLog.md,LICENSE.txt
|
data/ChangeLog.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
### 0.1.0 / 2010-06-08
|
2
|
+
|
3
|
+
* Initial release.
|
4
|
+
* Ignores auto-migrations on read-only Models.
|
5
|
+
* Ignores auto-upgrades on read-only Models.
|
6
|
+
* Puts all resources of a read-only Model into the Immutable state.
|
7
|
+
* Supports the `:migrations` and `:mutable` options for selectively enabling
|
8
|
+
migrations or mutability.
|
9
|
+
|
data/Gemfile
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
dm = 'git://github.com/datamapper'
|
3
|
+
|
4
|
+
group :runtime do
|
5
|
+
# We bundle both AS and extlib while extlib compatibility needs to be kept
|
6
|
+
# around. require 'dm-core' will ensure that only one is activated at any
|
7
|
+
# time though. This is done by trying to require AS components and
|
8
|
+
# fallback to requiring extlib in case a LoadError was rescued when
|
9
|
+
# requiring AS code.
|
10
|
+
#
|
11
|
+
# Due to bundle exec activating all groups in the Gemfile, it's
|
12
|
+
# recommended to run
|
13
|
+
#
|
14
|
+
# bundle install --without quality
|
15
|
+
#
|
16
|
+
# to have a development environment that is able to run the specs.
|
17
|
+
# The problem is that metric_fu activates active_support=2.2.3 if we
|
18
|
+
# comment out the gem 'activesupport' declaration - have a look below for
|
19
|
+
# why we would want to do that (and a bit later, for why that's actually
|
20
|
+
# not *strictly* necessary, but recommended)
|
21
|
+
#
|
22
|
+
# To run the specs using AS, leave this Gemfile as it is and just run:
|
23
|
+
#
|
24
|
+
# bundle install --without qality
|
25
|
+
# ADAPTERS=sqlite3 bundle exec rake spec # or whatever adapter
|
26
|
+
#
|
27
|
+
# To run the specs using extlib, comment out the: gem 'activesupport' line
|
28
|
+
# and run:
|
29
|
+
#
|
30
|
+
# bundle install --without quality
|
31
|
+
# ADAPTERS=sqlite3 bundle exec rake spec # or whatever adapter
|
32
|
+
#
|
33
|
+
# If you want to run the quality tasks as provided by metric_fu and
|
34
|
+
# related gems, you have to run:
|
35
|
+
#
|
36
|
+
# bundle install
|
37
|
+
# bundle exec rake metrics:all
|
38
|
+
#
|
39
|
+
# Switch back to a bundle without quality gems before trying to run the
|
40
|
+
# specs again:
|
41
|
+
#
|
42
|
+
# bundle install --without quality
|
43
|
+
# ADAPTERS=sqlite3 bundle exec rake spec # or whatever adapter
|
44
|
+
#
|
45
|
+
# It was mentioned above that all this is not *strictly* necessary, and
|
46
|
+
# this is true. Currently dm-core does the following as the first require
|
47
|
+
# when checking for AS:
|
48
|
+
#
|
49
|
+
# require 'active_support/core_ext/object/singleton_class'
|
50
|
+
#
|
51
|
+
# Because this method is not present in activesupport <= 3.0.0.beta,
|
52
|
+
# dm-core's feature detection will actually do the "right thing" and fall
|
53
|
+
# back to extlib. However, since this is not the case for all dm-more gems
|
54
|
+
# as well, the safest thing to do is to respect the more tedious workflow
|
55
|
+
# for now, as it will at least be guaranteed to work the same for both
|
56
|
+
# dm-core and dm-more.
|
57
|
+
#
|
58
|
+
# Note that this won't be an issue anymore once we dropped support for
|
59
|
+
# extlib completely, or bundler folks decide to support something like
|
60
|
+
# "bundle exec --without=foo rake spec" (which probably is not going to
|
61
|
+
# happen anytime soon).
|
62
|
+
#
|
63
|
+
|
64
|
+
if ENV['EXTLIB']
|
65
|
+
gem 'extlib', '~> 0.9.15'
|
66
|
+
else
|
67
|
+
gem 'activesupport', '~> 3.0.0.beta3', :require => 'active_support'
|
68
|
+
end
|
69
|
+
|
70
|
+
gem 'dm-core', '~> 1.0.0'
|
71
|
+
end
|
72
|
+
|
73
|
+
group :development do
|
74
|
+
gem 'rake', '~> 0.8.7'
|
75
|
+
gem 'jeweler', '~> 1.4.0', :git => 'git://github.com/technicalpickles/jeweler.git'
|
76
|
+
end
|
77
|
+
|
78
|
+
group :doc do
|
79
|
+
case RUBY_PLATFORM
|
80
|
+
when 'java'
|
81
|
+
gem 'maruku', '~> 0.6.0'
|
82
|
+
else
|
83
|
+
gem 'rdiscount', '~> 1.6.3'
|
84
|
+
end
|
85
|
+
|
86
|
+
gem 'yard', '~> 0.5.3'
|
87
|
+
end
|
88
|
+
|
89
|
+
group :test do
|
90
|
+
gem 'data_objects', '~> 0.10.2'
|
91
|
+
gem 'do_sqlite3', '~> 0.10.2'
|
92
|
+
gem 'dm-do-adapter', '~> 1.0.0'
|
93
|
+
gem 'dm-sqlite-adapter', '~> 1.0.0'
|
94
|
+
gem 'dm-migrations', '~> 1.0.0'
|
95
|
+
end
|
96
|
+
|
97
|
+
gem 'rspec', '~> 1.3.0', :group => [:development, :test]
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
Copyright (c) 2010 Hal Brodigan
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# dm-is-read_only
|
2
|
+
|
3
|
+
* [github.com/postmodern/dm-is-read_only](http://github.com/postmodern/dm-is-read_only)
|
4
|
+
* [github.com/postmodern/dm-is-read_only/issues](http://github.com/postmodern/dm-is-read_only/issues)
|
5
|
+
* Postmodern (postmodern.mod3 at gmail.com)
|
6
|
+
|
7
|
+
## Description
|
8
|
+
|
9
|
+
A DataMapper plugin for making Models absolutely **read-only**.
|
10
|
+
|
11
|
+
## Features
|
12
|
+
|
13
|
+
* Ignores auto-migrations on read-only Models.
|
14
|
+
* Ignores auto-upgrades on read-only Models.
|
15
|
+
* Puts all resources of a read-only Model into the Immutable state.
|
16
|
+
* Supports the `:migrations` and `:mutable` options for selectively enabling
|
17
|
+
migrations or mutability.
|
18
|
+
|
19
|
+
## Example
|
20
|
+
|
21
|
+
require 'dm-core'
|
22
|
+
require 'dm-is-read_only'
|
23
|
+
|
24
|
+
class Licence
|
25
|
+
|
26
|
+
include DataMapper::Resource
|
27
|
+
|
28
|
+
is :read_only
|
29
|
+
|
30
|
+
# The primary-key of the License
|
31
|
+
property :id, Serial
|
32
|
+
|
33
|
+
# Name of the Licence
|
34
|
+
property :name, String
|
35
|
+
|
36
|
+
# URL to the licence
|
37
|
+
property :url, String
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
Licence.first
|
42
|
+
# => #<Licence: id: 1, name: "GPL-2", url: "http://www.gnu.org/copyleft/gpl.html">
|
43
|
+
|
44
|
+
# ignores auto-migrations
|
45
|
+
License.auto_migrate!
|
46
|
+
# => true
|
47
|
+
|
48
|
+
Licence.first
|
49
|
+
# => #<Licence: id: 1, name: "GPL-2", url: "http://www.gnu.org/copyleft/gpl.html">
|
50
|
+
|
51
|
+
# ignores auto-upgrades
|
52
|
+
License.auto_upgrade!
|
53
|
+
# => true
|
54
|
+
|
55
|
+
license = Licence.first
|
56
|
+
# => #<Licence: id: 1, name: "GPL-2", url: "http://www.gnu.org/copyleft/gpl.html">
|
57
|
+
|
58
|
+
license.name = 'WTF'
|
59
|
+
license.save!
|
60
|
+
# => true
|
61
|
+
|
62
|
+
# will not allow saving resources
|
63
|
+
license.reload
|
64
|
+
license.name
|
65
|
+
# => "GPL-2"
|
66
|
+
|
67
|
+
license.destroy!
|
68
|
+
# => true
|
69
|
+
|
70
|
+
# will not allow destroying resources
|
71
|
+
license = License.first
|
72
|
+
# => #<Licence: id: 1, name: "GPL-2", url: "http://www.gnu.org/copyleft/gpl.html">
|
73
|
+
|
74
|
+
## Requirements
|
75
|
+
|
76
|
+
* [dm-core](http://github.com/datamapper/dm-core/) ~> 1.0.0
|
77
|
+
|
78
|
+
## Install
|
79
|
+
|
80
|
+
$ sudo gem install dm-is-read_only
|
81
|
+
|
82
|
+
## License
|
83
|
+
|
84
|
+
See {file:LICENSE.txt} for license information.
|
85
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
begin
|
5
|
+
Bundler.setup(:development, :doc)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
STDERR.puts e.message
|
8
|
+
STDERR.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'rake'
|
13
|
+
require 'jeweler'
|
14
|
+
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
gem.name = 'dm-is-read_only'
|
17
|
+
gem.license = 'MIT'
|
18
|
+
gem.summary = %Q{A DataMapper plugin for making Models absolutely read-only.}
|
19
|
+
gem.description = %Q{A DataMapper plugin for making Models absolutely read-only.}
|
20
|
+
gem.email = 'postmodern.mod3@gmail.com'
|
21
|
+
gem.homepage = 'http://github.com/postmodern/dm-is-read_only'
|
22
|
+
gem.authors = ['Postmodern']
|
23
|
+
gem.has_rdoc = 'yard'
|
24
|
+
end
|
25
|
+
|
26
|
+
require 'spec/rake/spectask'
|
27
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
28
|
+
spec.libs += ['lib', 'spec']
|
29
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
30
|
+
spec.spec_opts = ['--options', '.specopts']
|
31
|
+
end
|
32
|
+
|
33
|
+
task :default => :spec
|
34
|
+
|
35
|
+
require 'yard'
|
36
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{dm-is-read_only}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Postmodern"]
|
12
|
+
s.date = %q{2010-06-10}
|
13
|
+
s.description = %q{A DataMapper plugin for making Models absolutely read-only.}
|
14
|
+
s.email = %q{postmodern.mod3@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"ChangeLog.md",
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.md"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".gitignore",
|
22
|
+
".specopts",
|
23
|
+
".yardopts",
|
24
|
+
"ChangeLog.md",
|
25
|
+
"Gemfile",
|
26
|
+
"LICENSE.txt",
|
27
|
+
"README.md",
|
28
|
+
"Rakefile",
|
29
|
+
"VERSION",
|
30
|
+
"dm-is-read_only.gemspec",
|
31
|
+
"lib/dm-is-read_only.rb",
|
32
|
+
"lib/dm-is-read_only/is/read_only.rb",
|
33
|
+
"spec/classes/backend_model.rb",
|
34
|
+
"spec/classes/read_only_model.rb",
|
35
|
+
"spec/integration/read_only_spec.rb",
|
36
|
+
"spec/spec_helper.rb"
|
37
|
+
]
|
38
|
+
s.has_rdoc = %q{yard}
|
39
|
+
s.homepage = %q{http://github.com/postmodern/dm-is-read_only}
|
40
|
+
s.licenses = ["MIT"]
|
41
|
+
s.require_paths = ["lib"]
|
42
|
+
s.rubygems_version = %q{1.3.7}
|
43
|
+
s.summary = %q{A DataMapper plugin for making Models absolutely read-only.}
|
44
|
+
s.test_files = [
|
45
|
+
"spec/classes/backend_model.rb",
|
46
|
+
"spec/classes/read_only_model.rb",
|
47
|
+
"spec/integration/read_only_spec.rb",
|
48
|
+
"spec/spec_helper.rb"
|
49
|
+
]
|
50
|
+
|
51
|
+
if s.respond_to? :specification_version then
|
52
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
53
|
+
s.specification_version = 3
|
54
|
+
|
55
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
56
|
+
s.add_runtime_dependency(%q<activesupport>, ["~> 3.0.0.beta3"])
|
57
|
+
s.add_runtime_dependency(%q<dm-core>, ["~> 1.0.0"])
|
58
|
+
s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
|
59
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.4.0"])
|
60
|
+
s.add_development_dependency(%q<rspec>, ["~> 1.3.0"])
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<activesupport>, ["~> 3.0.0.beta3"])
|
63
|
+
s.add_dependency(%q<dm-core>, ["~> 1.0.0"])
|
64
|
+
s.add_dependency(%q<rake>, ["~> 0.8.7"])
|
65
|
+
s.add_dependency(%q<jeweler>, ["~> 1.4.0"])
|
66
|
+
s.add_dependency(%q<rspec>, ["~> 1.3.0"])
|
67
|
+
end
|
68
|
+
else
|
69
|
+
s.add_dependency(%q<activesupport>, ["~> 3.0.0.beta3"])
|
70
|
+
s.add_dependency(%q<dm-core>, ["~> 1.0.0"])
|
71
|
+
s.add_dependency(%q<rake>, ["~> 0.8.7"])
|
72
|
+
s.add_dependency(%q<jeweler>, ["~> 1.4.0"])
|
73
|
+
s.add_dependency(%q<rspec>, ["~> 1.3.0"])
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module DataMapper
|
2
|
+
module Is
|
3
|
+
module ReadOnly
|
4
|
+
#
|
5
|
+
# Makes a Model and all resources of the model, read-only.
|
6
|
+
#
|
7
|
+
# @param [Hash] options
|
8
|
+
# Additional options.
|
9
|
+
#
|
10
|
+
# @option options [Boolean] :migrations
|
11
|
+
# Specifies that migrations should be left enabled.
|
12
|
+
#
|
13
|
+
# @option options [Boolean] :mutable
|
14
|
+
# Specifies that the resource should remain mutable.
|
15
|
+
#
|
16
|
+
# @example Disable both migrations and mutability
|
17
|
+
# is :read_only
|
18
|
+
#
|
19
|
+
# @example Do not disable migrations
|
20
|
+
# is :read_only, :migrations => true
|
21
|
+
#
|
22
|
+
# @example Do not disable mutability
|
23
|
+
# is :read_only, :mutable => true
|
24
|
+
#
|
25
|
+
def is_read_only(options={})
|
26
|
+
unless options[:migrations]
|
27
|
+
extend DataMapper::Is::ReadOnly::ClassMethods
|
28
|
+
end
|
29
|
+
|
30
|
+
unless options[:mutable]
|
31
|
+
include DataMapper::Is::ReadOnly::InstanceMethods
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
module ClassMethods
|
36
|
+
#
|
37
|
+
# Disables auto-migrations.
|
38
|
+
#
|
39
|
+
# @return [true]
|
40
|
+
# Always returns `true`.
|
41
|
+
#
|
42
|
+
def auto_migrate!(repository_name=nil)
|
43
|
+
return true
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# Disables auto-upgrades.
|
48
|
+
#
|
49
|
+
# @return [true]
|
50
|
+
# Always returns `true`.
|
51
|
+
#
|
52
|
+
def auto_upgrade!(repository_name=nil)
|
53
|
+
return true
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
module InstanceMethods
|
58
|
+
#
|
59
|
+
# Overrides the default `persisted_state` method, to always use
|
60
|
+
# `DataMapper::Resource::State::Immutable`.
|
61
|
+
#
|
62
|
+
# @return [DataMapper::Resource::State::Immutable]
|
63
|
+
# The immutable state.
|
64
|
+
#
|
65
|
+
def persisted_state
|
66
|
+
@_state ||= Resource::State::Immutable.new(self)
|
67
|
+
end
|
68
|
+
|
69
|
+
#
|
70
|
+
# Prevents the persistence state from forcibly being changed.
|
71
|
+
#
|
72
|
+
# @param [DataMapper::Resource::State] new_state
|
73
|
+
# The new state to use.
|
74
|
+
#
|
75
|
+
# @return [DataMapper::Resource::State::Immutabe]
|
76
|
+
# Always returns the immutable state.
|
77
|
+
#
|
78
|
+
def persisted_state=(new_state)
|
79
|
+
persisted_state
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'classes/backend_model'
|
4
|
+
require 'classes/read_only_model'
|
5
|
+
|
6
|
+
describe DataMapper::Is::ReadOnly do
|
7
|
+
context "auto_migrate!" do
|
8
|
+
before(:all) do
|
9
|
+
BackendModel.auto_migrate!
|
10
|
+
|
11
|
+
('a'..'z').each do |value|
|
12
|
+
BackendModel.create(:value => value)
|
13
|
+
end
|
14
|
+
|
15
|
+
ReadOnlyModel.auto_migrate!
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should not destroy the contents of the storage table" do
|
19
|
+
ReadOnlyModel.all.length.should == 26
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should still return true" do
|
23
|
+
(ReadOnlyModel.auto_migrate!).should == true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "auto_upgrade!" do
|
28
|
+
end
|
29
|
+
|
30
|
+
context "immutable" do
|
31
|
+
before(:all) do
|
32
|
+
BackendModel.auto_migrate!
|
33
|
+
BackendModel.create(:value => 'x')
|
34
|
+
|
35
|
+
@resource = ReadOnlyModel.first(:value => 'x')
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should prevent modifying properties" do
|
39
|
+
lambda {
|
40
|
+
@resource.value = 'z'
|
41
|
+
}.should raise_error()
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should prevent calling save" do
|
45
|
+
lambda {
|
46
|
+
@resource.save
|
47
|
+
}.should raise_error()
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should prevent calling save!" do
|
51
|
+
lambda {
|
52
|
+
@resource.save!
|
53
|
+
}.should raise_error()
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should prevent calling destroy" do
|
57
|
+
@resource.destroy
|
58
|
+
|
59
|
+
original = BackendModel.first(:value => 'x')
|
60
|
+
original.should_not be_nil
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should prevent calling destroy!" do
|
64
|
+
@resource.destroy!
|
65
|
+
|
66
|
+
original = BackendModel.first(:value => 'x')
|
67
|
+
original.should_not be_nil
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should have an Immutable persisted state" do
|
71
|
+
@resource.persisted_state.class.should == DataMapper::Resource::State::Immutable
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should prevent forcibly changing the persisted state" do
|
75
|
+
old_state = @resource.persisted_state
|
76
|
+
|
77
|
+
new_state = DataMapper::Resource::State::Transient.new(@resource)
|
78
|
+
@resource.persisted_state = new_state
|
79
|
+
|
80
|
+
@resource.persisted_state.should == old_state
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
begin
|
5
|
+
Bundler.setup(:runtime, :test)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
STDERR.puts e.message
|
8
|
+
STDERR.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'spec'
|
13
|
+
require 'dm-core/spec/setup'
|
14
|
+
require 'dm-core/spec/lib/adapter_helpers'
|
15
|
+
|
16
|
+
require 'dm-is-read_only'
|
17
|
+
|
18
|
+
DataMapper::Spec.setup
|
19
|
+
|
20
|
+
Spec::Runner.configure do |config|
|
21
|
+
config.extend(DataMapper::Spec::Adapters::Helpers)
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dm-is-read_only
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Postmodern
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-06-10 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: activesupport
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 3
|
29
|
+
- 0
|
30
|
+
- 0
|
31
|
+
- beta3
|
32
|
+
version: 3.0.0.beta3
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: dm-core
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 1
|
45
|
+
- 0
|
46
|
+
- 0
|
47
|
+
version: 1.0.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: rake
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ~>
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
- 8
|
61
|
+
- 7
|
62
|
+
version: 0.8.7
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: *id003
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
name: jeweler
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ~>
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
segments:
|
74
|
+
- 1
|
75
|
+
- 4
|
76
|
+
- 0
|
77
|
+
version: 1.4.0
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *id004
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: rspec
|
83
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ~>
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
segments:
|
89
|
+
- 1
|
90
|
+
- 3
|
91
|
+
- 0
|
92
|
+
version: 1.3.0
|
93
|
+
type: :development
|
94
|
+
prerelease: false
|
95
|
+
version_requirements: *id005
|
96
|
+
description: A DataMapper plugin for making Models absolutely read-only.
|
97
|
+
email: postmodern.mod3@gmail.com
|
98
|
+
executables: []
|
99
|
+
|
100
|
+
extensions: []
|
101
|
+
|
102
|
+
extra_rdoc_files:
|
103
|
+
- ChangeLog.md
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.md
|
106
|
+
files:
|
107
|
+
- .gitignore
|
108
|
+
- .specopts
|
109
|
+
- .yardopts
|
110
|
+
- ChangeLog.md
|
111
|
+
- Gemfile
|
112
|
+
- LICENSE.txt
|
113
|
+
- README.md
|
114
|
+
- Rakefile
|
115
|
+
- VERSION
|
116
|
+
- dm-is-read_only.gemspec
|
117
|
+
- lib/dm-is-read_only.rb
|
118
|
+
- lib/dm-is-read_only/is/read_only.rb
|
119
|
+
- spec/classes/backend_model.rb
|
120
|
+
- spec/classes/read_only_model.rb
|
121
|
+
- spec/integration/read_only_spec.rb
|
122
|
+
- spec/spec_helper.rb
|
123
|
+
has_rdoc: yard
|
124
|
+
homepage: http://github.com/postmodern/dm-is-read_only
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
none: false
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
hash: -649568781
|
138
|
+
segments:
|
139
|
+
- 0
|
140
|
+
version: "0"
|
141
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
+
none: false
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
segments:
|
147
|
+
- 0
|
148
|
+
version: "0"
|
149
|
+
requirements: []
|
150
|
+
|
151
|
+
rubyforge_project:
|
152
|
+
rubygems_version: 1.3.7
|
153
|
+
signing_key:
|
154
|
+
specification_version: 3
|
155
|
+
summary: A DataMapper plugin for making Models absolutely read-only.
|
156
|
+
test_files:
|
157
|
+
- spec/classes/backend_model.rb
|
158
|
+
- spec/classes/read_only_model.rb
|
159
|
+
- spec/integration/read_only_spec.rb
|
160
|
+
- spec/spec_helper.rb
|