datamapper 0.3.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +0 -0
- data/Manifest.txt +5 -0
- data/README.txt +11 -0
- data/Rakefile +70 -0
- data/lib/datamapper.rb +8 -0
- metadata +152 -319
- data/CHANGELOG +0 -145
- data/FAQ +0 -96
- data/MIT-LICENSE +0 -22
- data/QUICKLINKS +0 -12
- data/README +0 -105
- data/environment.rb +0 -62
- data/example.rb +0 -156
- data/lib/data_mapper.rb +0 -88
- data/lib/data_mapper/adapters/abstract_adapter.rb +0 -43
- data/lib/data_mapper/adapters/data_object_adapter.rb +0 -480
- data/lib/data_mapper/adapters/mysql_adapter.rb +0 -72
- data/lib/data_mapper/adapters/postgresql_adapter.rb +0 -258
- data/lib/data_mapper/adapters/sql/coersion.rb +0 -134
- data/lib/data_mapper/adapters/sql/commands/load_command.rb +0 -545
- data/lib/data_mapper/adapters/sql/mappings/associations_set.rb +0 -34
- data/lib/data_mapper/adapters/sql/mappings/column.rb +0 -279
- data/lib/data_mapper/adapters/sql/mappings/conditions.rb +0 -172
- data/lib/data_mapper/adapters/sql/mappings/schema.rb +0 -60
- data/lib/data_mapper/adapters/sql/mappings/table.rb +0 -459
- data/lib/data_mapper/adapters/sql/quoting.rb +0 -24
- data/lib/data_mapper/adapters/sqlite3_adapter.rb +0 -159
- data/lib/data_mapper/associations.rb +0 -106
- data/lib/data_mapper/associations/belongs_to_association.rb +0 -160
- data/lib/data_mapper/associations/has_and_belongs_to_many_association.rb +0 -437
- data/lib/data_mapper/associations/has_many_association.rb +0 -283
- data/lib/data_mapper/associations/has_n_association.rb +0 -143
- data/lib/data_mapper/associations/reference.rb +0 -47
- data/lib/data_mapper/attributes.rb +0 -73
- data/lib/data_mapper/auto_migrations.rb +0 -36
- data/lib/data_mapper/base.rb +0 -17
- data/lib/data_mapper/callbacks.rb +0 -107
- data/lib/data_mapper/context.rb +0 -112
- data/lib/data_mapper/database.rb +0 -234
- data/lib/data_mapper/dependency_queue.rb +0 -28
- data/lib/data_mapper/embedded_value.rb +0 -145
- data/lib/data_mapper/identity_map.rb +0 -47
- data/lib/data_mapper/is/tree.rb +0 -121
- data/lib/data_mapper/migration.rb +0 -155
- data/lib/data_mapper/persistence.rb +0 -852
- data/lib/data_mapper/property.rb +0 -310
- data/lib/data_mapper/query.rb +0 -164
- data/lib/data_mapper/support/blank.rb +0 -35
- data/lib/data_mapper/support/connection_pool.rb +0 -117
- data/lib/data_mapper/support/enumerable.rb +0 -35
- data/lib/data_mapper/support/errors.rb +0 -16
- data/lib/data_mapper/support/inflector.rb +0 -265
- data/lib/data_mapper/support/object.rb +0 -54
- data/lib/data_mapper/support/serialization.rb +0 -96
- data/lib/data_mapper/support/silence.rb +0 -10
- data/lib/data_mapper/support/string.rb +0 -72
- data/lib/data_mapper/support/struct.rb +0 -7
- data/lib/data_mapper/support/symbol.rb +0 -82
- data/lib/data_mapper/support/typed_set.rb +0 -65
- data/lib/data_mapper/types/base.rb +0 -44
- data/lib/data_mapper/types/string.rb +0 -34
- data/lib/data_mapper/validatable_extensions/errors.rb +0 -12
- data/lib/data_mapper/validatable_extensions/macros.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validatable_instance_methods.rb +0 -62
- data/lib/data_mapper/validatable_extensions/validation_base.rb +0 -18
- data/lib/data_mapper/validatable_extensions/validations/formats/email.rb +0 -43
- data/lib/data_mapper/validatable_extensions/validations/validates_acceptance_of.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validations/validates_confirmation_of.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validations/validates_each.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validations/validates_format_of.rb +0 -28
- data/lib/data_mapper/validatable_extensions/validations/validates_length_of.rb +0 -15
- data/lib/data_mapper/validatable_extensions/validations/validates_numericality_of.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validations/validates_presence_of.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validations/validates_true_for.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validations/validates_uniqueness_of.rb +0 -40
- data/lib/data_mapper/validations.rb +0 -20
- data/lib/data_mapper/validations/number_validator.rb +0 -40
- data/lib/data_mapper/validations/string_validator.rb +0 -20
- data/lib/data_mapper/validations/validator.rb +0 -13
- data/performance.rb +0 -307
- data/plugins/can_has_sphinx/LICENSE +0 -23
- data/plugins/can_has_sphinx/README +0 -4
- data/plugins/can_has_sphinx/REVISION +0 -1
- data/plugins/can_has_sphinx/Rakefile +0 -22
- data/plugins/can_has_sphinx/init.rb +0 -1
- data/plugins/can_has_sphinx/install.rb +0 -1
- data/plugins/can_has_sphinx/lib/acts_as_sphinx.rb +0 -123
- data/plugins/can_has_sphinx/lib/sphinx.rb +0 -460
- data/plugins/can_has_sphinx/scripts/sphinx.sh +0 -47
- data/plugins/can_has_sphinx/tasks/acts_as_sphinx_tasks.rake +0 -41
- data/profile_data_mapper.rb +0 -40
- data/rakefile.rb +0 -159
- data/spec/acts_as_tree_spec.rb +0 -67
- data/spec/adapters/data_object_adapter_spec.rb +0 -31
- data/spec/associations/belongs_to_association_spec.rb +0 -98
- data/spec/associations/has_and_belongs_to_many_association_spec.rb +0 -377
- data/spec/associations/has_many_association_spec.rb +0 -337
- data/spec/attributes_spec.rb +0 -52
- data/spec/auto_migrations_spec.rb +0 -101
- data/spec/callbacks_spec.rb +0 -186
- data/spec/can_has_sphinx.rb +0 -5
- data/spec/coersion_spec.rb +0 -41
- data/spec/column_spec.rb +0 -114
- data/spec/count_command_spec.rb +0 -45
- data/spec/database_spec.rb +0 -18
- data/spec/dataobjects_spec.rb +0 -27
- data/spec/delete_command_spec.rb +0 -11
- data/spec/dependency_spec.rb +0 -29
- data/spec/embedded_value_spec.rb +0 -161
- data/spec/fixtures/animals.yaml +0 -33
- data/spec/fixtures/animals_exhibits.yaml +0 -2
- data/spec/fixtures/careers.yaml +0 -5
- data/spec/fixtures/comments.yaml +0 -1
- data/spec/fixtures/exhibits.yaml +0 -90
- data/spec/fixtures/fruit.yaml +0 -6
- data/spec/fixtures/people.yaml +0 -37
- data/spec/fixtures/posts.yaml +0 -3
- data/spec/fixtures/projects.yaml +0 -13
- data/spec/fixtures/sections.yaml +0 -5
- data/spec/fixtures/serializers.yaml +0 -6
- data/spec/fixtures/tasks.yaml +0 -6
- data/spec/fixtures/tasks_tasks.yaml +0 -2
- data/spec/fixtures/tomatoes.yaml +0 -1
- data/spec/fixtures/users.yaml +0 -1
- data/spec/fixtures/zoos.yaml +0 -24
- data/spec/is_a_tree_spec.rb +0 -149
- data/spec/legacy_spec.rb +0 -16
- data/spec/load_command_spec.rb +0 -322
- data/spec/magic_columns_spec.rb +0 -26
- data/spec/migration_spec.rb +0 -267
- data/spec/mock_adapter.rb +0 -20
- data/spec/models/animal.rb +0 -12
- data/spec/models/candidate.rb +0 -8
- data/spec/models/career.rb +0 -7
- data/spec/models/chain.rb +0 -8
- data/spec/models/comment.rb +0 -6
- data/spec/models/exhibit.rb +0 -14
- data/spec/models/fence.rb +0 -7
- data/spec/models/fruit.rb +0 -8
- data/spec/models/job.rb +0 -8
- data/spec/models/person.rb +0 -30
- data/spec/models/post.rb +0 -14
- data/spec/models/project.rb +0 -41
- data/spec/models/sales_person.rb +0 -5
- data/spec/models/section.rb +0 -8
- data/spec/models/serializer.rb +0 -5
- data/spec/models/task.rb +0 -9
- data/spec/models/tomato.rb +0 -27
- data/spec/models/user.rb +0 -12
- data/spec/models/zoo.rb +0 -13
- data/spec/natural_key_spec.rb +0 -36
- data/spec/paranoia_spec.rb +0 -38
- data/spec/persistence_spec.rb +0 -479
- data/spec/postgres_spec.rb +0 -96
- data/spec/property_spec.rb +0 -151
- data/spec/query_spec.rb +0 -77
- data/spec/save_command_spec.rb +0 -94
- data/spec/schema_spec.rb +0 -8
- data/spec/serialize_spec.rb +0 -19
- data/spec/single_table_inheritance_spec.rb +0 -43
- data/spec/spec_helper.rb +0 -45
- data/spec/support/blank_spec.rb +0 -8
- data/spec/support/inflector_spec.rb +0 -41
- data/spec/support/object_spec.rb +0 -9
- data/spec/support/serialization_spec.rb +0 -61
- data/spec/support/silence_spec.rb +0 -15
- data/spec/support/string_spec.rb +0 -7
- data/spec/support/struct_spec.rb +0 -12
- data/spec/support/typed_set_spec.rb +0 -66
- data/spec/symbolic_operators_spec.rb +0 -27
- data/spec/table_spec.rb +0 -79
- data/spec/types/string.rb +0 -81
- data/spec/validates_confirmation_of_spec.rb +0 -55
- data/spec/validates_format_of_spec.rb +0 -78
- data/spec/validates_length_of_spec.rb +0 -117
- data/spec/validates_uniqueness_of_spec.rb +0 -92
- data/spec/validations/number_validator.rb +0 -59
- data/spec/validations/string_validator.rb +0 -14
- data/spec/validations_spec.rb +0 -141
- data/tasks/fixtures.rb +0 -53
data/spec/magic_columns_spec.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
-
|
3
|
-
describe "Magic Columns" do
|
4
|
-
|
5
|
-
it "should update updated_at on save" do
|
6
|
-
zoo = Zoo.new(:name => 'Mary')
|
7
|
-
zoo.save
|
8
|
-
zoo.updated_at.should be_a_kind_of(Time)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should not update created_at when updating a model" do
|
12
|
-
section = Section.create(:title => "Mars")
|
13
|
-
old_created_at = section.created_at
|
14
|
-
section.update_attributes(:title => "Mars2!")
|
15
|
-
section.created_at.should eql(old_created_at)
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should not set the created_at/on fields if already set on creation" do
|
19
|
-
section = Section.new(:title => "Mars")
|
20
|
-
fixed_created_at = Time::now - 2600
|
21
|
-
section.created_at = fixed_created_at
|
22
|
-
section.save
|
23
|
-
section.created_at.should eql(fixed_created_at)
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
data/spec/migration_spec.rb
DELETED
@@ -1,267 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
-
require File.dirname(__FILE__) + "/../lib/data_mapper/migration"
|
3
|
-
|
4
|
-
class MigrationUser
|
5
|
-
include DataMapper::Persistence
|
6
|
-
|
7
|
-
property :name, :string
|
8
|
-
property :login, :string
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
def check_schema
|
13
|
-
case ENV['ADAPTER']
|
14
|
-
when 'postgresql'
|
15
|
-
result = database.query("
|
16
|
-
SELECT table_name, column_name FROM information_schema.columns WHERE table_name = 'migration_users'
|
17
|
-
").join(", ")
|
18
|
-
result.blank? ? nil : result
|
19
|
-
when 'mysql'
|
20
|
-
begin
|
21
|
-
database.query("SHOW CREATE TABLE migration_users")[0]["create table"]
|
22
|
-
rescue Exception => e
|
23
|
-
raise e unless e.message.match(/Table.*doesn\'t exist/)
|
24
|
-
end
|
25
|
-
else
|
26
|
-
database.query("
|
27
|
-
SELECT sql FROM
|
28
|
-
(SELECT * FROM sqlite_master UNION ALL
|
29
|
-
SELECT * FROM sqlite_temp_master)
|
30
|
-
WHERE name = 'migration_users'
|
31
|
-
ORDER BY substr(type,2,1), name
|
32
|
-
")[0]
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe DataMapper::Migration do
|
37
|
-
|
38
|
-
class AddUsers < DataMapper::Migration
|
39
|
-
def self.up
|
40
|
-
table :migration_users do # sees that the users table does not exist and so creates the table
|
41
|
-
add :name, :string
|
42
|
-
add :login, :string
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.down
|
47
|
-
table.drop :migration_users
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
class AddPasswordToUsers < DataMapper::Migration
|
52
|
-
def self.up
|
53
|
-
table :migration_users do
|
54
|
-
add :password, :string
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def self.down
|
59
|
-
table :migration_users do
|
60
|
-
remove :password
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
class RenameLoginOnUsers < DataMapper::Migration
|
66
|
-
def self.up
|
67
|
-
table :migration_users do
|
68
|
-
rename :login, :username
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def self.down
|
73
|
-
table :migration_users do
|
74
|
-
rename :username, :login
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
class AlterLoginOnUsers < DataMapper::Migration
|
80
|
-
def self.up
|
81
|
-
table :migration_users do
|
82
|
-
alter :login, :text, :nullable => false, :default => "username"
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def self.down
|
87
|
-
table :migration_users do
|
88
|
-
alter :login, :string
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
it "should migrate up creating a table with its columns" do
|
94
|
-
AddUsers.migrate(:up)
|
95
|
-
database.table_exists?(MigrationUser).should be_true
|
96
|
-
check_schema.should match(/migration_users/)
|
97
|
-
check_schema.should match(/name|login/)
|
98
|
-
user = MigrationUser.new(:name => "test", :login => "username")
|
99
|
-
user.save.should be_true
|
100
|
-
MigrationUser.first.should == user
|
101
|
-
end
|
102
|
-
|
103
|
-
it "should migrate down deleting the created table" do
|
104
|
-
AddUsers.migrate(:down)
|
105
|
-
check_schema.should be_nil
|
106
|
-
database.table_exists?(MigrationUser).should == false
|
107
|
-
end
|
108
|
-
|
109
|
-
it "should migrate up altering a table to add a column" do
|
110
|
-
AddUsers.migrate(:up)
|
111
|
-
AddPasswordToUsers.migrate(:up)
|
112
|
-
table = database.table(MigrationUser)
|
113
|
-
table[:password].should_not be_nil
|
114
|
-
end
|
115
|
-
|
116
|
-
it "should migrate down altering a table to remove a column" do
|
117
|
-
check_schema.should match(/password/)
|
118
|
-
AddPasswordToUsers.migrate(:down)
|
119
|
-
check_schema.should_not match(/password/)
|
120
|
-
table = database.table(MigrationUser)
|
121
|
-
table[:password].should be_nil
|
122
|
-
AddUsers.migrate(:down)
|
123
|
-
end
|
124
|
-
|
125
|
-
it "should migrate up renaming a column" do
|
126
|
-
AddUsers.migrate(:up)
|
127
|
-
user = MigrationUser.create(:name => "Sam", :login => "sammy")
|
128
|
-
RenameLoginOnUsers.migrate(:up)
|
129
|
-
class MigrationUser
|
130
|
-
property :username, :string
|
131
|
-
end
|
132
|
-
check_schema.should match(/username/)
|
133
|
-
check_schema.should_not match(/login/)
|
134
|
-
MigrationUser.first.username.should == user.login
|
135
|
-
end
|
136
|
-
|
137
|
-
it "should migrate down renaming a column" do
|
138
|
-
user = MigrationUser.first
|
139
|
-
RenameLoginOnUsers.migrate(:down)
|
140
|
-
check_schema.should_not match(/username/)
|
141
|
-
check_schema.should match(/login/)
|
142
|
-
MigrationUser.first.login.should == user.username
|
143
|
-
AddUsers.migrate(:down)
|
144
|
-
end
|
145
|
-
|
146
|
-
it "should migrate up altering a column" do
|
147
|
-
AddUsers.migrate(:up)
|
148
|
-
AlterLoginOnUsers.migrate(:up)
|
149
|
-
column = database.table(MigrationUser)[:login]
|
150
|
-
column.type.should == :text
|
151
|
-
column.nullable?.should be_false
|
152
|
-
column.default.should == "username"
|
153
|
-
end
|
154
|
-
|
155
|
-
it "should migrate down altering a column" do
|
156
|
-
AlterLoginOnUsers.migrate(:down)
|
157
|
-
column = database.table(MigrationUser)[:login]
|
158
|
-
column.type.should == :string
|
159
|
-
column.nullable?.should be_true
|
160
|
-
column.default.should be_nil
|
161
|
-
AddUsers.migrate(:down)
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
describe "DataMapper::Migration [RAILS]" do
|
166
|
-
class RailsAddUsers < DataMapper::Migration
|
167
|
-
def self.up
|
168
|
-
create_table :migration_users do |t|
|
169
|
-
t.column :name, :string
|
170
|
-
t.column :login, :string
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
def self.down
|
175
|
-
drop_table :migration_users
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
class RailsAddPasswordToUsers < DataMapper::Migration
|
180
|
-
def self.up
|
181
|
-
add_column :migration_users, :password, :string
|
182
|
-
end
|
183
|
-
|
184
|
-
def self.down
|
185
|
-
remove_column :migration_users, :password
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
class RailsRenameLoginOnUsers < DataMapper::Migration
|
190
|
-
def self.up
|
191
|
-
rename_column :migration_users, :login, :username
|
192
|
-
end
|
193
|
-
|
194
|
-
def self.down
|
195
|
-
rename_column :migration_users, :username, :login
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
class RailsAlterLoginOnUsers < DataMapper::Migration
|
200
|
-
def self.up
|
201
|
-
change_column :migration_users, :login, :text, :nullable => false, :default => "username"
|
202
|
-
end
|
203
|
-
|
204
|
-
def self.down
|
205
|
-
change_column :migration_users, :login, :string
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
it "should migrate up creating a table with its columns" do
|
210
|
-
RailsAddUsers.migrate(:up)
|
211
|
-
database.table_exists?(MigrationUser).should be_true
|
212
|
-
check_schema.should match(/migration_users/)
|
213
|
-
check_schema.should match(/name|login/)
|
214
|
-
end
|
215
|
-
|
216
|
-
it "should migrate down deleting the created table" do
|
217
|
-
RailsAddUsers.migrate(:down)
|
218
|
-
database.table_exists?(MigrationUser).should be_false
|
219
|
-
check_schema.should be_nil
|
220
|
-
end
|
221
|
-
|
222
|
-
it "should migrate up altering a table to add a column" do
|
223
|
-
RailsAddUsers.migrate(:up)
|
224
|
-
RailsAddPasswordToUsers.migrate(:up)
|
225
|
-
check_schema.should match(/password/)
|
226
|
-
end
|
227
|
-
|
228
|
-
it "should migrate down altering a table to remove a column" do
|
229
|
-
RailsAddPasswordToUsers.migrate(:down)
|
230
|
-
check_schema.should_not match(/password/)
|
231
|
-
table = database.table(MigrationUser)
|
232
|
-
table[:password].should be_nil
|
233
|
-
RailsAddUsers.migrate(:down)
|
234
|
-
end
|
235
|
-
|
236
|
-
it "should migrate up renaming a column" do
|
237
|
-
RailsAddUsers.migrate(:up)
|
238
|
-
RailsRenameLoginOnUsers.migrate(:up)
|
239
|
-
check_schema.should match(/username/)
|
240
|
-
check_schema.should_not match(/login/)
|
241
|
-
end
|
242
|
-
|
243
|
-
it "should migrate down renaming a column" do
|
244
|
-
RailsRenameLoginOnUsers.migrate(:down)
|
245
|
-
check_schema.should match(/login/)
|
246
|
-
check_schema.should_not match(/username/)
|
247
|
-
RailsAddUsers.migrate(:down)
|
248
|
-
end
|
249
|
-
|
250
|
-
it "should migrate up altering a column" do
|
251
|
-
AddUsers.migrate(:up)
|
252
|
-
RailsAlterLoginOnUsers.migrate(:up)
|
253
|
-
column = database.table(MigrationUser)[:login]
|
254
|
-
column.type.should == :text
|
255
|
-
column.nullable?.should be_false
|
256
|
-
column.default.should == "username"
|
257
|
-
end
|
258
|
-
|
259
|
-
it "should migrate down altering a column" do
|
260
|
-
RailsAlterLoginOnUsers.migrate(:down)
|
261
|
-
column = database.table(MigrationUser)[:login]
|
262
|
-
column.type.should == :string
|
263
|
-
column.nullable?.should be_true
|
264
|
-
column.default.should be_nil
|
265
|
-
AddUsers.migrate(:down)
|
266
|
-
end
|
267
|
-
end
|
data/spec/mock_adapter.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'data_mapper/adapters/data_object_adapter'
|
2
|
-
|
3
|
-
class MockAdapter < DataMapper::Adapters::DataObjectAdapter
|
4
|
-
COLUMN_QUOTING_CHARACTER = "`"
|
5
|
-
TABLE_QUOTING_CHARACTER = "`"
|
6
|
-
|
7
|
-
def delete(instance_or_klass, options = nil)
|
8
|
-
end
|
9
|
-
|
10
|
-
def save(database_context, instance)
|
11
|
-
end
|
12
|
-
|
13
|
-
def load(database_context, klass, options)
|
14
|
-
end
|
15
|
-
|
16
|
-
def table_exists?(name)
|
17
|
-
true
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
data/spec/models/animal.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
class Animal #< DataMapper::Base # please do not remove this
|
2
|
-
include DataMapper::Persistence
|
3
|
-
|
4
|
-
property :name, :string, :default => "No Name", :index => :unique
|
5
|
-
property :notes, :text
|
6
|
-
property :nice, :boolean
|
7
|
-
|
8
|
-
has_one :favourite_fruit, :class => 'Fruit', :foreign_key => 'devourer_id'
|
9
|
-
has_and_belongs_to_many :exhibits
|
10
|
-
|
11
|
-
DEFAULT_LIMIT = 5
|
12
|
-
end
|
data/spec/models/candidate.rb
DELETED
data/spec/models/career.rb
DELETED
data/spec/models/chain.rb
DELETED
data/spec/models/comment.rb
DELETED
data/spec/models/exhibit.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
class Exhibit #< DataMapper::Base # please do not remove this
|
2
|
-
include DataMapper::Persistence
|
3
|
-
|
4
|
-
property :name, :string
|
5
|
-
|
6
|
-
begin
|
7
|
-
validates_presence_of :name
|
8
|
-
rescue ArgumentError => e
|
9
|
-
throw e unless e.message =~ /specify a unique key/
|
10
|
-
end
|
11
|
-
|
12
|
-
belongs_to :zoo
|
13
|
-
has_and_belongs_to_many :animals
|
14
|
-
end
|
data/spec/models/fence.rb
DELETED
data/spec/models/fruit.rb
DELETED
data/spec/models/job.rb
DELETED
data/spec/models/person.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
class Person #< DataMapper::Base # please do not remove this
|
2
|
-
include DataMapper::Persistence
|
3
|
-
|
4
|
-
property [:name, :occupation], :string
|
5
|
-
property :age, :integer
|
6
|
-
property :type, :class
|
7
|
-
property :notes, :text
|
8
|
-
property :date_of_birth, :date
|
9
|
-
|
10
|
-
embed :address, :prefix => true do
|
11
|
-
property :street, :string
|
12
|
-
property :city, :string
|
13
|
-
property :state, :string, :size => 2
|
14
|
-
property :zip_code, :string, :size => 10
|
15
|
-
|
16
|
-
def city_state_zip_code
|
17
|
-
"#{city}, #{state} #{zip_code}"
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
belongs_to :career
|
23
|
-
|
24
|
-
before_save :before_save_callback
|
25
|
-
|
26
|
-
def before_save_callback
|
27
|
-
@notes = "Lorem ipsum dolor sit amet"
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
data/spec/models/post.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
class Post #< DataMapper::Base # please do not remove this
|
2
|
-
include DataMapper::Persistence
|
3
|
-
|
4
|
-
property :title, :string
|
5
|
-
property :created_at, :datetime
|
6
|
-
|
7
|
-
def next
|
8
|
-
Post.first(:created_at.gte => self.created_at, :id.gt => self.id, :order => "created_at, id")
|
9
|
-
end
|
10
|
-
|
11
|
-
def previous
|
12
|
-
Post.first(:created_at.lte => self.created_at, :id.lt => self.id, :order => "created_at DESC, id DESC")
|
13
|
-
end
|
14
|
-
end
|