dm-is-select 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +3 -8
- data/Rakefile +9 -24
- data/VERSION +1 -1
- data/dm-is-select.gemspec +14 -5
- data/lib/dm-is-select/is/select.rb +3 -7
- data/lib/dm-is-select/is/version.rb +1 -1
- data/lib/dm-is-select.rb +0 -6
- data/spec/integration/select_spec.rb +56 -40
- data/spec/spec_helper.rb +4 -2
- metadata +51 -7
data/README.rdoc
CHANGED
@@ -14,12 +14,7 @@ A DataMapper plugin that makes getting the <tt><select></tt> options from a Mode
|
|
14
14
|
|
15
15
|
The plugin depends upon the following:
|
16
16
|
|
17
|
-
* dm-core ( >= 0.
|
18
|
-
* dm-more ( >= 0.10.0) [not really, but your code will depend upon it]
|
19
|
-
|
20
|
-
|
21
|
-
<b>NB!</b> The plugin has been developed for and on DM's next branch[http://github.com/datamapper/dm-core/tree/next], so may NOT work on previous incarnations.
|
22
|
-
|
17
|
+
* dm-core ( >= 1.0.0)
|
23
18
|
|
24
19
|
|
25
20
|
== Getting Started
|
@@ -30,9 +25,9 @@ Let's say you got a basic Category Model.
|
|
30
25
|
include DataMapper::Resource
|
31
26
|
property :id, Serial
|
32
27
|
property :name, String
|
33
|
-
|
28
|
+
|
34
29
|
is :select, :name
|
35
|
-
|
30
|
+
|
36
31
|
end
|
37
32
|
|
38
33
|
Through that simple declaration you get the following class method ..
|
data/Rakefile
CHANGED
@@ -3,6 +3,7 @@ require 'rake'
|
|
3
3
|
|
4
4
|
begin
|
5
5
|
require 'jeweler'
|
6
|
+
|
6
7
|
Jeweler::Tasks.new do |gem|
|
7
8
|
gem.name = "dm-is-select"
|
8
9
|
# gem.version = IO.read('VERSION')
|
@@ -12,15 +13,16 @@ begin
|
|
12
13
|
gem.homepage = "http://github.com/kematzy/dm-is-select"
|
13
14
|
gem.authors = ["kematzy"]
|
14
15
|
gem.extra_rdoc_files = %w[ README.rdoc LICENSE TODO History.rdoc ]
|
15
|
-
gem.add_dependency
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
gem.add_dependency 'dm-core', '~> 1.0.0.rc3'
|
17
|
+
gem.add_development_dependency 'rspec', '~> 1.3'
|
18
|
+
gem.add_development_dependency 'dm-migrations', '~> 1.0.0.rc3'
|
19
|
+
gem.add_development_dependency 'dm-validations', '~> 1.0.0.rc3'
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
|
+
Jeweler::GemcutterTasks.new
|
23
|
+
|
22
24
|
rescue LoadError
|
23
|
-
puts "Jeweler (or a dependency) not available. Install it with:
|
25
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
24
26
|
end
|
25
27
|
|
26
28
|
require 'spec/rake/spectask'
|
@@ -91,20 +93,3 @@ namespace :docs do
|
|
91
93
|
end
|
92
94
|
|
93
95
|
end
|
94
|
-
|
95
|
-
|
96
|
-
# kept just as a reference for now.
|
97
|
-
#
|
98
|
-
# def sudo_gem(cmd)
|
99
|
-
# sh "#{SUDO} #{RUBY} -S gem #{cmd}", :verbose => false
|
100
|
-
# end
|
101
|
-
#
|
102
|
-
# desc "Install #{GEM_NAME} #{GEM_VERSION}"
|
103
|
-
# task :install => [ :package ] do
|
104
|
-
# sudo_gem "install --local pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources"
|
105
|
-
# end
|
106
|
-
#
|
107
|
-
# desc "Uninstall #{GEM_NAME} #{GEM_VERSION}"
|
108
|
-
# task :uninstall => [ :clobber ] do
|
109
|
-
# sudo_gem "uninstall #{GEM_NAME} -v#{GEM_VERSION} -Ix"
|
110
|
-
# end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.8
|
data/dm-is-select.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{dm-is-select}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["kematzy"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-06-09}
|
13
13
|
s.description = %q{A DataMapper plugin that makes getting the <tt>select</tt> options from a Model easier.}
|
14
14
|
s.email = %q{kematzy@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -48,12 +48,21 @@ Gem::Specification.new do |s|
|
|
48
48
|
s.specification_version = 3
|
49
49
|
|
50
50
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
51
|
-
s.add_runtime_dependency(%q<dm-core>, ["
|
51
|
+
s.add_runtime_dependency(%q<dm-core>, ["~> 1.0.0.rc3"])
|
52
|
+
s.add_development_dependency(%q<rspec>, ["~> 1.3"])
|
53
|
+
s.add_development_dependency(%q<dm-migrations>, ["~> 1.0.0.rc3"])
|
54
|
+
s.add_development_dependency(%q<dm-validations>, ["~> 1.0.0.rc3"])
|
52
55
|
else
|
53
|
-
s.add_dependency(%q<dm-core>, ["
|
56
|
+
s.add_dependency(%q<dm-core>, ["~> 1.0.0.rc3"])
|
57
|
+
s.add_dependency(%q<rspec>, ["~> 1.3"])
|
58
|
+
s.add_dependency(%q<dm-migrations>, ["~> 1.0.0.rc3"])
|
59
|
+
s.add_dependency(%q<dm-validations>, ["~> 1.0.0.rc3"])
|
54
60
|
end
|
55
61
|
else
|
56
|
-
s.add_dependency(%q<dm-core>, ["
|
62
|
+
s.add_dependency(%q<dm-core>, ["~> 1.0.0.rc3"])
|
63
|
+
s.add_dependency(%q<rspec>, ["~> 1.3"])
|
64
|
+
s.add_dependency(%q<dm-migrations>, ["~> 1.0.0.rc3"])
|
65
|
+
s.add_dependency(%q<dm-validations>, ["~> 1.0.0.rc3"])
|
57
66
|
end
|
58
67
|
end
|
59
68
|
|
@@ -35,7 +35,7 @@ module DataMapper
|
|
35
35
|
#
|
36
36
|
#
|
37
37
|
# @api public
|
38
|
-
def is_select(select_field = :name, options = {})
|
38
|
+
def is_select(select_field = :name, options = {})
|
39
39
|
raise ArgumentError, "The :select_field, must be an existing attribute in the Model. Got [ #{select_field.inspect} ]" unless properties.any?{ |p| p.name == select_field.to_sym }
|
40
40
|
|
41
41
|
@select_options = {
|
@@ -54,7 +54,7 @@ module DataMapper
|
|
54
54
|
|
55
55
|
end
|
56
56
|
|
57
|
-
module ClassMethods
|
57
|
+
module ClassMethods
|
58
58
|
attr_reader :select_field, :select_options, :value_field
|
59
59
|
|
60
60
|
##
|
@@ -102,8 +102,6 @@ module DataMapper
|
|
102
102
|
# clean out the various parts
|
103
103
|
html_options = options.only(:prompt, :divider, :show_root, :root_text)
|
104
104
|
sql_options = options.except(:prompt, :divider, :show_root, :root_text)
|
105
|
-
# puts "sql_options=[#{sql_options.inspect}] [#{__FILE__}:#{__LINE__}]"
|
106
|
-
# puts "html_options=[#{html_options.inspect}] [#{__FILE__}:#{__LINE__}]"
|
107
105
|
|
108
106
|
options = {
|
109
107
|
:prompt => "Select #{self.name}",
|
@@ -116,9 +114,7 @@ module DataMapper
|
|
116
114
|
:order => [self.select_field.to_sym],
|
117
115
|
}.merge(sql_options)
|
118
116
|
|
119
|
-
mi = self.select_options[:is_tree] ?
|
120
|
-
all({ :parent_id => 0 }.merge(sql_options) ) :
|
121
|
-
all(sql_options)
|
117
|
+
mi = self.select_options[:is_tree] ? all({ :parent_id => nil }.merge(sql_options) ) : all(sql_options)
|
122
118
|
|
123
119
|
res = []
|
124
120
|
if options[:prompt]
|
data/lib/dm-is-select.rb
CHANGED
@@ -3,14 +3,8 @@ require 'rubygems'
|
|
3
3
|
require 'pathname'
|
4
4
|
|
5
5
|
# Add all external dependencies for the plugin here
|
6
|
-
gem 'dm-core', '~> 0.10.0'
|
7
6
|
require 'dm-core'
|
8
|
-
# gem 'extlib', '~> 0.9.13'
|
9
|
-
# require 'extlib'
|
10
|
-
gem 'dm-is-tree', '~> 0.10.0'
|
11
7
|
require 'dm-is-tree'
|
12
|
-
|
13
|
-
|
14
8
|
# Require plugin-files
|
15
9
|
require Pathname(__FILE__).dirname.expand_path / 'dm-is-select' / 'is' / 'select.rb'
|
16
10
|
|
@@ -4,53 +4,45 @@ require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
|
4
4
|
if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
5
5
|
describe 'DataMapper::Is::Select' do
|
6
6
|
|
7
|
-
|
8
|
-
include DataMapper::Resource
|
9
|
-
property :id, Serial
|
10
|
-
property :name, String
|
11
|
-
property :publish_status, String, :default => "on"
|
7
|
+
before(:each) do
|
12
8
|
|
13
|
-
|
9
|
+
class Category
|
10
|
+
include DataMapper::Resource
|
11
|
+
property :id, Serial
|
12
|
+
property :name, String
|
13
|
+
property :publish_status, String, :default => "on"
|
14
|
+
|
15
|
+
is :select, :name
|
16
|
+
end
|
14
17
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
class TreeCategory
|
19
|
+
include DataMapper::Resource
|
20
|
+
property :id, Serial
|
21
|
+
property :name, String
|
22
|
+
property :publish_status, String, :default => "on"
|
23
|
+
# property :parent_id, Integer
|
24
|
+
|
25
|
+
is :tree, :order => :name
|
26
|
+
is :select, :name, :is_tree => true
|
27
|
+
end
|
23
28
|
|
24
|
-
|
25
|
-
|
29
|
+
class Country
|
30
|
+
include DataMapper::Resource
|
31
|
+
property :code, String, :key => true
|
32
|
+
property :name, String
|
33
|
+
is :select, :name, :value_field => :code
|
34
|
+
end #/ Country
|
26
35
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
class Country
|
32
|
-
include DataMapper::Resource
|
33
|
-
property :code, String, :key => true
|
34
|
-
property :name, String
|
35
|
-
is :select, :name, :value_field => :code
|
36
|
+
DataMapper.finalize
|
37
|
+
|
38
|
+
DataMapper.auto_migrate!
|
36
39
|
|
37
|
-
auto_migrate!
|
38
|
-
end #/ Country
|
39
|
-
|
40
|
-
5.times do |n|
|
41
|
-
Category.create(:name => "Category #{n+1}")
|
42
40
|
end
|
43
41
|
|
44
|
-
|
45
|
-
|
46
|
-
parent = TreeCategory.create(:name => "TreeCategory-#{parent_id}" , :parent_id => 0 )
|
47
|
-
child = TreeCategory.create(:name => "TreeCategory-#{parent_id}-Child" , :parent_id => parent.id )
|
48
|
-
grandchild = TreeCategory.create(:name => "TreeCategory-#{parent_id}-Child-GrandChild" , :parent_id => child.id )
|
42
|
+
it "should use DM-Core 1.0.0.rc3" do
|
43
|
+
DataMapper::VERSION.should == '1.0.0.rc3'
|
49
44
|
end
|
50
45
|
|
51
|
-
3.times do |i|
|
52
|
-
Country.create(:code => "A#{i}", :name => "Country#{i}")
|
53
|
-
end
|
54
46
|
|
55
47
|
describe "Class Methods" do
|
56
48
|
|
@@ -64,9 +56,10 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
64
56
|
property :name, String
|
65
57
|
|
66
58
|
is :select, 'name'
|
67
|
-
auto_migrate!
|
68
59
|
end
|
69
60
|
|
61
|
+
DataMapper.auto_migrate!
|
62
|
+
|
70
63
|
}.should_not raise_error(ArgumentError)
|
71
64
|
end
|
72
65
|
|
@@ -78,9 +71,9 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
78
71
|
property :name, String
|
79
72
|
|
80
73
|
is :select, :does_not_exist
|
81
|
-
auto_migrate!
|
82
74
|
end
|
83
75
|
|
76
|
+
DataMapper.auto_migrate!
|
84
77
|
}.should raise_error(ArgumentError)
|
85
78
|
end
|
86
79
|
|
@@ -90,6 +83,12 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
90
83
|
|
91
84
|
describe "A Normal Model" do
|
92
85
|
|
86
|
+
before(:each) do
|
87
|
+
5.times do |n|
|
88
|
+
Category.create(:name => "Category #{n+1}")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
93
92
|
it "should return the default select options when given no params" do
|
94
93
|
Category.items_for_select_menu.should == [
|
95
94
|
[nil, "Select Category"],
|
@@ -175,6 +174,7 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
175
174
|
# [1, "Category 1"]
|
176
175
|
]
|
177
176
|
end
|
177
|
+
|
178
178
|
it "should handle invalid SQL select options" do
|
179
179
|
Category.items_for_select_menu(:publish_status => "invalid", :order => [ :id.desc ] ).should == [
|
180
180
|
[nil, "Select Category"],
|
@@ -191,6 +191,16 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
191
191
|
|
192
192
|
describe "Tree Model" do
|
193
193
|
|
194
|
+
before(:each) do
|
195
|
+
2.times do |parent_id|
|
196
|
+
parent_id += 1
|
197
|
+
theparent = TreeCategory.create(:name => "TreeCategory-#{parent_id}") # sets parent_id => nil
|
198
|
+
child = TreeCategory.create(:name => "TreeCategory-#{parent_id}-Child" , :parent => theparent )
|
199
|
+
grandchild = TreeCategory.create(:name => "TreeCategory-#{parent_id}-Child-GrandChild" , :parent_id => child.id )
|
200
|
+
end
|
201
|
+
|
202
|
+
end
|
203
|
+
|
194
204
|
it "should return the default select options when given no params" do
|
195
205
|
TreeCategory.items_for_select_menu.should == [
|
196
206
|
[nil, "Select TreeCategory"],
|
@@ -287,6 +297,12 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
287
297
|
|
288
298
|
describe "A value_field model" do
|
289
299
|
|
300
|
+
before(:each) do
|
301
|
+
3.times do |i|
|
302
|
+
Country.create(:code => "A#{i}", :name => "Country#{i}")
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
290
306
|
it "should return the default select options when given no params" do
|
291
307
|
Country.items_for_select_menu.should == [
|
292
308
|
[nil, "Select Country"],
|
data/spec/spec_helper.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
require 'rubygems'
|
3
3
|
|
4
|
-
#
|
5
|
-
require '
|
4
|
+
# require 'spec'
|
5
|
+
require 'dm-validations'
|
6
|
+
require 'dm-migrations'
|
7
|
+
require 'dm-is-tree'
|
6
8
|
|
7
9
|
require Pathname(__FILE__).dirname.expand_path.parent + 'lib/dm-is-select'
|
8
10
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 8
|
9
|
+
version: 0.0.8
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- kematzy
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-06-09 00:00:00 +08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -22,15 +22,59 @@ dependencies:
|
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - ~>
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
segments:
|
28
|
+
- 1
|
28
29
|
- 0
|
29
|
-
-
|
30
|
-
-
|
31
|
-
version: 0.
|
30
|
+
- 0
|
31
|
+
- rc3
|
32
|
+
version: 1.0.0.rc3
|
32
33
|
type: :runtime
|
33
34
|
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 1
|
44
|
+
- 3
|
45
|
+
version: "1.3"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: dm-migrations
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 1
|
57
|
+
- 0
|
58
|
+
- 0
|
59
|
+
- rc3
|
60
|
+
version: 1.0.0.rc3
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: dm-validations
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ~>
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
segments:
|
71
|
+
- 1
|
72
|
+
- 0
|
73
|
+
- 0
|
74
|
+
- rc3
|
75
|
+
version: 1.0.0.rc3
|
76
|
+
type: :development
|
77
|
+
version_requirements: *id004
|
34
78
|
description: A DataMapper plugin that makes getting the <tt>select</tt> options from a Model easier.
|
35
79
|
email: kematzy@gmail.com
|
36
80
|
executables: []
|