dm-is-read_only 0.2.1 → 0.3.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/ChangeLog.md +10 -2
- data/Gemfile +52 -105
- data/LICENSE.txt +1 -1
- data/README.md +2 -2
- data/Rakefile +4 -4
- data/dm-is-read_only.gemspec +125 -13
- data/gemspec.yml +3 -3
- data/lib/dm-is-read_only/is/read_only/exceptions/error.rb +11 -0
- data/lib/dm-is-read_only/is/read_only/exceptions.rb +1 -0
- data/lib/dm-is-read_only/{resource/state/read_only.rb → is/read_only/state.rb} +6 -6
- data/lib/dm-is-read_only/is/read_only.rb +13 -9
- data/spec/classes/read_only_model.rb +1 -0
- data/spec/integration/read_only_spec.rb +25 -43
- data/spec/spec_helper.rb +12 -0
- metadata +48 -51
- data/lib/dm-is-read_only/exceptions/read_only_error.rb +0 -4
data/.gitignore
ADDED
data/ChangeLog.md
CHANGED
@@ -1,12 +1,20 @@
|
|
1
|
+
### 0.3.0 / 2012-02-17
|
2
|
+
|
3
|
+
* Require dm-core ~> 1.2.
|
4
|
+
* Replaced `DataMapper::Resource::State::ReadOnly` with
|
5
|
+
`DataMapper::Is::ReadOnly::State`.
|
6
|
+
* Replaced `DataMapper::ReadOnlyError` with
|
7
|
+
`DataMapper::Is::ReadOnly::Error`.
|
8
|
+
|
1
9
|
### 0.2.1 / 2011-03-23
|
2
10
|
|
3
11
|
* Require dm-core ~> 1.0.
|
4
12
|
|
5
13
|
### 0.2.0 / 2010-11-05
|
6
14
|
|
7
|
-
* Added
|
15
|
+
* Added `DataMapper::Resource::State::ReadOnly`:
|
8
16
|
* Inherits from the `Clean` state.
|
9
|
-
* Raises
|
17
|
+
* Raises `DataMapper::ReadOnlyError` exceptions when `set` or `delete`
|
10
18
|
are called.
|
11
19
|
* Fixed a bug where read-only resources with relationships were not being
|
12
20
|
loaded.
|
data/Gemfile
CHANGED
@@ -1,134 +1,81 @@
|
|
1
|
-
# If you're working on more than one datamapper gem at a time, then it's
|
2
|
-
# recommended to create a local Gemfile and use this instead of the git
|
3
|
-
# sources. This will make sure that you are developing against your
|
4
|
-
# other local datamapper sources that you currently work on. Gemfile.local
|
5
|
-
# will behave identically to the standard Gemfile apart from the fact that
|
6
|
-
# it fetches the datamapper gems from local paths. This means that you can
|
7
|
-
# use the same environment variables, like ADAPTER(S) or PLUGIN(S) when
|
8
|
-
# running
|
9
|
-
# bundle commands. Gemfile.local is added to .gitignore, so you don't need
|
10
|
-
# to worry about accidentally checking local development paths into git.
|
11
|
-
# In order to create a local Gemfile, all you need to do is run:
|
12
1
|
#
|
13
|
-
#
|
2
|
+
# Environment Variables:
|
14
3
|
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
4
|
+
# DM_EDGE - Bundle against the DataMapper git repositories at
|
5
|
+
# http://github.com/datamapper
|
6
|
+
# DM_BRANCH - The branch to use across all DataMapper git repositories.
|
7
|
+
# DM_ROOT - The path to the directory containing local copies of the DataMapper
|
8
|
+
# libraries.
|
9
|
+
# ADAPTER(S) - The list of DataMapper adapters to test with.
|
10
|
+
# (sqlite, postgres, mysql, oracle, sqlserver)
|
11
|
+
# PLUGIN(S) - The list of additional DataMapper plugins to test with.
|
19
12
|
#
|
20
|
-
# BUNDLE_GEMFILE=Gemfile.local bundle foo
|
21
|
-
#
|
22
|
-
# You can also specify which adapter(s) should be part of the bundle by
|
23
|
-
# setting an environment variable. This of course also works when using the
|
24
|
-
# Gemfile.local
|
25
|
-
#
|
26
|
-
# bundle foo # dm-sqlite-adapter
|
27
|
-
#
|
28
|
-
# ADAPTER=mysql bundle foo # dm-mysql-adapter
|
29
|
-
#
|
30
|
-
# ADAPTERS=sqlite,mysql bundle foo # dm-sqlite-adapter, dm-mysql-adapter
|
31
|
-
#
|
32
|
-
# Of course you can also use the ADAPTER(S) variable when using the
|
33
|
-
# Gemfile.local and running specs against selected adapters.
|
34
|
-
#
|
35
|
-
# For easily working with adapters supported on your machine, it's
|
36
|
-
# recommended that you first install all adapters that you are planning to
|
37
|
-
# use or work on by doing something like
|
38
|
-
#
|
39
|
-
# ADAPTERS=sqlite,mysql,postgres bundle install
|
40
|
-
#
|
41
|
-
# This will clone the various repositories and make them available to
|
42
|
-
# bundler. Once you have them installed you can easily switch between
|
43
|
-
# adapters for the various development tasks. Running something like
|
44
|
-
#
|
45
|
-
# ADAPTER=mysql bundle exec rake spec
|
46
|
-
#
|
47
|
-
# will make sure that the dm-mysql-adapter is part of the bundle, and will
|
48
|
-
# be used when running the specs.
|
49
|
-
#
|
50
|
-
# You can also specify which plugin(s) should be part of the bundle by
|
51
|
-
# setting an environment variable. This also works when using the
|
52
|
-
# Gemfile.local
|
53
|
-
#
|
54
|
-
# bundle foo # dm-migrations
|
55
|
-
#
|
56
|
-
# PLUGINS=dm-validations bundle foo # dm-migrations,
|
57
|
-
# # dm-validations
|
58
|
-
#
|
59
|
-
# PLUGINS=dm-validations,dm-types bundle foo # dm-migrations,
|
60
|
-
# # dm-validations,
|
61
|
-
# # dm-types
|
62
|
-
#
|
63
|
-
# Of course you can combine the PLUGIN(S) and ADAPTER(S) env vars to run
|
64
|
-
# specs for certain adapter/plugin combinations.
|
65
|
-
#
|
66
|
-
# Finally, to speed up running specs and other tasks, it's recommended to
|
67
|
-
# run
|
68
|
-
#
|
69
|
-
# bundle lock
|
70
|
-
#
|
71
|
-
# after running 'bundle install' for the first time. This will make
|
72
|
-
# 'bundle exec' run a lot faster compared to the unlocked version. With an
|
73
|
-
# unlocked bundle you would typically just run 'bundle install' from time
|
74
|
-
# to time to fetch the latest sources from upstream. When you locked your
|
75
|
-
# bundle, you need to run
|
76
|
-
#
|
77
|
-
# bundle install --relock
|
78
|
-
#
|
79
|
-
# to make sure to fetch the latest updates and then lock the bundle again.
|
80
|
-
# Gemfile.lock is added to the .gitignore file, so you don't need to worry
|
81
|
-
# about accidentally checking it into version control.
|
82
13
|
|
83
14
|
source :rubygems
|
84
15
|
|
85
|
-
|
86
|
-
DM_VERSION = '~> 1.1'
|
87
|
-
DO_VERSION = '~> 0.10.2'
|
88
|
-
DM_DO_ADAPTERS = %w[ sqlite postgres mysql oracle sqlserver ]
|
89
|
-
RAILS = 'http://github.com/rails/rails.git'
|
16
|
+
gemspec
|
90
17
|
|
91
|
-
|
18
|
+
if ENV['DM_EDGE']
|
19
|
+
SOURCE = :git
|
20
|
+
DM_URI = 'http://github.com/datamapper'
|
21
|
+
DM_BRANCH = ENV.fetch('DM_BRANCH', 'master')
|
22
|
+
elsif ENV['DM_ROOT']
|
23
|
+
SOURCE = :path
|
24
|
+
DM_ROOT = File.expand_path(ENV['DM_ROOT'])
|
25
|
+
else
|
26
|
+
SOURCE = :gem
|
27
|
+
end
|
92
28
|
|
93
|
-
|
94
|
-
|
29
|
+
DM_VERSION = '~> 1.2'
|
30
|
+
DO_VERSION = '~> 0.10.6'
|
31
|
+
DO_ADAPTERS = %w[ sqlite postgres mysql oracle sqlserver ]
|
95
32
|
|
96
|
-
|
97
|
-
|
33
|
+
def dm_gem(name,repo=name)
|
34
|
+
options = case SOURCE
|
35
|
+
when :git
|
36
|
+
{:git => "#{DM_URI}/#{repo}.git", :branch => DM_BRANCH}
|
37
|
+
when :path
|
38
|
+
{:path => "#{DM_ROOT}/#{repo}"}
|
39
|
+
end
|
98
40
|
|
99
|
-
gem
|
100
|
-
|
41
|
+
gem name, DM_VERSION, options
|
42
|
+
end
|
43
|
+
|
44
|
+
def do_gem(name)
|
45
|
+
dm_gem name, 'do'
|
101
46
|
end
|
102
47
|
|
103
48
|
group :datamapper do
|
104
|
-
|
105
|
-
|
49
|
+
|
50
|
+
dm_gem 'dm-core'
|
106
51
|
|
107
52
|
adapters = ENV['ADAPTER'] || ENV['ADAPTERS']
|
108
53
|
adapters = adapters.to_s.tr(',', ' ').split.uniq - %w[ in_memory ]
|
109
54
|
|
110
|
-
if (do_adapters =
|
111
|
-
|
112
|
-
options[:git] = "#{DATAMAPPER}/do.git" if ENV['DO_GIT'] == 'true'
|
113
|
-
|
114
|
-
gem 'data_objects', DO_VERSION, options.dup
|
55
|
+
if (do_adapters = DO_ADAPTERS & adapters).any?
|
56
|
+
do_gem 'data_objects'
|
115
57
|
|
116
58
|
do_adapters.each do |adapter|
|
117
59
|
adapter = 'sqlite3' if adapter == 'sqlite'
|
118
|
-
|
60
|
+
do_gem "do_#{adapter}"
|
119
61
|
end
|
120
62
|
|
121
|
-
|
63
|
+
dm_gem 'dm-do-adapter'
|
122
64
|
end
|
123
65
|
|
124
|
-
adapters.each
|
125
|
-
gem "dm-#{adapter}-adapter", DM_VERSION, :git => "#{DATAMAPPER}/dm-#{adapter}-adapter.git"
|
126
|
-
end
|
66
|
+
adapters.each { |adapter| dm_gem "dm-#{adapter}-adapter" }
|
127
67
|
|
128
68
|
plugins = ENV['PLUGINS'] || ENV['PLUGIN']
|
129
69
|
plugins = plugins.to_s.tr(',', ' ').split.push('dm-migrations').uniq
|
130
70
|
|
131
|
-
plugins.each
|
132
|
-
|
133
|
-
|
71
|
+
plugins.each { |plugin| dm_gem plugin }
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
group :development do
|
76
|
+
gem 'rake', '~> 0.8'
|
77
|
+
gem 'ore-tasks', '~> 0.4'
|
78
|
+
gem 'rspec', '~> 2.4'
|
79
|
+
|
80
|
+
gem 'kramdown', '~> 0.12'
|
134
81
|
end
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -74,7 +74,7 @@ A DataMapper plugin for making Models absolutely **read-only**.
|
|
74
74
|
|
75
75
|
## Requirements
|
76
76
|
|
77
|
-
* [dm-core](http://github.com/datamapper/dm-core/) ~> 1.
|
77
|
+
* [dm-core](http://github.com/datamapper/dm-core/) ~> 1.2
|
78
78
|
|
79
79
|
## Install
|
80
80
|
|
@@ -82,6 +82,6 @@ A DataMapper plugin for making Models absolutely **read-only**.
|
|
82
82
|
|
83
83
|
## License
|
84
84
|
|
85
|
-
Copyright (c) 2010-
|
85
|
+
Copyright (c) 2010-2012 Hal Brodigan
|
86
86
|
|
87
87
|
See {file:LICENSE.txt} for license information.
|
data/Rakefile
CHANGED
@@ -3,16 +3,16 @@ require 'rubygems'
|
|
3
3
|
begin
|
4
4
|
require 'bundler'
|
5
5
|
rescue LoadError => e
|
6
|
-
|
7
|
-
|
6
|
+
warn e.message
|
7
|
+
warn "Run `gem install bundler` to install Bundler."
|
8
8
|
exit e.status_code
|
9
9
|
end
|
10
10
|
|
11
11
|
begin
|
12
12
|
Bundler.setup(:development)
|
13
13
|
rescue Bundler::BundlerError => e
|
14
|
-
|
15
|
-
|
14
|
+
warn e.message
|
15
|
+
warn "Run `bundle install` to install missing gems"
|
16
16
|
exit e.status_code
|
17
17
|
end
|
18
18
|
|
data/dm-is-read_only.gemspec
CHANGED
@@ -1,15 +1,127 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
Gem::Specification.new do |gemspec|
|
6
|
+
files = if File.directory?('.git')
|
7
|
+
`git ls-files`.split($/)
|
8
|
+
elsif File.directory?('.hg')
|
9
|
+
`hg manifest`.split($/)
|
10
|
+
elsif File.directory?('.svn')
|
11
|
+
`svn ls -R`.split($/).select { |path| File.file?(path) }
|
12
|
+
else
|
13
|
+
Dir['{**/}{.*,*}'].select { |path| File.file?(path) }
|
14
|
+
end
|
15
|
+
|
16
|
+
filter_files = lambda { |paths|
|
17
|
+
case paths
|
18
|
+
when Array
|
19
|
+
(files & paths)
|
20
|
+
when String
|
21
|
+
(files & Dir[paths])
|
22
|
+
end
|
23
|
+
}
|
24
|
+
|
25
|
+
version = {
|
26
|
+
:file => 'lib/dm-is-read_only/version.rb',
|
27
|
+
:constant => 'DataMapper::Is::ReadOnly::VERSION'
|
28
|
+
}
|
29
|
+
|
30
|
+
defaults = {
|
31
|
+
'name' => File.basename(File.dirname(__FILE__)),
|
32
|
+
'files' => files,
|
33
|
+
'executables' => filter_files['bin/*'].map { |path| File.basename(path) },
|
34
|
+
'test_files' => filter_files['{test/{**/}*_test.rb,spec/{**/}*_spec.rb}'],
|
35
|
+
'extra_doc_files' => filter_files['*.{txt,rdoc,md,markdown,tt,textile}'],
|
36
|
+
}
|
37
|
+
|
38
|
+
metadata = defaults.merge(YAML.load_file('gemspec.yml'))
|
39
|
+
|
40
|
+
gemspec.name = metadata.fetch('name',defaults[:name])
|
41
|
+
gemspec.version = if metadata['version']
|
42
|
+
metadata['version']
|
43
|
+
elsif File.file?(version[:file])
|
44
|
+
require File.join('.',version[:file])
|
45
|
+
eval(version[:constant])
|
46
|
+
end
|
47
|
+
|
48
|
+
gemspec.summary = metadata.fetch('summary',metadata['description'])
|
49
|
+
gemspec.description = metadata.fetch('description',metadata['summary'])
|
50
|
+
|
51
|
+
case metadata['license']
|
52
|
+
when Array
|
53
|
+
gemspec.licenses = metadata['license']
|
54
|
+
when String
|
55
|
+
gemspec.license = metadata['license']
|
56
|
+
end
|
57
|
+
|
58
|
+
case metadata['authors']
|
59
|
+
when Array
|
60
|
+
gemspec.authors = metadata['authors']
|
61
|
+
when String
|
62
|
+
gemspec.author = metadata['authors']
|
63
|
+
end
|
64
|
+
|
65
|
+
gemspec.email = metadata['email']
|
66
|
+
gemspec.homepage = metadata['homepage']
|
67
|
+
|
68
|
+
case metadata['require_paths']
|
69
|
+
when Array
|
70
|
+
gemspec.require_paths = metadata['require_paths']
|
71
|
+
when String
|
72
|
+
gemspec.require_path = metadata['require_paths']
|
73
|
+
end
|
74
|
+
|
75
|
+
gemspec.files = filter_files[metadata['files']]
|
76
|
+
|
77
|
+
gemspec.executables = metadata['executables']
|
78
|
+
gemspec.extensions = metadata['extensions']
|
79
|
+
|
80
|
+
if Gem::VERSION < '1.7.'
|
81
|
+
gemspec.default_executable = gemspec.executables.first
|
82
|
+
end
|
83
|
+
|
84
|
+
gemspec.test_files = filter_files[metadata['test_files']]
|
85
|
+
|
86
|
+
unless gemspec.files.include?('.document')
|
87
|
+
gemspec.extra_rdoc_files = metadata['extra_doc_files']
|
88
|
+
end
|
89
|
+
|
90
|
+
gemspec.post_install_message = metadata['post_install_message']
|
91
|
+
gemspec.requirements = metadata['requirements']
|
92
|
+
|
93
|
+
if gemspec.respond_to?(:required_ruby_version=)
|
94
|
+
gemspec.required_ruby_version = metadata['required_ruby_version']
|
95
|
+
end
|
96
|
+
|
97
|
+
if gemspec.respond_to?(:required_rubygems_version=)
|
98
|
+
gemspec.required_rubygems_version = metadata['required_rubygems_version']
|
99
|
+
end
|
100
|
+
|
101
|
+
parse_versions = lambda { |versions|
|
102
|
+
case versions
|
103
|
+
when Array
|
104
|
+
versions.map { |v| v.to_s }
|
105
|
+
when String
|
106
|
+
versions.split(/,\s*/)
|
107
|
+
end
|
108
|
+
}
|
109
|
+
|
110
|
+
if metadata['dependencies']
|
111
|
+
metadata['dependencies'].each do |name,versions|
|
112
|
+
gemspec.add_dependency(name,parse_versions[versions])
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
if metadata['runtime_dependencies']
|
117
|
+
metadata['runtime_dependencies'].each do |name,versions|
|
118
|
+
gemspec.add_runtime_dependency(name,parse_versions[versions])
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
if metadata['development_dependencies']
|
123
|
+
metadata['development_dependencies'].each do |name,versions|
|
124
|
+
gemspec.add_development_dependency(name,parse_versions[versions])
|
125
|
+
end
|
14
126
|
end
|
15
127
|
end
|
data/gemspec.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
name: dm-is-read_only
|
2
|
-
version: 0.
|
2
|
+
version: 0.3.0
|
3
3
|
summary: DataMapper plugin for making models absolutely read-only.
|
4
4
|
description:
|
5
5
|
A DataMapper plugin for making models absolutely read-only.
|
@@ -11,8 +11,8 @@ homepage: http://github.com/postmodern/dm-is-read_only
|
|
11
11
|
has_yard: true
|
12
12
|
|
13
13
|
dependencies:
|
14
|
-
dm-core: ~> 1.
|
14
|
+
dm-core: ~> 1.2
|
15
15
|
|
16
16
|
development_dependencies:
|
17
17
|
bundler: ~> 1.0.0
|
18
|
-
yard: ~> 0.
|
18
|
+
yard: ~> 0.7
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'dm-is-read_only/is/read_only/exceptions/error'
|
@@ -1,12 +1,12 @@
|
|
1
|
-
require 'dm-is-read_only/exceptions/
|
1
|
+
require 'dm-is-read_only/is/read_only/exceptions/error'
|
2
2
|
|
3
3
|
module DataMapper
|
4
|
-
module
|
5
|
-
|
4
|
+
module Is
|
5
|
+
module ReadOnly
|
6
6
|
#
|
7
7
|
# A lazy-loaded and unmodifiable resource.
|
8
8
|
#
|
9
|
-
class
|
9
|
+
class State < DataMapper::Resource::PersistenceState::Clean
|
10
10
|
|
11
11
|
#
|
12
12
|
# Receives modifications attempts on a read-only resource.
|
@@ -17,7 +17,7 @@ module DataMapper
|
|
17
17
|
# @since 0.2.0
|
18
18
|
#
|
19
19
|
def set(subject,value)
|
20
|
-
raise(
|
20
|
+
raise(Error,"ReadOnly resource cannot be modified",caller)
|
21
21
|
end
|
22
22
|
|
23
23
|
#
|
@@ -29,7 +29,7 @@ module DataMapper
|
|
29
29
|
# @since 0.2.0
|
30
30
|
#
|
31
31
|
def delete
|
32
|
-
raise(
|
32
|
+
raise(Error,"ReadOnly resource cannot be deleted",caller)
|
33
33
|
end
|
34
34
|
|
35
35
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'dm-is-read_only/
|
1
|
+
require 'dm-is-read_only/is/read_only/state'
|
2
2
|
|
3
3
|
module DataMapper
|
4
4
|
module Is
|
@@ -68,14 +68,16 @@ module DataMapper
|
|
68
68
|
|
69
69
|
module InstanceMethods
|
70
70
|
#
|
71
|
-
# Overrides the default `
|
72
|
-
# {DataMapper::
|
71
|
+
# Overrides the default `persistence_state` method, to always use
|
72
|
+
# {DataMapper::Is::ReadOnly::State}.
|
73
73
|
#
|
74
|
-
# @return [DataMapper::
|
74
|
+
# @return [DataMapper::Is::ReadOnly::State]
|
75
75
|
# The read-only state.
|
76
76
|
#
|
77
|
-
|
78
|
-
|
77
|
+
# @since 0.3.0
|
78
|
+
#
|
79
|
+
def persistence_state
|
80
|
+
@_persistence_state ||= DataMapper::Is::ReadOnly::State.new(self)
|
79
81
|
end
|
80
82
|
|
81
83
|
#
|
@@ -84,11 +86,13 @@ module DataMapper
|
|
84
86
|
# @param [DataMapper::Resource::State] new_state
|
85
87
|
# The new state to use.
|
86
88
|
#
|
87
|
-
# @return [DataMapper::
|
89
|
+
# @return [DataMapper::Is::ReadOnly::State]
|
88
90
|
# Always returns the read-only state.
|
89
91
|
#
|
90
|
-
|
91
|
-
|
92
|
+
# @since 0.3.0
|
93
|
+
#
|
94
|
+
def persistence_state=(new_state)
|
95
|
+
persistence_state
|
92
96
|
end
|
93
97
|
end
|
94
98
|
end
|
@@ -1,42 +1,22 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
require 'classes/backend_model'
|
4
|
-
require 'classes/read_only_model'
|
5
|
-
require 'classes/related_model'
|
6
|
-
|
7
3
|
describe DataMapper::Is::ReadOnly do
|
8
|
-
|
9
|
-
|
10
|
-
BackendModel.auto_migrate!
|
11
|
-
|
12
|
-
('a'..'z').each do |value|
|
13
|
-
BackendModel.create(:value => value)
|
14
|
-
end
|
15
|
-
|
4
|
+
describe "migrate!" do
|
5
|
+
it "should not destroy the contents of the storage table" do
|
16
6
|
ReadOnlyModel.migrate!
|
17
|
-
end
|
18
7
|
|
19
|
-
it "should not destroy the contents of the storage table" do
|
20
8
|
ReadOnlyModel.all.length.should == 26
|
21
9
|
end
|
22
10
|
|
23
11
|
it "should still return true" do
|
24
|
-
(ReadOnlyModel.
|
12
|
+
(ReadOnlyModel.migrate!).should == true
|
25
13
|
end
|
26
14
|
end
|
27
15
|
|
28
|
-
|
29
|
-
|
30
|
-
BackendModel.auto_migrate!
|
31
|
-
|
32
|
-
('a'..'z').each do |value|
|
33
|
-
BackendModel.create(:value => value)
|
34
|
-
end
|
35
|
-
|
16
|
+
describe "auto_migrate!" do
|
17
|
+
it "should not destroy the contents of the storage table" do
|
36
18
|
ReadOnlyModel.auto_migrate!
|
37
|
-
end
|
38
19
|
|
39
|
-
it "should not destroy the contents of the storage table" do
|
40
20
|
ReadOnlyModel.all.length.should == 26
|
41
21
|
end
|
42
22
|
|
@@ -45,15 +25,17 @@ describe DataMapper::Is::ReadOnly do
|
|
45
25
|
end
|
46
26
|
end
|
47
27
|
|
48
|
-
|
28
|
+
describe "auto_upgrade!" do
|
49
29
|
end
|
50
30
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
31
|
+
describe "immutable" do
|
32
|
+
TransientState = if defined?(DataMapper::Resource::PersistenceState)
|
33
|
+
DataMapper::Resource::PersistenceState::Transient
|
34
|
+
else
|
35
|
+
DataMapper::Resource::State::TransientState
|
36
|
+
end
|
56
37
|
|
38
|
+
before(:all) do
|
57
39
|
@resource = ReadOnlyModel.first(:value => 'x')
|
58
40
|
|
59
41
|
RelatedModel.create(:read_only_model => @resource)
|
@@ -61,16 +43,20 @@ describe DataMapper::Is::ReadOnly do
|
|
61
43
|
@related_resource = RelatedModel.first
|
62
44
|
end
|
63
45
|
|
46
|
+
it "should have an ReadOnly persisted state" do
|
47
|
+
@resource.persistence_state.class.should == described_class::State
|
48
|
+
end
|
49
|
+
|
64
50
|
it "should prevent setting properties" do
|
65
51
|
lambda {
|
66
52
|
@resource.value = 'z'
|
67
|
-
}.should raise_error(DataMapper::
|
53
|
+
}.should raise_error(DataMapper::Is::ReadOnly::Error)
|
68
54
|
end
|
69
55
|
|
70
56
|
it "should prevent updating resources" do
|
71
57
|
lambda {
|
72
58
|
@resource.update(:value => 'z')
|
73
|
-
}.should raise_error(DataMapper::
|
59
|
+
}.should raise_error(DataMapper::Is::ReadOnly::Error)
|
74
60
|
end
|
75
61
|
|
76
62
|
it "should mark read-only resources as saved" do
|
@@ -96,26 +82,22 @@ describe DataMapper::Is::ReadOnly do
|
|
96
82
|
it "should prevent calling destroy" do
|
97
83
|
lambda {
|
98
84
|
@resource.destroy
|
99
|
-
}.should raise_error(DataMapper::
|
85
|
+
}.should raise_error(DataMapper::Is::ReadOnly::Error)
|
100
86
|
end
|
101
87
|
|
102
88
|
it "should prevent calling destroy!" do
|
103
89
|
lambda {
|
104
90
|
@resource.destroy!
|
105
|
-
}.should raise_error(DataMapper::
|
106
|
-
end
|
107
|
-
|
108
|
-
it "should have an ReadOnly persisted state" do
|
109
|
-
@resource.persisted_state.class.should == DataMapper::Resource::State::ReadOnly
|
91
|
+
}.should raise_error(DataMapper::Is::ReadOnly::Error)
|
110
92
|
end
|
111
93
|
|
112
94
|
it "should prevent forcibly changing the persisted state" do
|
113
|
-
old_state = @resource.
|
95
|
+
old_state = @resource.persistence_state
|
114
96
|
|
115
|
-
new_state =
|
116
|
-
@resource.
|
97
|
+
new_state = TransientState.new(@resource)
|
98
|
+
@resource.persistence_state = new_state
|
117
99
|
|
118
|
-
@resource.
|
100
|
+
@resource.persistence_state.should == old_state
|
119
101
|
end
|
120
102
|
|
121
103
|
it "should report the resource as having already been saved" do
|
data/spec/spec_helper.rb
CHANGED
@@ -3,9 +3,21 @@ require 'dm-core/spec/setup'
|
|
3
3
|
require 'dm-core/spec/lib/adapter_helpers'
|
4
4
|
|
5
5
|
require 'dm-is-read_only'
|
6
|
+
require 'classes/backend_model'
|
7
|
+
require 'classes/read_only_model'
|
8
|
+
require 'classes/related_model'
|
6
9
|
|
7
10
|
DataMapper::Spec.setup
|
8
11
|
|
9
12
|
RSpec.configure do |config|
|
10
13
|
config.extend(DataMapper::Spec::Adapters::Helpers)
|
14
|
+
|
15
|
+
config.before(:suite) do
|
16
|
+
DataMapper.finalize
|
17
|
+
BackendModel.auto_migrate!
|
18
|
+
|
19
|
+
('a'..'z').each do |value|
|
20
|
+
BackendModel.create(:value => value)
|
21
|
+
end
|
22
|
+
end
|
11
23
|
end
|
metadata
CHANGED
@@ -1,61 +1,59 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-is-read_only
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
4
5
|
prerelease:
|
5
|
-
version: 0.2.1
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Postmodern
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-02-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
17
15
|
name: dm-core
|
18
|
-
requirement: &
|
16
|
+
requirement: &20890100 !ruby/object:Gem::Requirement
|
19
17
|
none: false
|
20
|
-
requirements:
|
18
|
+
requirements:
|
21
19
|
- - ~>
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version:
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.2'
|
24
22
|
type: :runtime
|
25
23
|
prerelease: false
|
26
|
-
version_requirements: *
|
27
|
-
- !ruby/object:Gem::Dependency
|
24
|
+
version_requirements: *20890100
|
25
|
+
- !ruby/object:Gem::Dependency
|
28
26
|
name: bundler
|
29
|
-
requirement: &
|
27
|
+
requirement: &20886460 !ruby/object:Gem::Requirement
|
30
28
|
none: false
|
31
|
-
requirements:
|
29
|
+
requirements:
|
32
30
|
- - ~>
|
33
|
-
- !ruby/object:Gem::Version
|
31
|
+
- !ruby/object:Gem::Version
|
34
32
|
version: 1.0.0
|
35
33
|
type: :development
|
36
34
|
prerelease: false
|
37
|
-
version_requirements: *
|
38
|
-
- !ruby/object:Gem::Dependency
|
35
|
+
version_requirements: *20886460
|
36
|
+
- !ruby/object:Gem::Dependency
|
39
37
|
name: yard
|
40
|
-
requirement: &
|
38
|
+
requirement: &20965380 !ruby/object:Gem::Requirement
|
41
39
|
none: false
|
42
|
-
requirements:
|
40
|
+
requirements:
|
43
41
|
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: 0.
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0.7'
|
46
44
|
type: :development
|
47
45
|
prerelease: false
|
48
|
-
version_requirements: *
|
46
|
+
version_requirements: *20965380
|
49
47
|
description: A DataMapper plugin for making models absolutely read-only.
|
50
|
-
email:
|
51
|
-
- postmodern.mod3@gmail.com
|
48
|
+
email: postmodern.mod3@gmail.com
|
52
49
|
executables: []
|
53
|
-
|
54
50
|
extensions: []
|
55
|
-
|
56
|
-
|
51
|
+
extra_rdoc_files:
|
52
|
+
- ChangeLog.md
|
53
|
+
- LICENSE.txt
|
57
54
|
- README.md
|
58
|
-
files:
|
55
|
+
files:
|
56
|
+
- .gitignore
|
59
57
|
- .rspec
|
60
58
|
- .yardopts
|
61
59
|
- ChangeLog.md
|
@@ -66,41 +64,40 @@ files:
|
|
66
64
|
- dm-is-read_only.gemspec
|
67
65
|
- gemspec.yml
|
68
66
|
- lib/dm-is-read_only.rb
|
69
|
-
- lib/dm-is-read_only/exceptions/read_only_error.rb
|
70
67
|
- lib/dm-is-read_only/is/read_only.rb
|
71
|
-
- lib/dm-is-read_only/
|
68
|
+
- lib/dm-is-read_only/is/read_only/exceptions.rb
|
69
|
+
- lib/dm-is-read_only/is/read_only/exceptions/error.rb
|
70
|
+
- lib/dm-is-read_only/is/read_only/state.rb
|
72
71
|
- spec/classes/backend_model.rb
|
73
72
|
- spec/classes/read_only_model.rb
|
74
73
|
- spec/classes/related_model.rb
|
75
74
|
- spec/integration/read_only_spec.rb
|
76
75
|
- spec/spec_helper.rb
|
77
|
-
has_rdoc: yard
|
78
76
|
homepage: http://github.com/postmodern/dm-is-read_only
|
79
|
-
licenses:
|
77
|
+
licenses:
|
80
78
|
- MIT
|
81
79
|
post_install_message:
|
82
80
|
rdoc_options: []
|
83
|
-
|
84
|
-
require_paths:
|
81
|
+
require_paths:
|
85
82
|
- lib
|
86
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
84
|
none: false
|
88
|
-
requirements:
|
89
|
-
- -
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
version:
|
92
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
90
|
none: false
|
94
|
-
requirements:
|
95
|
-
- -
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
version:
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
98
95
|
requirements: []
|
99
|
-
|
100
|
-
|
101
|
-
rubygems_version: 1.6.2
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 1.8.15
|
102
98
|
signing_key:
|
103
99
|
specification_version: 3
|
104
100
|
summary: DataMapper plugin for making models absolutely read-only.
|
105
|
-
test_files:
|
101
|
+
test_files:
|
106
102
|
- spec/integration/read_only_spec.rb
|
103
|
+
has_rdoc:
|