dm-is-list 0.10.2 → 1.0.0.rc2
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 +36 -0
- data/Gemfile +143 -0
- data/README.rdoc +4 -4
- data/Rakefile +4 -4
- data/VERSION +1 -1
- data/dm-is-list.gemspec +25 -18
- data/lib/dm-is-list/is/list.rb +24 -15
- data/lib/dm-is-list.rb +0 -3
- data/spec/integration/list_spec.rb +10 -43
- data/spec/spec_helper.rb +37 -26
- data/tasks/local_gemfile.rake +18 -0
- data/tasks/spec.rake +0 -3
- metadata +76 -31
data/.gitignore
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
## MAC OS
|
2
|
+
.DS_Store
|
3
|
+
|
4
|
+
## TEXTMATE
|
5
|
+
*.tmproj
|
6
|
+
tmtags
|
7
|
+
|
8
|
+
## EMACS
|
9
|
+
*~
|
10
|
+
\#*
|
11
|
+
.\#*
|
12
|
+
|
13
|
+
## VIM
|
14
|
+
*.swp
|
15
|
+
|
16
|
+
## Rubinius
|
17
|
+
*.rbc
|
18
|
+
|
19
|
+
## PROJECT::GENERAL
|
20
|
+
*.gem
|
21
|
+
coverage
|
22
|
+
rdoc
|
23
|
+
pkg
|
24
|
+
tmp
|
25
|
+
doc
|
26
|
+
log
|
27
|
+
.yardoc
|
28
|
+
measurements
|
29
|
+
|
30
|
+
## BUNDLER
|
31
|
+
.bundle
|
32
|
+
Gemfile.local
|
33
|
+
Gemfile.lock
|
34
|
+
|
35
|
+
## PROJECT::SPECIFIC
|
36
|
+
spec/db/
|
data/Gemfile
ADDED
@@ -0,0 +1,143 @@
|
|
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 use
|
7
|
+
# the same environment variables, like ADAPTER(S) or PLUGIN(S) when running
|
8
|
+
# bundle commands. Gemfile.local is added to .gitignore, so you don't need to
|
9
|
+
# worry about accidentally checking local development paths into git.
|
10
|
+
# In order to create a local Gemfile, all you need to do is run:
|
11
|
+
#
|
12
|
+
# bundle exec rake local_gemfile
|
13
|
+
#
|
14
|
+
# This will give you a Gemfile.local file that points to your local clones of
|
15
|
+
# the various datamapper gems. It's assumed that all datamapper repo clones
|
16
|
+
# reside in the same directory. You can use the Gemfile.local like so for
|
17
|
+
# running any bundle command:
|
18
|
+
#
|
19
|
+
# BUNDLE_GEMFILE=Gemfile.local bundle foo
|
20
|
+
#
|
21
|
+
# You can also specify which adapter(s) should be part of the bundle by setting
|
22
|
+
# an environment variable. This of course also works when using the Gemfile.local
|
23
|
+
#
|
24
|
+
# bundle foo # dm-sqlite-adapter
|
25
|
+
# ADAPTER=mysql bundle foo # dm-mysql-adapter
|
26
|
+
# ADAPTERS=sqlite,mysql bundle foo # dm-sqlite-adapter and dm-mysql-adapter
|
27
|
+
#
|
28
|
+
# Of course you can also use the ADAPTER(S) variable when using the Gemfile.local
|
29
|
+
# and running specs against selected adapters.
|
30
|
+
#
|
31
|
+
# For easily working with adapters supported on your machine, it's recommended
|
32
|
+
# that you first install all adapters that you are planning to use or work on
|
33
|
+
# by doing something like
|
34
|
+
#
|
35
|
+
# ADAPTERS=sqlite,mysql,postgres bundle install
|
36
|
+
#
|
37
|
+
# This will clone the various repositories and make them available to bundler.
|
38
|
+
# Once you have them installed you can easily switch between adapters for the
|
39
|
+
# various development tasks. Running something like
|
40
|
+
#
|
41
|
+
# ADAPTER=mysql bundle exec rake spec
|
42
|
+
#
|
43
|
+
# will make sure that the dm-mysql-adapter is part of the bundle, and will be used
|
44
|
+
# when running the specs.
|
45
|
+
#
|
46
|
+
# You can also specify which plugin(s) should be part of the bundle by setting
|
47
|
+
# an environment variable. This also works when using the Gemfile.local
|
48
|
+
#
|
49
|
+
# bundle foo # dm-migrations
|
50
|
+
# PLUGINS=dm-validations bundle foo # dm-migrations and dm-validations
|
51
|
+
# PLUGINS=dm-validations,dm-types bundle foo # dm-migrations, dm-validations and dm-types
|
52
|
+
#
|
53
|
+
# Of course you can combine the PLUGIN(S) and ADAPTER(S) env vars to run specs
|
54
|
+
# for certain adapter/plugin combinations.
|
55
|
+
#
|
56
|
+
# Finally, to speed up running specs and other tasks, it's recommended to run
|
57
|
+
#
|
58
|
+
# bundle lock
|
59
|
+
#
|
60
|
+
# after running 'bundle install' for the first time. This will make 'bundle exec' run
|
61
|
+
# a lot faster compared to the unlocked version. With an unlocked bundle you would
|
62
|
+
# typically just run 'bundle install' from time to time to fetch the latest sources from
|
63
|
+
# upstream. When you locked your bundle, you need to run
|
64
|
+
#
|
65
|
+
# bundle install --relock
|
66
|
+
#
|
67
|
+
# to make sure to fetch the latest updates and then lock the bundle again. Gemfile.lock
|
68
|
+
# is added to the .gitignore file, so you don't need to worry about accidentally checking
|
69
|
+
# it into version control.
|
70
|
+
|
71
|
+
source 'http://rubygems.org'
|
72
|
+
|
73
|
+
DATAMAPPER = 'git://github.com/datamapper'
|
74
|
+
DM_VERSION = '~> 1.0.0.rc2'
|
75
|
+
|
76
|
+
group :runtime do # Runtime dependencies (as in the gemspec)
|
77
|
+
|
78
|
+
if ENV['EXTLIB']
|
79
|
+
gem 'extlib', '~> 0.9.15', :git => "#{DATAMAPPER}/extlib.git"
|
80
|
+
else
|
81
|
+
gem 'activesupport', '~> 3.0.0.beta3', :git => 'git://github.com/rails/rails.git', :require => nil
|
82
|
+
end
|
83
|
+
|
84
|
+
gem 'dm-core', DM_VERSION, :git => "#{DATAMAPPER}/dm-core.git"
|
85
|
+
gem 'dm-adjust', DM_VERSION, :git => "#{DATAMAPPER}/dm-adjust.git"
|
86
|
+
gem 'dm-transactions', DM_VERSION, :git => "#{DATAMAPPER}/dm-transactions.git"
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
group(:development) do # Development dependencies (as in the gemspec)
|
91
|
+
|
92
|
+
gem 'rake', '~> 0.8.7'
|
93
|
+
gem 'rspec', '~> 1.3'
|
94
|
+
gem 'jeweler', '~> 1.4'
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
group :quality do # These gems contain rake tasks that check the quality of the source code
|
99
|
+
|
100
|
+
gem 'metric_fu', '~> 1.3'
|
101
|
+
gem 'rcov', '~> 0.9.8'
|
102
|
+
gem 'reek', '~> 1.2.8'
|
103
|
+
gem 'roodi', '~> 2.1'
|
104
|
+
gem 'yard', '~> 0.5'
|
105
|
+
gem 'yardstick', '~> 0.1'
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
group :datamapper do # We need this because we want to pin these dependencies to their git master sources
|
110
|
+
|
111
|
+
adapters = ENV['ADAPTER'] || ENV['ADAPTERS']
|
112
|
+
adapters = adapters.to_s.gsub(',',' ').split(' ') - ['in_memory']
|
113
|
+
|
114
|
+
unless adapters.empty?
|
115
|
+
|
116
|
+
DO_VERSION = '~> 0.10.3'
|
117
|
+
DM_DO_ADAPTERS = %w[sqlite postgres mysql oracle sqlserver]
|
118
|
+
|
119
|
+
gem 'data_objects', DO_VERSION, :git => "#{DATAMAPPER}/do.git"
|
120
|
+
|
121
|
+
adapters.each do |adapter|
|
122
|
+
if DM_DO_ADAPTERS.any? { |dm_do_adapter| dm_do_adapter =~ /#{adapter}/ }
|
123
|
+
adapter = 'sqlite3' if adapter == 'sqlite'
|
124
|
+
gem "do_#{adapter}", DO_VERSION, :git => "#{DATAMAPPER}/do.git"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
gem 'dm-do-adapter', DM_VERSION, :git => "#{DATAMAPPER}/dm-do-adapter.git"
|
129
|
+
|
130
|
+
adapters.each do |adapter|
|
131
|
+
gem "dm-#{adapter}-adapter", DM_VERSION, :git => "#{DATAMAPPER}/dm-#{adapter}-adapter.git"
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
plugins = ENV['PLUGINS'] || ENV['PLUGIN']
|
137
|
+
plugins = (plugins.to_s.gsub(',',' ').split(' ') + ['dm-migrations']).uniq
|
138
|
+
|
139
|
+
plugins.each do |plugin|
|
140
|
+
gem plugin, DM_VERSION, :git => "#{DATAMAPPER}/#{plugin}.git"
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
data/README.rdoc
CHANGED
@@ -41,7 +41,7 @@ having their own todo-lists.
|
|
41
41
|
class User
|
42
42
|
include DataMapper::Resource
|
43
43
|
|
44
|
-
property :id,
|
44
|
+
property :id, Serial
|
45
45
|
property :name, String
|
46
46
|
|
47
47
|
has n, :todos
|
@@ -50,14 +50,14 @@ having their own todo-lists.
|
|
50
50
|
class Todo
|
51
51
|
include DataMapper::Resource
|
52
52
|
|
53
|
-
property :id,
|
53
|
+
property :id, Serial
|
54
54
|
property :title, String
|
55
|
-
property :done,
|
55
|
+
property :done, DateTime
|
56
56
|
|
57
57
|
belongs_to :user
|
58
58
|
|
59
59
|
# here we define that this should be a list, scoped on :user_id
|
60
|
-
is :list, :scope => [:user_id]
|
60
|
+
is :list, :scope => :user_id # you may also pass in multiple properties, eg [ :user_id, :title ]
|
61
61
|
end
|
62
62
|
|
63
63
|
Once we have our Users and Lists, we might want to work with...
|
data/Rakefile
CHANGED
@@ -15,11 +15,11 @@ begin
|
|
15
15
|
|
16
16
|
gem.rubyforge_project = 'datamapper'
|
17
17
|
|
18
|
-
gem.add_dependency 'dm-core',
|
19
|
-
gem.add_dependency 'dm-adjust',
|
18
|
+
gem.add_dependency 'dm-core', '~> 1.0.0.rc2'
|
19
|
+
gem.add_dependency 'dm-adjust', '~> 1.0.0.rc2'
|
20
|
+
gem.add_dependency 'dm-transactions', '~> 1.0.0.rc2'
|
20
21
|
|
21
|
-
gem.add_development_dependency 'rspec', '~> 1.
|
22
|
-
gem.add_development_dependency 'yard', '~> 0.4.0'
|
22
|
+
gem.add_development_dependency 'rspec', '~> 1.3'
|
23
23
|
end
|
24
24
|
|
25
25
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
1.0.0.rc2
|
data/dm-is-list.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{dm-is-list}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "1.0.0.rc2"
|
9
9
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Sindre Aarsaether"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-05-19}
|
13
13
|
s.description = %q{DataMapper plugin for creating and organizing lists}
|
14
14
|
s.email = %q{sindre [a] identu [d] no}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -17,7 +17,9 @@ Gem::Specification.new do |s|
|
|
17
17
|
"README.rdoc"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
|
-
"
|
20
|
+
".gitignore",
|
21
|
+
"Gemfile",
|
22
|
+
"LICENSE",
|
21
23
|
"README.rdoc",
|
22
24
|
"Rakefile",
|
23
25
|
"VERSION",
|
@@ -29,6 +31,7 @@ Gem::Specification.new do |s|
|
|
29
31
|
"spec/spec.opts",
|
30
32
|
"spec/spec_helper.rb",
|
31
33
|
"tasks/ci.rake",
|
34
|
+
"tasks/local_gemfile.rake",
|
32
35
|
"tasks/metrics.rake",
|
33
36
|
"tasks/spec.rake",
|
34
37
|
"tasks/yard.rake",
|
@@ -38,29 +41,33 @@ Gem::Specification.new do |s|
|
|
38
41
|
s.rdoc_options = ["--charset=UTF-8"]
|
39
42
|
s.require_paths = ["lib"]
|
40
43
|
s.rubyforge_project = %q{datamapper}
|
41
|
-
s.rubygems_version = %q{1.3.
|
44
|
+
s.rubygems_version = %q{1.3.7}
|
42
45
|
s.summary = %q{DataMapper plugin for creating and organizing lists}
|
46
|
+
s.test_files = [
|
47
|
+
"spec/integration/list_spec.rb",
|
48
|
+
"spec/spec_helper.rb"
|
49
|
+
]
|
43
50
|
|
44
51
|
if s.respond_to? :specification_version then
|
45
52
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
46
53
|
s.specification_version = 3
|
47
54
|
|
48
|
-
if Gem::Version.new(Gem::
|
49
|
-
s.add_runtime_dependency(%q<dm-core>, ["~> 0.
|
50
|
-
s.add_runtime_dependency(%q<dm-adjust>, ["~> 0.
|
51
|
-
s.
|
52
|
-
s.add_development_dependency(%q<
|
55
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
56
|
+
s.add_runtime_dependency(%q<dm-core>, ["~> 1.0.0.rc2"])
|
57
|
+
s.add_runtime_dependency(%q<dm-adjust>, ["~> 1.0.0.rc2"])
|
58
|
+
s.add_runtime_dependency(%q<dm-transactions>, ["~> 1.0.0.rc2"])
|
59
|
+
s.add_development_dependency(%q<rspec>, ["~> 1.3"])
|
53
60
|
else
|
54
|
-
s.add_dependency(%q<dm-core>, ["~> 0.
|
55
|
-
s.add_dependency(%q<dm-adjust>, ["~> 0.
|
56
|
-
s.add_dependency(%q<
|
57
|
-
s.add_dependency(%q<
|
61
|
+
s.add_dependency(%q<dm-core>, ["~> 1.0.0.rc2"])
|
62
|
+
s.add_dependency(%q<dm-adjust>, ["~> 1.0.0.rc2"])
|
63
|
+
s.add_dependency(%q<dm-transactions>, ["~> 1.0.0.rc2"])
|
64
|
+
s.add_dependency(%q<rspec>, ["~> 1.3"])
|
58
65
|
end
|
59
66
|
else
|
60
|
-
s.add_dependency(%q<dm-core>, ["~> 0.
|
61
|
-
s.add_dependency(%q<dm-adjust>, ["~> 0.
|
62
|
-
s.add_dependency(%q<
|
63
|
-
s.add_dependency(%q<
|
67
|
+
s.add_dependency(%q<dm-core>, ["~> 1.0.0.rc2"])
|
68
|
+
s.add_dependency(%q<dm-adjust>, ["~> 1.0.0.rc2"])
|
69
|
+
s.add_dependency(%q<dm-transactions>, ["~> 1.0.0.rc2"])
|
70
|
+
s.add_dependency(%q<rspec>, ["~> 1.3"])
|
64
71
|
end
|
65
72
|
end
|
66
73
|
|
data/lib/dm-is-list/is/list.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
require 'dm-core'
|
2
|
+
require 'dm-transactions'
|
3
|
+
require 'dm-adjust'
|
4
|
+
|
1
5
|
module DataMapper
|
2
6
|
module Is
|
3
7
|
|
@@ -9,21 +13,17 @@ module DataMapper
|
|
9
13
|
#
|
10
14
|
# === Stable
|
11
15
|
#
|
12
|
-
# Install the +dm-
|
16
|
+
# Install the +dm-is-list+ gem using rubygems.
|
13
17
|
#
|
14
|
-
# $
|
18
|
+
# $ gem install dm-is-list
|
15
19
|
#
|
16
20
|
# === Edge
|
17
21
|
#
|
18
|
-
# Download or clone +dm-
|
19
|
-
#
|
20
|
-
# $ cd /path/to/dm-more
|
22
|
+
# Download or clone +dm-is-list+ from Github[http://github.com/datamapper/dm-is-list/].
|
21
23
|
#
|
22
|
-
# $
|
23
|
-
#
|
24
|
-
# # enter your password at the prompt, if required
|
25
|
-
# $ password ...
|
24
|
+
# $ cd /path/to/dm-is-list
|
26
25
|
#
|
26
|
+
# $ rake install
|
27
27
|
#
|
28
28
|
# == Getting started
|
29
29
|
#
|
@@ -235,9 +235,9 @@ module DataMapper
|
|
235
235
|
# custom :field
|
236
236
|
#
|
237
237
|
# @example [Usage]
|
238
|
-
# is :list
|
239
|
-
# is :list, :scope =>
|
240
|
-
# is :list, :scope => [:user_id, :context_id] # also works with multiple params
|
238
|
+
# is :list # put this in your model to make it act as a list.
|
239
|
+
# is :list, :scope => :user_id # you can also define scopes
|
240
|
+
# is :list, :scope => [ :user_id, :context_id ] # also works with multiple params
|
241
241
|
#
|
242
242
|
# @param options <Hash> a hash of options
|
243
243
|
#
|
@@ -247,10 +247,13 @@ module DataMapper
|
|
247
247
|
def is_list(options={})
|
248
248
|
options = { :scope => [], :first => 1 }.merge(options)
|
249
249
|
|
250
|
+
# coerce the scope into an Array
|
251
|
+
options[:scope] = Array(options[:scope])
|
252
|
+
|
250
253
|
extend DataMapper::Is::List::ClassMethods
|
251
254
|
include DataMapper::Is::List::InstanceMethods
|
252
255
|
|
253
|
-
unless properties.any? { |p| p.name == :position && p.
|
256
|
+
unless properties.any? { |p| p.name == :position && p.primitive == Integer }
|
254
257
|
property :position, Integer
|
255
258
|
end
|
256
259
|
|
@@ -313,8 +316,11 @@ module DataMapper
|
|
313
316
|
# @api public
|
314
317
|
def repair_list(scope = {})
|
315
318
|
return false unless scope.keys.all?{ |s| list_options[:scope].include?(s) || s == :order }
|
316
|
-
|
317
|
-
|
319
|
+
retval = true
|
320
|
+
all({ :order => [ :position.asc ] | default_order }.merge(scope)).each_with_index do |item, index|
|
321
|
+
retval &= item.update(:position => index.succ)
|
322
|
+
end
|
323
|
+
retval
|
318
324
|
end
|
319
325
|
|
320
326
|
end
|
@@ -612,4 +618,7 @@ module DataMapper
|
|
612
618
|
end # InstanceMethods
|
613
619
|
end # List
|
614
620
|
end # Is
|
621
|
+
|
622
|
+
Model.append_extensions(Is::List)
|
623
|
+
|
615
624
|
end # DataMapper
|
data/lib/dm-is-list.rb
CHANGED
@@ -1,31 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
describe 'DataMapper::Is::List' do
|
3
|
+
describe 'DataMapper::Is::List' do
|
5
4
|
|
6
|
-
|
7
|
-
include DataMapper::Resource
|
8
|
-
|
9
|
-
property :id, Serial
|
10
|
-
property :name, String
|
11
|
-
|
12
|
-
has n, :todos
|
13
|
-
end
|
14
|
-
|
15
|
-
class Todo
|
16
|
-
include DataMapper::Resource
|
17
|
-
|
18
|
-
property :id, Serial
|
19
|
-
property :title, String
|
20
|
-
|
21
|
-
belongs_to :user
|
22
|
-
|
23
|
-
is :list, :scope => [:user_id]
|
24
|
-
end
|
5
|
+
supported_by :sqlite, :postgres, :mysql, :oracle, :sqlserver do
|
25
6
|
|
26
7
|
before :each do
|
27
|
-
|
28
|
-
Todo.auto_migrate!
|
8
|
+
DataMapper.auto_migrate!
|
29
9
|
|
30
10
|
@u1 = User.create(:name => 'Johnny')
|
31
11
|
Todo.create(:user => @u1, :title => 'Write down what is needed in a list-plugin')
|
@@ -39,18 +19,6 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
39
19
|
Todo.create(:user => @u2, :title => 'Go to sleep')
|
40
20
|
end
|
41
21
|
|
42
|
-
##
|
43
|
-
# Keep things DRY shortcut
|
44
|
-
#
|
45
|
-
# todo_list.should == [ [1, 1], [2, 2], [3, 3], [4, 4], [5, 5] ]
|
46
|
-
#
|
47
|
-
# todo_list(:user => @u2, :order => [:id]).should == [ [1, 1], [2, 2], [3, 3], [4, 4], [5, 5] ]
|
48
|
-
#
|
49
|
-
def todo_list(options={})
|
50
|
-
options = { :user => @u1, :order => [:position] }.merge(options)
|
51
|
-
Todo.all(:user => options[:user], :order => options[:order]).map{ |a| [a.id, a.position] }
|
52
|
-
end
|
53
|
-
|
54
22
|
describe "Class Methods" do
|
55
23
|
|
56
24
|
describe "#repair_list" do
|
@@ -61,7 +29,7 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
61
29
|
items.each{ |item| item.update(:position => [4,2,8,32,16][item.id - 1]) }
|
62
30
|
todo_list.should == [ [2, 2], [1, 4], [3, 8], [5, 16], [4, 32] ]
|
63
31
|
|
64
|
-
Todo.repair_list(:user_id => @u1.id)
|
32
|
+
Todo.repair_list(:user_id => @u1.id).should be(true)
|
65
33
|
todo_list.should == [ [2, 1], [1, 2], [3, 3], [5, 4], [4, 5] ]
|
66
34
|
end
|
67
35
|
end
|
@@ -69,7 +37,7 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
69
37
|
it "should repair unscoped lists" do
|
70
38
|
DataMapper.repository(:default) do |repos|
|
71
39
|
Todo.all.map { |t| [t.id, t.position] }.should == [ [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 1], [7, 2], [8, 3] ]
|
72
|
-
Todo.repair_list
|
40
|
+
Todo.repair_list.should be(true)
|
73
41
|
# note the order, repairs lists based on position
|
74
42
|
Todo.all.map { |t| [t.id, t.position] }.should == [ [1, 1], [2, 3], [3, 5], [4, 7], [5, 8], [6, 2], [7, 4], [8, 6] ]
|
75
43
|
Todo.all(:order => [:position]).map { |t| t.id }.should == [1, 6, 2, 7, 3, 8, 4, 5]
|
@@ -398,7 +366,7 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
398
366
|
describe "#list_scope" do
|
399
367
|
|
400
368
|
describe 'without scope' do
|
401
|
-
class Property
|
369
|
+
class ::Property
|
402
370
|
include DataMapper::Resource
|
403
371
|
|
404
372
|
property :id, Serial
|
@@ -494,7 +462,7 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
494
462
|
todo_list.should == [ [1, 1], [2, 2], [3, 3], [4, 4], [5, 20] ]
|
495
463
|
|
496
464
|
item = Todo.get(5)
|
497
|
-
item.repair_list
|
465
|
+
item.repair_list.should be(true)
|
498
466
|
item.position.should == 5
|
499
467
|
end
|
500
468
|
end
|
@@ -510,7 +478,7 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
510
478
|
todo_list.should == [ [2, 5], [4, 48], [1, 83], [5, 99], [3, 186] ]
|
511
479
|
|
512
480
|
item = Todo.get(5)
|
513
|
-
item.repair_list
|
481
|
+
item.repair_list.should be(true)
|
514
482
|
# note position numbers being 1 - 5, and it retained the id positions
|
515
483
|
todo_list.should == [ [2, 1], [4, 2], [1, 3], [5, 4], [3, 5] ]
|
516
484
|
end
|
@@ -974,7 +942,7 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
974
942
|
|
975
943
|
describe "With :unique_index => position defined" do
|
976
944
|
|
977
|
-
class Client
|
945
|
+
class ::Client
|
978
946
|
include DataMapper::Resource
|
979
947
|
|
980
948
|
property :id, Serial
|
@@ -983,7 +951,7 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
983
951
|
has n, :client_todos
|
984
952
|
end
|
985
953
|
|
986
|
-
class ClientTodo
|
954
|
+
class ::ClientTodo
|
987
955
|
include DataMapper::Resource
|
988
956
|
|
989
957
|
property :id, Serial
|
@@ -1046,7 +1014,6 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
1046
1014
|
|
1047
1015
|
end #/ With :unique_index => position defined
|
1048
1016
|
|
1049
|
-
|
1050
1017
|
end
|
1051
1018
|
|
1052
1019
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,35 +1,46 @@
|
|
1
|
-
require '
|
1
|
+
require 'dm-core/spec/setup'
|
2
|
+
require 'dm-core/spec/lib/adapter_helpers'
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
$LOAD_PATH.unshift(lib) if File.directory?(lib)
|
6
|
-
require 'dm-core'
|
4
|
+
require 'dm-is-list'
|
5
|
+
require 'dm-migrations'
|
7
6
|
|
8
|
-
|
9
|
-
lib = File.join('..', 'dm-adjust', 'lib')
|
10
|
-
$LOAD_PATH.unshift(lib) if File.directory?(lib)
|
11
|
-
require 'dm-adjust'
|
7
|
+
DataMapper::Spec.setup
|
12
8
|
|
13
|
-
|
14
|
-
|
9
|
+
class User
|
10
|
+
include DataMapper::Resource
|
15
11
|
|
16
|
-
|
12
|
+
property :id, Serial
|
13
|
+
property :name, String
|
17
14
|
|
18
|
-
|
19
|
-
|
15
|
+
has n, :todos
|
16
|
+
end
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
18
|
+
class Todo
|
19
|
+
include DataMapper::Resource
|
20
|
+
|
21
|
+
property :id, Serial
|
22
|
+
property :title, String
|
23
|
+
|
24
|
+
belongs_to :user
|
25
|
+
|
26
|
+
is :list, :scope => :user_id
|
29
27
|
end
|
30
28
|
|
31
|
-
|
29
|
+
module TodoListHelper
|
30
|
+
##
|
31
|
+
# Keep things DRY shortcut
|
32
|
+
#
|
33
|
+
# todo_list.should == [ [1, 1], [2, 2], [3, 3], [4, 4], [5, 5] ]
|
34
|
+
#
|
35
|
+
# todo_list(:user => @u2, :order => [:id]).should == [ [1, 1], [2, 2], [3, 3], [4, 4], [5, 5] ]
|
36
|
+
#
|
37
|
+
def todo_list(options={})
|
38
|
+
options = { :user => @u1, :order => [:position] }.merge(options)
|
39
|
+
Todo.all(:user => options[:user], :order => options[:order]).map{ |a| [a.id, a.position] }
|
40
|
+
end
|
41
|
+
end
|
32
42
|
|
33
|
-
|
34
|
-
|
35
|
-
|
43
|
+
Spec::Runner.configure do |config|
|
44
|
+
config.extend(DataMapper::Spec::Adapters::Helpers)
|
45
|
+
config.send(:include, TodoListHelper)
|
46
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
desc "Support bundling from local source code (allows BUNDLE_GEMFILE=Gemfile.local bundle foo)"
|
2
|
+
task :local_gemfile do |t|
|
3
|
+
|
4
|
+
root = Pathname(__FILE__).dirname.parent
|
5
|
+
datamapper = root.parent
|
6
|
+
|
7
|
+
source_regex = /DATAMAPPER = 'git:\/\/github.com\/datamapper'/
|
8
|
+
gem_source_regex = /:git => \"#\{DATAMAPPER\}\/(.+?)(?:\.git)?\"/
|
9
|
+
|
10
|
+
root.join('Gemfile.local').open('w') do |f|
|
11
|
+
root.join('Gemfile').open.each do |line|
|
12
|
+
line.sub!(source_regex, "DATAMAPPER = '#{datamapper}'")
|
13
|
+
line.sub!(gem_source_regex, ':path => "#{DATAMAPPER}/\1"')
|
14
|
+
f.puts line
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/tasks/spec.rake
CHANGED
metadata
CHANGED
@@ -1,7 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-is-list
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 977940575
|
5
|
+
prerelease: true
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
- rc2
|
11
|
+
version: 1.0.0.rc2
|
5
12
|
platform: ruby
|
6
13
|
authors:
|
7
14
|
- Sindre Aarsaether
|
@@ -9,49 +16,75 @@ autorequire:
|
|
9
16
|
bindir: bin
|
10
17
|
cert_chain: []
|
11
18
|
|
12
|
-
date:
|
19
|
+
date: 2010-05-19 00:00:00 -07:00
|
13
20
|
default_executable:
|
14
21
|
dependencies:
|
15
22
|
- !ruby/object:Gem::Dependency
|
16
23
|
name: dm-core
|
17
|
-
|
18
|
-
|
19
|
-
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
20
27
|
requirements:
|
21
28
|
- - ~>
|
22
29
|
- !ruby/object:Gem::Version
|
23
|
-
|
24
|
-
|
30
|
+
hash: 977940575
|
31
|
+
segments:
|
32
|
+
- 1
|
33
|
+
- 0
|
34
|
+
- 0
|
35
|
+
- rc2
|
36
|
+
version: 1.0.0.rc2
|
37
|
+
type: :runtime
|
38
|
+
version_requirements: *id001
|
25
39
|
- !ruby/object:Gem::Dependency
|
26
40
|
name: dm-adjust
|
27
|
-
|
28
|
-
|
29
|
-
|
41
|
+
prerelease: false
|
42
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
30
44
|
requirements:
|
31
45
|
- - ~>
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
|
34
|
-
|
47
|
+
hash: 977940575
|
48
|
+
segments:
|
49
|
+
- 1
|
50
|
+
- 0
|
51
|
+
- 0
|
52
|
+
- rc2
|
53
|
+
version: 1.0.0.rc2
|
54
|
+
type: :runtime
|
55
|
+
version_requirements: *id002
|
35
56
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
37
|
-
|
38
|
-
|
39
|
-
|
57
|
+
name: dm-transactions
|
58
|
+
prerelease: false
|
59
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
40
61
|
requirements:
|
41
62
|
- - ~>
|
42
63
|
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
|
64
|
+
hash: 977940575
|
65
|
+
segments:
|
66
|
+
- 1
|
67
|
+
- 0
|
68
|
+
- 0
|
69
|
+
- rc2
|
70
|
+
version: 1.0.0.rc2
|
71
|
+
type: :runtime
|
72
|
+
version_requirements: *id003
|
45
73
|
- !ruby/object:Gem::Dependency
|
46
|
-
name:
|
47
|
-
|
48
|
-
|
49
|
-
|
74
|
+
name: rspec
|
75
|
+
prerelease: false
|
76
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
50
78
|
requirements:
|
51
79
|
- - ~>
|
52
80
|
- !ruby/object:Gem::Version
|
53
|
-
|
54
|
-
|
81
|
+
hash: 9
|
82
|
+
segments:
|
83
|
+
- 1
|
84
|
+
- 3
|
85
|
+
version: "1.3"
|
86
|
+
type: :development
|
87
|
+
version_requirements: *id004
|
55
88
|
description: DataMapper plugin for creating and organizing lists
|
56
89
|
email: sindre [a] identu [d] no
|
57
90
|
executables: []
|
@@ -62,6 +95,8 @@ extra_rdoc_files:
|
|
62
95
|
- LICENSE
|
63
96
|
- README.rdoc
|
64
97
|
files:
|
98
|
+
- .gitignore
|
99
|
+
- Gemfile
|
65
100
|
- LICENSE
|
66
101
|
- README.rdoc
|
67
102
|
- Rakefile
|
@@ -74,6 +109,7 @@ files:
|
|
74
109
|
- spec/spec.opts
|
75
110
|
- spec/spec_helper.rb
|
76
111
|
- tasks/ci.rake
|
112
|
+
- tasks/local_gemfile.rake
|
77
113
|
- tasks/metrics.rake
|
78
114
|
- tasks/spec.rake
|
79
115
|
- tasks/yard.rake
|
@@ -88,23 +124,32 @@ rdoc_options:
|
|
88
124
|
require_paths:
|
89
125
|
- lib
|
90
126
|
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
91
128
|
requirements:
|
92
129
|
- - ">="
|
93
130
|
- !ruby/object:Gem::Version
|
131
|
+
hash: 3
|
132
|
+
segments:
|
133
|
+
- 0
|
94
134
|
version: "0"
|
95
|
-
version:
|
96
135
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
none: false
|
97
137
|
requirements:
|
98
|
-
- - "
|
138
|
+
- - ">"
|
99
139
|
- !ruby/object:Gem::Version
|
100
|
-
|
101
|
-
|
140
|
+
hash: 25
|
141
|
+
segments:
|
142
|
+
- 1
|
143
|
+
- 3
|
144
|
+
- 1
|
145
|
+
version: 1.3.1
|
102
146
|
requirements: []
|
103
147
|
|
104
148
|
rubyforge_project: datamapper
|
105
|
-
rubygems_version: 1.3.
|
149
|
+
rubygems_version: 1.3.7
|
106
150
|
signing_key:
|
107
151
|
specification_version: 3
|
108
152
|
summary: DataMapper plugin for creating and organizing lists
|
109
|
-
test_files:
|
110
|
-
|
153
|
+
test_files:
|
154
|
+
- spec/integration/list_spec.rb
|
155
|
+
- spec/spec_helper.rb
|