spontaneous 0.2.0.beta4 → 0.2.0.beta5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +39 -0
  3. data/Gemfile +11 -6
  4. data/Readme.markdown +136 -69
  5. data/application/css/core.css.scss +27 -7
  6. data/application/css/editing.css.scss +4 -26
  7. data/application/css/schema_error.css.scss +22 -0
  8. data/application/js/content.js +11 -3
  9. data/application/js/edit_panel.js +1 -4
  10. data/application/js/field/file.js +17 -0
  11. data/application/js/field/image.js +30 -21
  12. data/application/js/field/string.js +4 -1
  13. data/application/js/field_preview.js +21 -16
  14. data/application/js/publish.js +6 -6
  15. data/application/js/types.js +5 -13
  16. data/application/js/views.js +2 -2
  17. data/application/js/views/box_view.js +3 -2
  18. data/application/js/views/page_piece_view.js +1 -1
  19. data/application/js/views/piece_view.js +1 -1
  20. data/application/views/schema_modification_error.html.erb +13 -3
  21. data/db/migrations/20131104101935_site_must_publish_all.rb +14 -0
  22. data/lib/spontaneous.rb +0 -1
  23. data/lib/spontaneous/box_style.rb +15 -9
  24. data/lib/spontaneous/capistrano/deploy.rb +13 -1
  25. data/lib/spontaneous/change.rb +11 -13
  26. data/lib/spontaneous/cli.rb +5 -2
  27. data/lib/spontaneous/cli/assets.rb +7 -1
  28. data/lib/spontaneous/cli/console.rb +7 -1
  29. data/lib/spontaneous/cli/content.rb +35 -0
  30. data/lib/spontaneous/cli/fields.rb +3 -2
  31. data/lib/spontaneous/cli/generate.rb +5 -2
  32. data/lib/spontaneous/cli/server.rb +12 -8
  33. data/lib/spontaneous/cli/site.rb +12 -12
  34. data/lib/spontaneous/cli/user.rb +28 -14
  35. data/lib/spontaneous/collections/box_set.rb +4 -4
  36. data/lib/spontaneous/collections/field_set.rb +4 -4
  37. data/lib/spontaneous/collections/prototype_set.rb +12 -4
  38. data/lib/spontaneous/data_mapper.rb +11 -7
  39. data/lib/spontaneous/data_mapper/content_model.rb +8 -0
  40. data/lib/spontaneous/data_mapper/content_model/associations.rb +1 -1
  41. data/lib/spontaneous/data_mapper/dataset.rb +14 -2
  42. data/lib/spontaneous/data_mapper/scope.rb +33 -13
  43. data/lib/spontaneous/facet.rb +4 -0
  44. data/lib/spontaneous/field.rb +12 -12
  45. data/lib/spontaneous/field/base.rb +27 -22
  46. data/lib/spontaneous/field/boolean.rb +4 -4
  47. data/lib/spontaneous/field/date.rb +2 -2
  48. data/lib/spontaneous/field/file.rb +24 -18
  49. data/lib/spontaneous/field/html.rb +1 -1
  50. data/lib/spontaneous/field/image.rb +6 -19
  51. data/lib/spontaneous/field/location.rb +1 -1
  52. data/lib/spontaneous/field/long_string.rb +3 -3
  53. data/lib/spontaneous/field/markdown.rb +3 -3
  54. data/lib/spontaneous/field/select.rb +2 -2
  55. data/lib/spontaneous/field/string.rb +2 -2
  56. data/lib/spontaneous/field/tags.rb +2 -2
  57. data/lib/spontaneous/field/update.rb +21 -20
  58. data/lib/spontaneous/field/webvideo.rb +6 -6
  59. data/lib/spontaneous/field/webvideo/fallback.rb +2 -2
  60. data/lib/spontaneous/field/webvideo/vimeo.rb +7 -7
  61. data/lib/spontaneous/generators/site.rb +2 -2
  62. data/lib/spontaneous/generators/site/Gemfile.tt +5 -1
  63. data/lib/spontaneous/layout.rb +2 -2
  64. data/lib/spontaneous/media.rb +1 -0
  65. data/lib/spontaneous/media/file.rb +6 -5
  66. data/lib/spontaneous/media/image/attributes.rb +4 -0
  67. data/lib/spontaneous/media/image/renderable.rb +4 -4
  68. data/lib/spontaneous/media/store.rb +22 -0
  69. data/lib/spontaneous/{storage → media/store}/backend.rb +1 -1
  70. data/lib/spontaneous/{storage → media/store}/cloud.rb +1 -1
  71. data/lib/spontaneous/{storage → media/store}/local.rb +1 -1
  72. data/lib/spontaneous/media/temp_file.rb +1 -1
  73. data/lib/spontaneous/model.rb +10 -7
  74. data/lib/spontaneous/model/action.rb +7 -0
  75. data/lib/spontaneous/model/action/clean.rb +87 -0
  76. data/lib/spontaneous/model/box/allowed_types.rb +15 -1
  77. data/lib/spontaneous/model/core.rb +10 -0
  78. data/lib/spontaneous/model/core/aliases.rb +1 -1
  79. data/lib/spontaneous/model/core/content_groups.rb +1 -1
  80. data/lib/spontaneous/model/core/fields.rb +1 -1
  81. data/lib/spontaneous/model/core/modifications.rb +2 -2
  82. data/lib/spontaneous/model/core/page_search.rb +4 -0
  83. data/lib/spontaneous/model/core/publishing.rb +4 -17
  84. data/lib/spontaneous/model/core/render.rb +4 -4
  85. data/lib/spontaneous/model/core/styles.rb +2 -2
  86. data/lib/spontaneous/model/core/visibility.rb +6 -2
  87. data/lib/spontaneous/model/page.rb +6 -2
  88. data/lib/spontaneous/model/page/controllers.rb +55 -17
  89. data/lib/spontaneous/model/page/formats.rb +12 -7
  90. data/lib/spontaneous/model/page/layouts.rb +2 -2
  91. data/lib/spontaneous/model/page/locks.rb +4 -1
  92. data/lib/spontaneous/model/page/page_tree.rb +40 -6
  93. data/lib/spontaneous/output.rb +14 -52
  94. data/lib/spontaneous/output/context.rb +11 -39
  95. data/lib/spontaneous/output/context/navigation.rb +31 -0
  96. data/lib/spontaneous/output/format.rb +15 -19
  97. data/lib/spontaneous/output/renderable.rb +99 -0
  98. data/lib/spontaneous/output/store.rb +24 -0
  99. data/lib/spontaneous/output/store/backend.rb +52 -0
  100. data/lib/spontaneous/output/store/file.rb +77 -0
  101. data/lib/spontaneous/output/store/moneta.rb +117 -0
  102. data/lib/spontaneous/output/store/revision.rb +34 -0
  103. data/lib/spontaneous/output/store/store.rb +15 -0
  104. data/lib/spontaneous/output/store/transaction.rb +44 -0
  105. data/lib/spontaneous/output/template/engine.rb +17 -7
  106. data/lib/spontaneous/output/template/renderer.rb +66 -40
  107. data/lib/spontaneous/page_lock.rb +5 -7
  108. data/lib/spontaneous/page_piece.rb +2 -2
  109. data/lib/spontaneous/permissions/user.rb +14 -7
  110. data/lib/spontaneous/plugins/application/features.rb +8 -4
  111. data/lib/spontaneous/plugins/application/state.rb +12 -6
  112. data/lib/spontaneous/prototypes/box_prototype.rb +9 -10
  113. data/lib/spontaneous/prototypes/field_prototype.rb +66 -15
  114. data/lib/spontaneous/publishing/immediate.rb +30 -26
  115. data/lib/spontaneous/rack.rb +12 -7
  116. data/lib/spontaneous/rack/back.rb +43 -37
  117. data/lib/spontaneous/rack/back/base.rb +4 -4
  118. data/lib/spontaneous/rack/back/changes.rb +2 -2
  119. data/lib/spontaneous/rack/back/file.rb +16 -24
  120. data/lib/spontaneous/rack/back/map.rb +5 -5
  121. data/lib/spontaneous/rack/back/preview.rb +3 -4
  122. data/lib/spontaneous/rack/back/schema.rb +1 -1
  123. data/lib/spontaneous/rack/back/site.rb +6 -7
  124. data/lib/spontaneous/rack/front.rb +19 -16
  125. data/lib/spontaneous/rack/middleware/authenticate.rb +3 -3
  126. data/lib/spontaneous/rack/middleware/reloader.rb +3 -2
  127. data/lib/spontaneous/rack/middleware/scope.rb +25 -19
  128. data/lib/spontaneous/rack/page_controller.rb +164 -13
  129. data/lib/spontaneous/rack/public.rb +23 -62
  130. data/lib/spontaneous/rack/static.rb +2 -3
  131. data/lib/spontaneous/schema.rb +27 -8
  132. data/lib/spontaneous/schema/schema_modification.rb +9 -1
  133. data/lib/spontaneous/schema/uid.rb +2 -2
  134. data/lib/spontaneous/schema/uid_map.rb +3 -2
  135. data/lib/spontaneous/search/database.rb +2 -2
  136. data/lib/spontaneous/search/field.rb +5 -3
  137. data/lib/spontaneous/search/index.rb +12 -7
  138. data/lib/spontaneous/search/results.rb +5 -3
  139. data/lib/spontaneous/server.rb +2 -2
  140. data/lib/spontaneous/site.rb +10 -3
  141. data/lib/spontaneous/site/features.rb +26 -6
  142. data/lib/spontaneous/site/helpers.rb +9 -12
  143. data/lib/spontaneous/site/level.rb +7 -9
  144. data/lib/spontaneous/site/map.rb +9 -11
  145. data/lib/spontaneous/site/paths.rb +5 -5
  146. data/lib/spontaneous/site/publishing.rb +83 -80
  147. data/lib/spontaneous/site/schema.rb +1 -7
  148. data/lib/spontaneous/site/search.rb +8 -18
  149. data/lib/spontaneous/site/selectors.rb +60 -54
  150. data/lib/spontaneous/site/state.rb +36 -30
  151. data/lib/spontaneous/site/storage.rb +10 -16
  152. data/lib/spontaneous/state.rb +8 -0
  153. data/lib/spontaneous/style.rb +32 -33
  154. data/lib/spontaneous/version.rb +1 -1
  155. data/spontaneous.gemspec +22 -21
  156. data/test/fixtures/public/templates/layouts/default.html.cut +1 -1
  157. data/test/fixtures/public/templates/layouts/default.pdf.cut +1 -1
  158. data/test/fixtures/public/templates/layouts/default.rss.cut +1 -1
  159. data/test/fixtures/search/config/indexes.rb +1 -1
  160. data/test/fixtures/serialisation/class_hash.yaml.erb +13 -1
  161. data/test/fixtures/serialisation/root_hash.yaml.erb +10 -0
  162. data/test/functional/test_application.rb +20 -24
  163. data/test/functional/test_back.rb +26 -27
  164. data/test/functional/test_cli.rb +146 -0
  165. data/test/functional/test_front.rb +287 -216
  166. data/test/functional/test_user_manager.rb +1 -1
  167. data/test/test_helper.rb +15 -11
  168. data/test/unit/test_alias.rb +32 -25
  169. data/test/unit/test_asset_bundler.rb +1 -1
  170. data/test/unit/test_assets.rb +34 -33
  171. data/test/unit/test_authentication.rb +1 -1
  172. data/test/unit/test_boxes.rb +16 -2
  173. data/test/unit/test_changesets.rb +23 -11
  174. data/test/unit/test_content.rb +15 -0
  175. data/test/unit/test_context.rb +139 -0
  176. data/test/unit/test_controllers.rb +374 -0
  177. data/test/{experimental → unit}/test_crypt.rb +0 -0
  178. data/test/unit/test_datamapper.rb +260 -237
  179. data/test/unit/test_datamapper_content.rb +42 -12
  180. data/test/{experimental → unit}/test_features.rb +85 -3
  181. data/test/unit/test_fields.rb +117 -42
  182. data/test/unit/test_formats.rb +11 -1
  183. data/test/unit/test_generators.rb +2 -2
  184. data/test/unit/test_helpers.rb +7 -8
  185. data/test/unit/test_images.rb +39 -2
  186. data/test/unit/test_layouts.rb +14 -12
  187. data/test/unit/test_media.rb +32 -23
  188. data/test/unit/test_output_store.rb +342 -0
  189. data/test/unit/test_page.rb +8 -1
  190. data/test/unit/test_permissions.rb +11 -7
  191. data/test/unit/test_plugins.rb +3 -3
  192. data/test/unit/test_prototype_set.rb +8 -1
  193. data/test/unit/test_publishing.rb +67 -54
  194. data/test/unit/test_render.rb +91 -38
  195. data/test/unit/test_revisions.rb +4 -4
  196. data/test/unit/test_schema.rb +109 -84
  197. data/test/unit/test_search.rb +42 -42
  198. data/test/unit/test_serialisation.rb +3 -2
  199. data/test/unit/test_site.rb +39 -27
  200. data/test/unit/test_storage.rb +9 -6
  201. data/test/unit/test_styles.rb +25 -32
  202. data/test/unit/test_templates.rb +8 -4
  203. metadata +89 -54
  204. data/lib/spontaneous/model/page/request.rb +0 -105
  205. data/lib/spontaneous/storage.rb +0 -22
File without changes
@@ -24,7 +24,7 @@ describe "DataMapper" do
24
24
  @expected_columns = [:id, :type_sid, :label, :object1, :object2]
25
25
  @database = ::Sequel.mock(autoid: 1)
26
26
  @table = Spontaneous::DataMapper::ContentTable.new(:content, @database)
27
- @schema = Spontaneous::Schema.new(Dir.pwd, NameMap)
27
+ @schema = Spontaneous::Schema.new(@site, Dir.pwd, NameMap)
28
28
  @mapper = Spontaneous::DataMapper.new(@table, @schema)
29
29
  @database.columns = @expected_columns
30
30
  Spontaneous::DataMapper.stubs(:timestamp).returns(@now)
@@ -33,12 +33,14 @@ describe "DataMapper" do
33
33
  end
34
34
  # having timestamps on makes testing the sql very difficult/tedious
35
35
  MockContent2 = Class.new(MockContent)
36
+ MockContent3 = Class.new(MockContent)
36
37
  @database.sqls # clear sql log -- column introspection makes a query to the db
37
38
  end
38
39
 
39
40
  after do
40
41
  Object.send :remove_const, :MockContent rescue nil
41
42
  Object.send :remove_const, :MockContent2 rescue nil
43
+ Object.send :remove_const, :MockContent3 rescue nil
42
44
  teardown_site
43
45
  end
44
46
 
@@ -50,12 +52,12 @@ describe "DataMapper" do
50
52
 
51
53
  describe "instances" do
52
54
  it "insert model data when saving a new model instance" do
53
- @database.fetch = { id:1, label:"column1", type_sid:"MockContent" }
54
- instance = MockContent.new(:label => "column1")
55
+ @database.fetch = { id:1, label:"column1", type_sid:"MockContent2" }
56
+ instance = MockContent2.new(:label => "column1")
55
57
  assert instance.new?
56
58
  @mapper.create(instance)
57
59
  @database.sqls.must_equal [
58
- "INSERT INTO content (label, type_sid) VALUES ('column1', 'MockContent')",
60
+ "INSERT INTO content (label, type_sid) VALUES ('column1', 'MockContent2')",
59
61
  "SELECT * FROM content WHERE (id = 1) LIMIT 1"
60
62
  ]
61
63
  refute instance.new?
@@ -63,10 +65,10 @@ describe "DataMapper" do
63
65
  end
64
66
 
65
67
  it "insert models using the DataMapper.create method" do
66
- @database.fetch = { id:1, label:"column1", type_sid:"MockContent" }
67
- instance = @mapper.instance MockContent, :label => "column1"
68
+ @database.fetch = { id:1, label:"column1", type_sid:"MockContent2" }
69
+ instance = @mapper.instance MockContent2, :label => "column1"
68
70
  @database.sqls.must_equal [
69
- "INSERT INTO content (label, type_sid) VALUES ('column1', 'MockContent')",
71
+ "INSERT INTO content (label, type_sid) VALUES ('column1', 'MockContent2')",
70
72
  "SELECT * FROM content WHERE (id = 1) LIMIT 1"
71
73
  ]
72
74
  refute instance.new?
@@ -74,66 +76,75 @@ describe "DataMapper" do
74
76
  end
75
77
 
76
78
  it "update an existing model" do
77
- @database.fetch = { id:1, label:"column1", type_sid:"MockContent" }
78
- instance = @mapper.instance MockContent, :label => "column1"
79
+ @database.fetch = { id:1, label:"column1", type_sid:"MockContent2" }
80
+ instance = @mapper.instance MockContent2, :label => "column1"
79
81
  instance.set label: "changed"
80
82
  @mapper.save(instance)
81
83
  @database.sqls.must_equal [
82
- "INSERT INTO content (label, type_sid) VALUES ('column1', 'MockContent')",
84
+ "INSERT INTO content (label, type_sid) VALUES ('column1', 'MockContent2')",
83
85
  "SELECT * FROM content WHERE (id = 1) LIMIT 1",
84
86
  "UPDATE content SET label = 'changed' WHERE (id = 1)"
85
87
  ]
86
88
  end
87
89
 
88
90
  it "update model rows directly" do
89
- @mapper.update([MockContent], label: "changed")
91
+ @mapper.update([MockContent2], label: "changed")
90
92
  @database.sqls.must_equal [
91
- "UPDATE content SET label = 'changed' WHERE (type_sid IN ('MockContent'))"
93
+ "UPDATE content SET label = 'changed' WHERE (type_sid IN ('MockContent2'))"
92
94
  ]
93
95
  end
94
96
 
95
97
  it "find an existing model" do
96
- instance = @mapper.instance MockContent, :label => "column1"
98
+ instance = @mapper.instance MockContent2, :label => "column1"
97
99
  @database.sqls # clear the sql log
98
- @database.fetch = { id:1, label:"column1", type_sid:"MockContent" }
100
+ @database.fetch = { id:1, label:"column1", type_sid:"MockContent2" }
99
101
  instance = @mapper.get(1)
100
102
  @database.sqls.must_equal [
101
- "SELECT * FROM content WHERE (id = 1) LIMIT 1"
103
+ "SELECT * FROM content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (id = 1)) LIMIT 1"
102
104
  ]
103
- instance.must_be_instance_of MockContent
105
+ instance.must_be_instance_of MockContent2
104
106
  instance.id.must_equal 1
105
107
  instance.attributes[:label].must_equal "column1"
106
108
  end
107
109
 
110
+ it "responds to Sequel's #primary_key_lookup" do
111
+ @database.sqls # clear the sql log
112
+ @database.fetch = { id:1, label:"column1", type_sid:"MockContent2" }
113
+ instance = @mapper.primary_key_lookup(1)
114
+ @database.sqls.must_equal [
115
+ "SELECT * FROM content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (id = 1)) LIMIT 1"
116
+ ]
117
+ end
118
+
108
119
  it "retirieve a list of objects in the specified order" do
109
- instance = @mapper.instance MockContent, :label => "column1"
120
+ # instance = @mapper.instance MockContent2, :label => "column1"
110
121
  @database.sqls # clear the sql log
111
122
  @database.fetch = [
112
- { id:1, type_sid:"MockContent" },
113
- { id:2, type_sid:"MockContent" },
114
- { id:3, type_sid:"MockContent" },
115
- { id:4, type_sid:"MockContent" }
123
+ { id:1, type_sid:"MockContent2" },
124
+ { id:2, type_sid:"MockContent2" },
125
+ { id:3, type_sid:"MockContent2" },
126
+ { id:4, type_sid:"MockContent2" }
116
127
  ]
117
128
  results = @mapper.get([2, 3, 4, 1])
118
129
  results.map(&:id).must_equal [2, 3, 4, 1]
119
130
  end
120
131
 
121
132
  it "allow for finding the first instance of a model" do
122
- @database.fetch = { id:1, label:"column1", type_sid:"MockContent" }
123
- instance = @mapper.first([MockContent], id: 1)
133
+ @database.fetch = { id:1, label:"column1", type_sid:"MockContent2" }
134
+ instance = @mapper.first([MockContent2], id: 1)
124
135
  @database.sqls.must_equal [
125
- "SELECT * FROM content WHERE ((type_sid IN ('MockContent')) AND (id = 1)) LIMIT 1"
136
+ "SELECT * FROM content WHERE ((type_sid IN ('MockContent2')) AND (id = 1)) LIMIT 1"
126
137
  ]
127
138
  end
128
139
 
129
140
  it "be scopable to a revision" do
130
- @database.fetch = { id:1, label:"column1", type_sid:"MockContent" }
141
+ @database.fetch = { id:1, label:"column1", type_sid:"MockContent2" }
131
142
  @mapper.revision(10) do
132
- instance = @mapper.instance MockContent, :label => "column1"
143
+ instance = @mapper.instance MockContent2, :label => "column1"
133
144
  instance.set label: "changed"
134
145
  @mapper.save(instance)
135
146
  @database.sqls.must_equal [
136
- "INSERT INTO __r00010_content (label, type_sid) VALUES ('column1', 'MockContent')",
147
+ "INSERT INTO __r00010_content (label, type_sid) VALUES ('column1', 'MockContent2')",
137
148
  "SELECT * FROM __r00010_content WHERE (id = 1) LIMIT 1",
138
149
  "UPDATE __r00010_content SET label = 'changed' WHERE (id = 1)"
139
150
  ]
@@ -148,16 +159,16 @@ describe "DataMapper" do
148
159
  end
149
160
 
150
161
  it "allow for retrieval of rows from a specific revision" do
151
- @database.fetch = { id:1, label:"column1", type_sid:"MockContent" }
162
+ @database.fetch = { id:1, label:"column1", type_sid:"MockContent2" }
152
163
  instance = @mapper.revision(20).get(1)
153
- @database.sqls.must_equal ["SELECT * FROM __r00020_content WHERE (id = 1) LIMIT 1"]
154
- instance.must_be_instance_of MockContent
164
+ @database.sqls.must_equal ["SELECT * FROM __r00020_content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (id = 1)) LIMIT 1"]
165
+ instance.must_be_instance_of MockContent2
155
166
  instance.id.must_equal 1
156
167
  instance.attributes[:label].must_equal "column1"
157
168
  end
158
169
 
159
170
  it "support nested revision scopes" do
160
- @database.fetch = { id:1, label:"column1", type_sid:"MockContent" }
171
+ @database.fetch = { id:1, label:"column1", type_sid:"MockContent2" }
161
172
  @mapper.revision(10) do
162
173
  instance = @mapper.get(1)
163
174
  instance.label = "changed1"
@@ -170,130 +181,132 @@ describe "DataMapper" do
170
181
  end
171
182
  end
172
183
  @database.sqls.must_equal [
173
- "SELECT * FROM __r00010_content WHERE (id = 1) LIMIT 1",
184
+ "SELECT * FROM __r00010_content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (id = 1)) LIMIT 1",
174
185
  "UPDATE __r00010_content SET label = 'changed1' WHERE (id = 1)",
175
- "SELECT * FROM __r00020_content WHERE (id = 1) LIMIT 1",
186
+ "SELECT * FROM __r00020_content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (id = 1)) LIMIT 1",
176
187
  "UPDATE __r00020_content SET label = 'changed2' WHERE (id = 1)",
177
- "SELECT * FROM content WHERE (id = 3) LIMIT 1"
188
+ "SELECT * FROM content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (id = 3)) LIMIT 1"
178
189
  ]
179
190
  end
180
191
 
181
192
  it "allow for finding all instances of a class with DataMapper#all" do
182
193
  @database.fetch = [
183
- { id:1, label:"column1", type_sid:"MockContent" },
184
- { id:2, label:"column2", type_sid:"MockContent2" }
185
- ]
186
- results = @mapper.all([MockContent, MockContent2])
187
- @database.sqls.must_equal [
188
- "SELECT * FROM content WHERE (type_sid IN ('MockContent', 'MockContent2'))"
189
- ]
190
- results.map(&:class).must_equal [MockContent, MockContent2]
191
- results.map(&:id).must_equal [1, 2]
192
- end
193
-
194
- it "allow for finding all instances of a class with DataMapper#types" do
195
- @database.fetch = [
196
- { id:1, label:"column1", type_sid:"MockContent" },
197
- { id:2, label:"column2", type_sid:"MockContent2" }
194
+ { id:1, label:"column1", type_sid:"MockContent2" },
195
+ { id:2, label:"column2", type_sid:"MockContent3" }
198
196
  ]
199
- results = @mapper.all([MockContent, MockContent2])
197
+ results = @mapper.all([MockContent2, MockContent3])
200
198
  @database.sqls.must_equal [
201
- "SELECT * FROM content WHERE (type_sid IN ('MockContent', 'MockContent2'))"
199
+ "SELECT * FROM content WHERE (type_sid IN ('MockContent2', 'MockContent3'))"
202
200
  ]
203
- results.map(&:class).must_equal [MockContent, MockContent2]
201
+ results.map(&:class).must_equal [MockContent2, MockContent3]
204
202
  results.map(&:id).must_equal [1, 2]
205
203
  end
206
204
 
207
205
  it "allow for counting type rows" do
208
- @mapper.count([MockContent, MockContent2])
206
+ @mapper.count([MockContent2, MockContent3])
209
207
  @database.sqls.must_equal [
210
- "SELECT COUNT(*) AS count FROM content WHERE (type_sid IN ('MockContent', 'MockContent2')) LIMIT 1"
208
+ "SELECT count(*) AS count FROM content WHERE (type_sid IN ('MockContent2', 'MockContent3')) LIMIT 1"
211
209
  ]
212
210
  end
213
211
 
214
212
  it "allow for use of block iterator when loading all model instances" do
215
213
  ids = []
216
214
  @database.fetch = [
217
- { id:1, label:"column1", type_sid:"MockContent" },
218
- { id:2, label:"column2", type_sid:"MockContent2" }
215
+ { id:1, label:"column1", type_sid:"MockContent2" },
216
+ { id:2, label:"column2", type_sid:"MockContent3" }
219
217
  ]
220
- results = @mapper.all([MockContent, MockContent2]) do |i|
218
+ results = @mapper.all([MockContent2, MockContent3]) do |i|
221
219
  ids << i.id
222
220
  end
223
221
  ids.must_equal [1, 2]
224
- results.map(&:class).must_equal [MockContent, MockContent2]
222
+ results.map(&:class).must_equal [MockContent2, MockContent3]
225
223
  end
226
224
 
227
225
  it "allow for defining an order" do
228
- ds = @mapper.order([MockContent], "column1").all
226
+ ds = @mapper.order([MockContent2], "column1").all
229
227
  @database.sqls.must_equal [
230
- "SELECT * FROM content WHERE (type_sid IN ('MockContent')) ORDER BY 'column1'"
228
+ "SELECT * FROM content WHERE (type_sid IN ('MockContent2')) ORDER BY 'column1'"
231
229
  ]
232
230
  end
233
231
 
234
232
  it "allow for defining a limit" do
235
- ds = @mapper.limit([MockContent], 10...20).all
233
+ ds = @mapper.limit([MockContent2], 10...20).all
236
234
  ds = @mapper.filter([], label: "this").limit(10).all
237
235
  @database.sqls.must_equal [
238
- "SELECT * FROM content WHERE (type_sid IN ('MockContent')) LIMIT 10 OFFSET 10",
239
- "SELECT * FROM content WHERE (label = 'this') LIMIT 10"
236
+ "SELECT * FROM content WHERE (type_sid IN ('MockContent2')) LIMIT 10 OFFSET 10",
237
+ "SELECT * FROM content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (label = 'this')) LIMIT 10"
240
238
  ]
241
239
  end
242
240
 
243
241
  it "support chained filters" do
244
242
  @database.fetch = [
245
- { id:1, label:"column1", type_sid:"MockContent" }
243
+ { id:1, label:"column1", type_sid:"MockContent2" }
246
244
  ]
247
- ds = @mapper.filter([MockContent, MockContent2], id:1)
245
+ ds = @mapper.filter([MockContent2, MockContent3], id:1)
248
246
  results = ds.all
249
- results.map(&:class).must_equal [MockContent]
247
+ results.map(&:class).must_equal [MockContent2]
250
248
  results.map(&:id).must_equal [1]
251
249
  @database.sqls.must_equal [
252
- "SELECT * FROM content WHERE ((type_sid IN ('MockContent', 'MockContent2')) AND (id = 1))"
250
+ "SELECT * FROM content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (id = 1))"
253
251
  ]
254
252
  end
255
253
 
256
254
  it "support filtering using virtual rows" do
257
255
  @database.fetch = [
258
- { id:1, label:"column1", type_sid:"MockContent" },
259
- { id:2, label:"column2", type_sid:"MockContent2" }
256
+ { id:1, label:"column1", type_sid:"MockContent2" },
257
+ { id:2, label:"column2", type_sid:"MockContent3" }
260
258
  ]
261
- ds = @mapper.filter([MockContent, MockContent2]) { id > 0 }
259
+ ds = @mapper.filter([MockContent2, MockContent3]) { id > 0 }
262
260
  results = ds.all
263
- results.map(&:class).must_equal [MockContent, MockContent2]
261
+ results.map(&:class).must_equal [MockContent2, MockContent3]
264
262
  results.map(&:id).must_equal [1, 2]
265
263
  @database.sqls.must_equal [
266
- "SELECT * FROM content WHERE ((type_sid IN ('MockContent', 'MockContent2')) AND (id > 0))"
264
+ "SELECT * FROM content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (id > 0))"
267
265
  ]
268
266
  end
269
267
 
270
268
  it "support multiple concurrent filters" do
271
269
  # want to be sure that each dataset is independent
272
- ds1 = @mapper.filter([MockContent], id: 1)
273
- ds2 = @mapper.filter([MockContent2])
270
+ ds1 = @mapper.filter([MockContent2], id: 1)
271
+ ds2 = @mapper.filter([MockContent3])
274
272
 
275
- @database.fetch = { id:1, label:"column1", type_sid:"MockContent" }
276
- ds1.first([]).must_be_instance_of MockContent
273
+ @database.fetch = { id:1, label:"column1", type_sid:"MockContent2" }
274
+ ds1.first([]).must_be_instance_of MockContent2
277
275
 
278
- @database.fetch = { id:2, label:"column2", type_sid:"MockContent2" }
279
- ds2.first([]).must_be_instance_of MockContent2
276
+ @database.fetch = { id:2, label:"column2", type_sid:"MockContent3" }
277
+ ds2.first([]).must_be_instance_of MockContent3
278
+
279
+ @database.sqls.must_equal [
280
+ "SELECT * FROM content WHERE ((type_sid IN ('MockContent2')) AND (id = 1)) LIMIT 1",
281
+ "SELECT * FROM content WHERE (type_sid IN ('MockContent3')) LIMIT 1"
282
+ ]
283
+ end
284
+
285
+
286
+ it "allows you to invert the conditions" do
287
+ ds = @mapper.filter([MockContent2]).invert.all
288
+ @database.sqls.must_equal [
289
+ "SELECT * FROM content WHERE (type_sid NOT IN ('MockContent2'))",
290
+ ]
291
+ end
280
292
 
293
+ it "allow you to delete all content" do
294
+ @mapper.delete
281
295
  @database.sqls.must_equal [
282
- "SELECT * FROM content WHERE ((type_sid IN ('MockContent')) AND (id = 1)) LIMIT 1",
283
- "SELECT * FROM content WHERE (type_sid IN ('MockContent2')) LIMIT 1"
296
+ "DELETE FROM content"
284
297
  ]
285
298
  end
286
299
 
287
300
  it "allow you to delete datasets" do
288
- @mapper.delete([MockContent])
301
+ @mapper.delete([MockContent2])
289
302
  @database.sqls.must_equal [
290
- "DELETE FROM content WHERE (type_sid IN ('MockContent'))"
303
+ "DELETE FROM content WHERE (type_sid IN ('MockContent2'))"
291
304
  ]
292
305
  end
293
306
 
294
307
  it "allow you to delete instances" do
295
- @database.fetch = { id:1, label:"label", type_sid:"MockContent" }
296
- instance = @mapper.instance MockContent, label: "label"
308
+ @database.fetch = { id:1, label:"label", type_sid:"MockContent2" }
309
+ instance = @mapper.instance MockContent2, label: "label"
297
310
  @database.sqls
298
311
  @mapper.delete_instance instance
299
312
  @database.sqls.must_equal [
@@ -302,8 +315,8 @@ describe "DataMapper" do
302
315
  end
303
316
 
304
317
  it "allow you to delete instances within a revision" do
305
- @database.fetch = { id:1, label:"label", type_sid:"MockContent" }
306
- instance = @mapper.instance MockContent, label: "label"
318
+ @database.fetch = { id:1, label:"label", type_sid:"MockContent2" }
319
+ instance = @mapper.instance MockContent2, label: "label"
307
320
  @database.sqls
308
321
  @mapper.revision(20) do
309
322
  @mapper.delete_instance instance
@@ -314,8 +327,8 @@ describe "DataMapper" do
314
327
  end
315
328
 
316
329
  it "allow you to destroy model instances" do
317
- @database.fetch = { id:1, label:"column1", type_sid:"MockContent" }
318
- instance = @mapper.instance MockContent, :label => "column1"
330
+ @database.fetch = { id:1, label:"column1", type_sid:"MockContent2" }
331
+ instance = @mapper.instance MockContent2, :label => "column1"
319
332
  @database.sqls # clear sql log
320
333
  @mapper.delete_instance instance
321
334
  instance.id.must_equal 1
@@ -325,7 +338,7 @@ describe "DataMapper" do
325
338
  end
326
339
 
327
340
  it "support visibility contexts" do
328
- @database.fetch = { id:1, label:"column1", type_sid:"MockContent" }
341
+ @database.fetch = { id:1, label:"column1", type_sid:"MockContent2" }
329
342
  @mapper.visible do
330
343
  @mapper.get(1)
331
344
  @mapper.visible(false) do
@@ -334,27 +347,27 @@ describe "DataMapper" do
334
347
  end
335
348
  end
336
349
  @database.sqls.must_equal [
337
- "SELECT * FROM content WHERE ((hidden IS FALSE) AND (id = 1)) LIMIT 1",
338
- "SELECT * FROM content WHERE (id = 1) LIMIT 1",
339
- "SELECT * FROM content WHERE ((hidden IS FALSE) AND (id = 1)) LIMIT 1",
350
+ "SELECT * FROM content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (hidden IS FALSE) AND (id = 1)) LIMIT 1",
351
+ "SELECT * FROM content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (id = 1)) LIMIT 1",
352
+ "SELECT * FROM content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (hidden IS FALSE) AND (id = 1)) LIMIT 1",
340
353
  ]
341
354
  end
342
355
 
343
356
  it "support mixed revision & visibility states" do
344
- @database.fetch = { id:1, label:"column1", type_sid:"MockContent" }
357
+ @database.fetch = { id:1, label:"column1", type_sid:"MockContent2" }
345
358
  @mapper.revision(25) do
346
359
  @mapper.visible do
347
360
  @mapper.get(1)
348
361
  end
349
362
  end
350
363
  @database.sqls.must_equal [
351
- "SELECT * FROM __r00025_content WHERE ((hidden IS FALSE) AND (id = 1)) LIMIT 1",
364
+ "SELECT * FROM __r00025_content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (hidden IS FALSE) AND (id = 1)) LIMIT 1",
352
365
  ]
353
366
  end
354
367
 
355
368
  it "ignore visibility filter for deletes" do
356
- @database.fetch = { id:1, label:"label", type_sid:"MockContent" }
357
- instance = @mapper.instance MockContent, label: "label"
369
+ @database.fetch = { id:1, label:"label", type_sid:"MockContent2" }
370
+ instance = @mapper.instance MockContent2, label: "label"
358
371
  @database.sqls
359
372
  @mapper.visible do
360
373
  @mapper.delete_instance(instance)
@@ -367,36 +380,46 @@ describe "DataMapper" do
367
380
  it "ignore visibility setting for creates" do
368
381
  @mapper.visible do
369
382
  @mapper.revision(99) do
370
- instance = @mapper.instance MockContent, :label => "column1"
383
+ instance = @mapper.instance MockContent2, :label => "column1"
371
384
  end
372
385
  end
373
386
  @database.sqls.must_equal [
374
- "INSERT INTO __r00099_content (label, type_sid) VALUES ('column1', 'MockContent')",
387
+ "INSERT INTO __r00099_content (label, type_sid) VALUES ('column1', 'MockContent2')",
375
388
  "SELECT * FROM __r00099_content WHERE (id = 1) LIMIT 1"
376
389
  ]
377
390
  end
378
391
 
379
392
  it "allow for inserting raw attributes" do
380
- @mapper.insert type_sid: "MockContent", label: "label"
393
+ @mapper.insert type_sid: "MockContent2", label: "label"
381
394
  @database.sqls.must_equal [
382
- "INSERT INTO content (type_sid, label) VALUES ('MockContent', 'label')"
395
+ "INSERT INTO content (type_sid, label) VALUES ('MockContent2', 'label')"
383
396
  ]
384
397
  end
385
398
  end
386
399
 
387
400
  describe "models" do
388
- it "be deletable" do
401
+ it "can clean the db completely" do
402
+ def MockContent.types
403
+ nil
404
+ end
389
405
  MockContent.delete
390
406
  @database.sqls.must_equal [
391
- "DELETE FROM content WHERE (type_sid IN ('MockContent'))"
407
+ "DELETE FROM content"
408
+ ]
409
+ end
410
+
411
+ it "be deletable" do
412
+ MockContent2.delete
413
+ @database.sqls.must_equal [
414
+ "DELETE FROM content WHERE (type_sid IN ('MockContent2'))"
392
415
  ]
393
416
  end
394
417
 
395
418
  it "be creatable using Model.create" do
396
- @database.fetch = { id:1, label:"value", type_sid:"MockContent" }
397
- instance = MockContent.create(label: "value")
419
+ @database.fetch = { id:1, label:"value", type_sid:"MockContent2" }
420
+ instance = MockContent2.create(label: "value")
398
421
  @database.sqls.must_equal [
399
- "INSERT INTO content (label, type_sid) VALUES ('value', 'MockContent')",
422
+ "INSERT INTO content (label, type_sid) VALUES ('value', 'MockContent2')",
400
423
  "SELECT * FROM content WHERE (id = 1) LIMIT 1"
401
424
  ]
402
425
  refute instance.new?
@@ -404,40 +427,40 @@ describe "DataMapper" do
404
427
  end
405
428
 
406
429
  it "be instantiable using Model.new" do
407
- instance = MockContent.new(label: "value")
430
+ instance = MockContent2.new(label: "value")
408
431
  assert instance.new?
409
432
  end
410
433
 
411
434
  it "be creatable using Model.new" do
412
- @database.fetch = { id:1, label:"value", type_sid:"MockContent" }
413
- instance = MockContent.new(label: "value")
435
+ @database.fetch = { id:1, label:"value", type_sid:"MockContent2" }
436
+ instance = MockContent2.new(label: "value")
414
437
  instance.save
415
438
  refute instance.new?
416
439
  @database.sqls.must_equal [
417
- "INSERT INTO content (label, type_sid) VALUES ('value', 'MockContent')",
440
+ "INSERT INTO content (label, type_sid) VALUES ('value', 'MockContent2')",
418
441
  "SELECT * FROM content WHERE (id = 1) LIMIT 1"
419
442
  ]
420
443
  instance.id.must_equal 1
421
444
  end
422
445
 
423
446
  it "be updatable" do
424
- @database.fetch = { id:1, label:"value", type_sid:"MockContent" }
425
- instance = MockContent.create(label: "value")
447
+ @database.fetch = { id:1, label:"value", type_sid:"MockContent2" }
448
+ instance = MockContent2.create(label: "value")
426
449
  instance.update(label: "changed")
427
450
  @database.sqls.must_equal [
428
- "INSERT INTO content (label, type_sid) VALUES ('value', 'MockContent')",
451
+ "INSERT INTO content (label, type_sid) VALUES ('value', 'MockContent2')",
429
452
  "SELECT * FROM content WHERE (id = 1) LIMIT 1",
430
453
  "UPDATE content SET label = 'changed' WHERE (id = 1)"
431
454
  ]
432
455
  end
433
456
 
434
457
  it "exclude id column from updates" do
435
- @database.fetch = { id:1, label:"value", type_sid:"MockContent" }
436
- instance = MockContent.create(id: 103, label: "value")
458
+ @database.fetch = { id:1, label:"value", type_sid:"MockContent2" }
459
+ instance = MockContent2.create(id: 103, label: "value")
437
460
  instance.id.must_equal 1
438
461
  instance.update(id: 99, label: "changed")
439
462
  @database.sqls.must_equal [
440
- "INSERT INTO content (label, type_sid) VALUES ('value', 'MockContent')",
463
+ "INSERT INTO content (label, type_sid) VALUES ('value', 'MockContent2')",
441
464
  "SELECT * FROM content WHERE (id = 1) LIMIT 1",
442
465
  "UPDATE content SET label = 'changed' WHERE (id = 1)"
443
466
  ]
@@ -445,11 +468,11 @@ describe "DataMapper" do
445
468
  end
446
469
 
447
470
  it "exclude type_sid column from updates" do
448
- @database.fetch = { id:1, label:"value", type_sid:"MockContent" }
449
- instance = MockContent.create(type_sid: "Nothing", label: "value")
471
+ @database.fetch = { id:1, label:"value", type_sid:"MockContent2" }
472
+ instance = MockContent2.create(type_sid: "Nothing", label: "value")
450
473
  instance.update(type_sid: "Invalid", label: "changed")
451
474
  @database.sqls.must_equal [
452
- "INSERT INTO content (label, type_sid) VALUES ('value', 'MockContent')",
475
+ "INSERT INTO content (label, type_sid) VALUES ('value', 'MockContent2')",
453
476
  "SELECT * FROM content WHERE (id = 1) LIMIT 1",
454
477
  "UPDATE content SET label = 'changed' WHERE (id = 1)"
455
478
  ]
@@ -457,8 +480,8 @@ describe "DataMapper" do
457
480
  end
458
481
 
459
482
  it "only update changed columns" do
460
- @database.fetch = { id:1, label:"value", type_sid:"MockContent" }
461
- instance = MockContent.create(label: "value")
483
+ @database.fetch = { id:1, label:"value", type_sid:"MockContent2" }
484
+ instance = MockContent2.create(label: "value")
462
485
  @database.sqls
463
486
  instance.changed_columns.must_equal []
464
487
  instance.label = "changed"
@@ -472,46 +495,46 @@ describe "DataMapper" do
472
495
  end
473
496
 
474
497
  it "mark new instances as modified" do
475
- instance = MockContent.new(label: "value")
498
+ instance = MockContent2.new(label: "value")
476
499
  assert instance.modified?
477
500
  end
478
501
 
479
502
  it "updated modified flag after save" do
480
- instance = MockContent.new(label: "value")
503
+ instance = MockContent2.new(label: "value")
481
504
  instance.save
482
505
  refute instance.modified?
483
506
  end
484
507
 
485
508
  it "have a modified flag if columns changed" do
486
- @database.fetch = { id:1, label:"value", type_sid:"MockContent" }
487
- instance = MockContent.create(label: "value")
509
+ @database.fetch = { id:1, label:"value", type_sid:"MockContent2" }
510
+ instance = MockContent2.create(label: "value")
488
511
  refute instance.modified?
489
512
  instance.label = "changed"
490
513
  assert instance.modified?
491
514
  end
492
515
 
493
516
  it "not make a db call if no values have been modified" do
494
- @database.fetch = { id:1, label:"value", type_sid:"MockContent" }
495
- instance = MockContent.create(label: "value")
517
+ @database.fetch = { id:1, label:"value", type_sid:"MockContent2" }
518
+ instance = MockContent2.create(label: "value")
496
519
  @database.sqls
497
520
  instance.save
498
521
  @database.sqls.must_equal []
499
522
  end
500
523
 
501
524
  it "allow you to force a save" do
502
- @database.fetch = { id:1, label:"value", type_sid:"MockContent" }
503
- instance = MockContent.create(label: "value")
525
+ @database.fetch = { id:1, label:"value", type_sid:"MockContent2" }
526
+ instance = MockContent2.create(label: "value")
504
527
  @database.sqls
505
528
  instance.mark_modified!
506
529
  instance.save
507
530
  @database.sqls.must_equal [
508
- "UPDATE content SET label = 'value', type_sid = 'MockContent' WHERE (id = 1)"
531
+ "UPDATE content SET label = 'value', type_sid = 'MockContent2' WHERE (id = 1)"
509
532
  ]
510
533
  end
511
534
 
512
535
  it "allow you to force an update to a specific column" do
513
- @database.fetch = { id:1, label:"value", type_sid:"MockContent" }
514
- instance = MockContent.create(label: "value")
536
+ @database.fetch = { id:1, label:"value", type_sid:"MockContent2" }
537
+ instance = MockContent2.create(label: "value")
515
538
  @database.sqls
516
539
  instance.mark_modified!(:label)
517
540
  instance.save
@@ -521,12 +544,12 @@ describe "DataMapper" do
521
544
  end
522
545
 
523
546
  it "be destroyable" do
524
- @database.fetch = { id:1, label:"value", type_sid:"MockContent" }
525
- instance = MockContent.create(label: "value")
547
+ @database.fetch = { id:1, label:"value", type_sid:"MockContent2" }
548
+ instance = MockContent2.create(label: "value")
526
549
  instance.id.must_equal 1
527
550
  instance.destroy
528
551
  @database.sqls.must_equal [
529
- "INSERT INTO content (label, type_sid) VALUES ('value', 'MockContent')",
552
+ "INSERT INTO content (label, type_sid) VALUES ('value', 'MockContent2')",
530
553
  "SELECT * FROM content WHERE (id = 1) LIMIT 1",
531
554
  "DELETE FROM content WHERE (id = 1)"
532
555
  ]
@@ -534,53 +557,53 @@ describe "DataMapper" do
534
557
 
535
558
  it "allow for searching for all instances of a class" do
536
559
  @database.fetch = [
537
- { id:1, label:"column1", type_sid:"MockContent" },
538
- { id:2, label:"column2", type_sid:"MockContent" }
560
+ { id:1, label:"column1", type_sid:"MockContent2" },
561
+ { id:2, label:"column2", type_sid:"MockContent2" }
539
562
  ]
540
- results = MockContent.all
563
+ results = MockContent2.all
541
564
  @database.sqls.must_equal [
542
- "SELECT * FROM content WHERE (type_sid IN ('MockContent'))"
565
+ "SELECT * FROM content WHERE (type_sid IN ('MockContent2'))"
543
566
  ]
544
567
  results.length.must_equal 2
545
- results.map(&:class).must_equal [MockContent, MockContent]
568
+ results.map(&:class).must_equal [MockContent2, MockContent2]
546
569
  results.map(&:id).must_equal [1, 2]
547
570
  end
548
571
 
549
572
  it "allow for finding first instance of a type" do
550
573
  @database.fetch = [
551
- { id:1, label:"column1", type_sid:"MockContent" }
574
+ { id:1, label:"column1", type_sid:"MockContent2" }
552
575
  ]
553
- instance = MockContent.first
554
- MockContent.first(id: 1)
555
- MockContent.first { id > 0}
576
+ instance = MockContent2.first
577
+ MockContent2.first(id: 1)
578
+ MockContent2.first { id > 0}
556
579
  @database.sqls.must_equal [
557
- "SELECT * FROM content WHERE (type_sid IN ('MockContent')) LIMIT 1",
558
- "SELECT * FROM content WHERE ((type_sid IN ('MockContent')) AND (id = 1)) LIMIT 1",
559
- "SELECT * FROM content WHERE ((type_sid IN ('MockContent')) AND (id > 0)) LIMIT 1"
580
+ "SELECT * FROM content WHERE (type_sid IN ('MockContent2')) LIMIT 1",
581
+ "SELECT * FROM content WHERE ((type_sid IN ('MockContent2')) AND (id = 1)) LIMIT 1",
582
+ "SELECT * FROM content WHERE ((type_sid IN ('MockContent2')) AND (id > 0)) LIMIT 1"
560
583
  ]
561
- instance.must_be_instance_of MockContent
584
+ instance.must_be_instance_of MockContent2
562
585
  instance.id.must_equal 1
563
586
  end
564
587
 
565
588
  it "return nil if no instance matching filter is found" do
566
589
  @database.fetch = []
567
- instance = MockContent.first(id: 1)
590
+ instance = MockContent2.first(id: 1)
568
591
  instance.must_be_nil
569
592
  end
570
593
 
571
594
  it "retrieve by primary key using []" do
572
- instance = MockContent[1]
595
+ instance = MockContent2[1]
573
596
  @database.sqls.must_equal [
574
- "SELECT * FROM content WHERE (id = 1) LIMIT 1",
597
+ "SELECT * FROM content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (id = 1)) LIMIT 1",
575
598
  ]
576
599
  end
577
600
 
578
601
  it "have correct equality test" do
579
602
  @database.fetch = [
580
- { id:1, label:"column1", type_sid:"MockContent" }
603
+ { id:1, label:"column1", type_sid:"MockContent2" }
581
604
  ]
582
- a = MockContent[1]
583
- b = MockContent[1]
605
+ a = MockContent2[1]
606
+ b = MockContent2[1]
584
607
  a.must_equal b
585
608
 
586
609
  a.label = "changed"
@@ -589,39 +612,39 @@ describe "DataMapper" do
589
612
 
590
613
  it "allow for filtering model instances" do
591
614
  @database.fetch = [
592
- { id:100, label:"column1", type_sid:"MockContent" }
615
+ { id:100, label:"column1", type_sid:"MockContent2" }
593
616
  ]
594
- results = MockContent.filter(hidden: false).all
617
+ results = MockContent2.filter(hidden: false).all
595
618
  @database.sqls.must_equal [
596
- "SELECT * FROM content WHERE ((type_sid IN ('MockContent')) AND (hidden IS FALSE))"
619
+ "SELECT * FROM content WHERE ((type_sid IN ('MockContent2')) AND (hidden IS FALSE))"
597
620
  ]
598
621
  results.length.must_equal 1
599
- results.map(&:class).must_equal [MockContent]
622
+ results.map(&:class).must_equal [MockContent2]
600
623
  results.map(&:id).must_equal [100]
601
624
  end
602
625
 
603
626
  it "use the current mapper revision to save" do
604
627
  @database.fetch = [
605
- { id:100, label:"column1", type_sid:"MockContent" }
628
+ { id:100, label:"column1", type_sid:"MockContent2" }
606
629
  ]
607
630
  instance = nil
608
631
  @mapper.revision(99) do
609
- instance = MockContent.first
632
+ instance = MockContent2.first
610
633
  end
611
634
  instance.update(label: "changed")
612
635
  @mapper.revision(99) do
613
636
  instance.update(label: "changed2")
614
637
  end
615
638
  @database.sqls.must_equal [
616
- "SELECT * FROM __r00099_content WHERE (type_sid IN ('MockContent')) LIMIT 1",
639
+ "SELECT * FROM __r00099_content WHERE (type_sid IN ('MockContent2')) LIMIT 1",
617
640
  "UPDATE content SET label = 'changed' WHERE (id = 100)",
618
641
  "UPDATE __r00099_content SET label = 'changed2' WHERE (id = 100)"
619
642
  ]
620
643
  end
621
644
 
622
645
  it "allow for reloading values from the db" do
623
- @database.fetch = { id:100, label:"column1", type_sid:"MockContent" }
624
- instance = MockContent.first
646
+ @database.fetch = { id:100, label:"column1", type_sid:"MockContent2" }
647
+ instance = MockContent2.first
625
648
  instance.set(label:"changed")
626
649
  instance.attributes[:label].must_equal "changed"
627
650
  instance.changed_columns.must_equal [:label]
@@ -629,27 +652,27 @@ describe "DataMapper" do
629
652
  instance.attributes[:label].must_equal "column1"
630
653
  instance.changed_columns.must_equal []
631
654
  @database.sqls.must_equal [
632
- "SELECT * FROM content WHERE (type_sid IN ('MockContent')) LIMIT 1",
655
+ "SELECT * FROM content WHERE (type_sid IN ('MockContent2')) LIMIT 1",
633
656
  "SELECT * FROM content WHERE (id = 100) LIMIT 1"
634
657
  ]
635
658
  end
636
659
 
637
660
 
638
661
  it "update model rows directly" do
639
- MockContent.update(label: "changed")
662
+ MockContent2.update(label: "changed")
640
663
  @database.sqls.must_equal [
641
- "UPDATE content SET label = 'changed' WHERE (type_sid IN ('MockContent'))"
664
+ "UPDATE content SET label = 'changed' WHERE (type_sid IN ('MockContent2'))"
642
665
  ]
643
666
  end
644
667
 
645
668
  it "introspect columns" do
646
- MockContent.columns.must_equal @expected_columns
669
+ MockContent2.columns.must_equal @expected_columns
647
670
  end
648
671
 
649
672
  it "create getters & setters for all columns except id & type_sid" do
650
673
  columns = (@expected_columns - [:id, :type_sid])
651
674
  attrs = Hash[columns.map { |c| [c, "#{c}_value"] } ]
652
- c = MockContent.new attrs
675
+ c = MockContent2.new attrs
653
676
 
654
677
  columns.each do |column|
655
678
  assert c.respond_to?(column), "Instance it respond to ##{column}"
@@ -670,7 +693,7 @@ describe "DataMapper" do
670
693
  end
671
694
 
672
695
  it "support after_initialize hooks" do
673
- model = Class.new(MockContent) do
696
+ model = Class.new(MockContent2) do
674
697
  attr_accessor :param
675
698
  def after_initialize
676
699
  self.param = true
@@ -681,7 +704,7 @@ describe "DataMapper" do
681
704
  end
682
705
 
683
706
  it "support before create triggers" do
684
- model = Class.new(MockContent) do
707
+ model = Class.new(MockContent2) do
685
708
  attr_accessor :param
686
709
  def before_create
687
710
  self.param = true
@@ -692,7 +715,7 @@ describe "DataMapper" do
692
715
  end
693
716
 
694
717
  it "support after create triggers" do
695
- model = Class.new(MockContent) do
718
+ model = Class.new(MockContent2) do
696
719
  attr_accessor :param
697
720
  def after_create
698
721
  self.param = true
@@ -703,7 +726,7 @@ describe "DataMapper" do
703
726
  end
704
727
 
705
728
  it "not insert instance & return nil if before_create throws :halt" do
706
- model = Class.new(MockContent) do
729
+ model = Class.new(MockContent2) do
707
730
  attr_accessor :param
708
731
  def before_create
709
732
  throw :halt
@@ -715,7 +738,7 @@ describe "DataMapper" do
715
738
  end
716
739
 
717
740
  it "call before save triggers on model create" do
718
- model = Class.new(MockContent) do
741
+ model = Class.new(MockContent2) do
719
742
  attr_accessor :param
720
743
  def before_save
721
744
  self.param = true
@@ -726,8 +749,8 @@ describe "DataMapper" do
726
749
  end
727
750
 
728
751
  it "call before save triggers on existing instances" do
729
- @database.fetch = { id:1, label:"label", type_sid:"MockContent" }
730
- model = Class.new(MockContent) do
752
+ @database.fetch = { id:1, label:"label", type_sid:"MockContent2" }
753
+ model = Class.new(MockContent2) do
731
754
  attr_accessor :param
732
755
  def before_save
733
756
  self.param = true
@@ -742,7 +765,7 @@ describe "DataMapper" do
742
765
  end
743
766
 
744
767
  it "call after save triggers after create" do
745
- model = Class.new(MockContent) do
768
+ model = Class.new(MockContent2) do
746
769
  attr_accessor :param
747
770
  def after_save
748
771
  self.param = true
@@ -753,8 +776,8 @@ describe "DataMapper" do
753
776
  end
754
777
 
755
778
  it "call after save triggers on existing instances" do
756
- @database.fetch = { id:1, label:"label", type_sid:"MockContent" }
757
- model = Class.new(MockContent) do
779
+ @database.fetch = { id:1, label:"label", type_sid:"MockContent2" }
780
+ model = Class.new(MockContent2) do
758
781
  attr_accessor :param
759
782
  def after_save
760
783
  self.param = true
@@ -769,8 +792,8 @@ describe "DataMapper" do
769
792
  end
770
793
 
771
794
  it "support before_update triggers" do
772
- @database.fetch = { id:1, label:"label", type_sid:"MockContent" }
773
- model = Class.new(MockContent) do
795
+ @database.fetch = { id:1, label:"label", type_sid:"MockContent2" }
796
+ model = Class.new(MockContent2) do
774
797
  attr_accessor :param
775
798
  def before_update
776
799
  self.param = true
@@ -784,8 +807,8 @@ describe "DataMapper" do
784
807
  end
785
808
 
786
809
  it "fail to save instance if before_update throws halt" do
787
- @database.fetch = { id:1, label:"label", type_sid:"MockContent" }
788
- model = Class.new(MockContent) do
810
+ @database.fetch = { id:1, label:"label", type_sid:"MockContent2" }
811
+ model = Class.new(MockContent2) do
789
812
  attr_accessor :param
790
813
  def before_update
791
814
  throw :halt
@@ -800,8 +823,8 @@ describe "DataMapper" do
800
823
  end
801
824
 
802
825
  it "support after update triggers" do
803
- @database.fetch = { id:1, label:"label", type_sid:"MockContent" }
804
- model = Class.new(MockContent) do
826
+ @database.fetch = { id:1, label:"label", type_sid:"MockContent2" }
827
+ model = Class.new(MockContent2) do
805
828
  attr_accessor :param
806
829
  def after_update
807
830
  self.param = true
@@ -815,8 +838,8 @@ describe "DataMapper" do
815
838
  end
816
839
 
817
840
  it "support before destroy triggers" do
818
- @database.fetch = { id:1, label:"label", type_sid:"MockContent" }
819
- model = Class.new(MockContent) do
841
+ @database.fetch = { id:1, label:"label", type_sid:"MockContent2" }
842
+ model = Class.new(MockContent2) do
820
843
  attr_accessor :param
821
844
  def before_destroy
822
845
  self.param = true
@@ -832,8 +855,8 @@ describe "DataMapper" do
832
855
  end
833
856
 
834
857
  it "not delete an instance if before_destroy throws halt" do
835
- @database.fetch = { id:1, label:"label", type_sid:"MockContent" }
836
- model = Class.new(MockContent) do
858
+ @database.fetch = { id:1, label:"label", type_sid:"MockContent2" }
859
+ model = Class.new(MockContent2) do
837
860
  attr_accessor :param
838
861
  def before_destroy
839
862
  throw :halt
@@ -847,8 +870,8 @@ describe "DataMapper" do
847
870
  end
848
871
 
849
872
  it "support after destroy triggers" do
850
- @database.fetch = { id:1, label:"label", type_sid:"MockContent" }
851
- model = Class.new(MockContent) do
873
+ @database.fetch = { id:1, label:"label", type_sid:"MockContent2" }
874
+ model = Class.new(MockContent2) do
852
875
  attr_accessor :param
853
876
  def after_destroy
854
877
  self.param = true
@@ -861,8 +884,8 @@ describe "DataMapper" do
861
884
  end
862
885
 
863
886
  it "not trigger before destroy hooks when calling #delete" do
864
- @database.fetch = { id:1, label:"label", type_sid:"MockContent" }
865
- model = Class.new(MockContent) do
887
+ @database.fetch = { id:1, label:"label", type_sid:"MockContent2" }
888
+ model = Class.new(MockContent2) do
866
889
  attr_accessor :param
867
890
  def before_destroy
868
891
  throw :halt
@@ -875,33 +898,33 @@ describe "DataMapper" do
875
898
  end
876
899
 
877
900
  it "serialize column to JSON" do
878
- row = { id: 1, type_sid:"MockContent" }
901
+ row = { id: 1, type_sid:"MockContent2" }
879
902
  object = {name:"value"}
880
903
  serialized = Spontaneous::JSON.encode(object)
881
- MockContent.serialized_columns.each do |column|
904
+ MockContent2.serialized_columns.each do |column|
882
905
  @database.fetch = row
883
- instance = MockContent.create({column => object})
884
- @database.sqls.first.must_equal "INSERT INTO content (#{column}, type_sid) VALUES ('#{serialized}', 'MockContent')"
906
+ instance = MockContent2.create({column => object})
907
+ @database.sqls.first.must_equal "INSERT INTO content (#{column}, type_sid) VALUES ('#{serialized}', 'MockContent2')"
885
908
  end
886
909
  end
887
910
 
888
911
  it "deserialize objects stored in the db" do
889
- row = { id: 1, type_sid:"MockContent" }
912
+ row = { id: 1, type_sid:"MockContent2" }
890
913
  object = {name:"value"}
891
914
  serialized = Spontaneous::JSON.encode(object)
892
- MockContent.serialized_columns.each do |column|
915
+ MockContent2.serialized_columns.each do |column|
893
916
  @database.fetch = row.merge(column => serialized)
894
- instance = MockContent.first
917
+ instance = MockContent2.first
895
918
  instance.send(column).must_equal object
896
919
  end
897
920
  end
898
921
  it "save updates to serialized columns" do
899
- row = { id: 1, type_sid:"MockContent" }
922
+ row = { id: 1, type_sid:"MockContent2" }
900
923
  object = {name:"value"}
901
924
  serialized = Spontaneous::JSON.encode(object)
902
- MockContent.serialized_columns.each do |column|
925
+ MockContent2.serialized_columns.each do |column|
903
926
  @database.fetch = row.merge(column => serialized)
904
- instance = MockContent.first
927
+ instance = MockContent2.first
905
928
  @database.sqls
906
929
  instance.send(column).must_equal object
907
930
  changed = {name:"it's different", value:[99, 100]}
@@ -961,14 +984,14 @@ describe "DataMapper" do
961
984
  Set.new(A1.subclasses).must_equal Set.new([B1, C1])
962
985
  A2.subclasses.must_equal [B2]
963
986
  C1.subclasses.must_equal []
964
- Set.new(MockContent.subclasses).must_equal Set.new([MockContent2, A1, A2, B1, B2, C1])
987
+ Set.new(MockContent.subclasses).must_equal Set.new([MockContent2, MockContent3, A1, A2, B1, B2, C1])
965
988
  end
966
989
  end
967
990
  end
968
991
 
969
992
  it "allow for the creation of instance after save hooks" do
970
- @database.fetch = { id: 1, type_sid:"MockContent" }
971
- instance = MockContent.create label: "something"
993
+ @database.fetch = { id: 1, type_sid:"MockContent2" }
994
+ instance = MockContent2.create label: "something"
972
995
  test = false
973
996
  instance.after_save_hook do
974
997
  test = true
@@ -978,9 +1001,9 @@ describe "DataMapper" do
978
1001
  end
979
1002
 
980
1003
  it "let you count available instances" do
981
- result = MockContent.count
1004
+ result = MockContent2.count
982
1005
  @database.sqls.must_equal [
983
- "SELECT COUNT(*) AS count FROM content WHERE (type_sid IN ('MockContent')) LIMIT 1"
1006
+ "SELECT count(*) AS count FROM content WHERE (type_sid IN ('MockContent2')) LIMIT 1"
984
1007
  ]
985
1008
  end
986
1009
 
@@ -1003,21 +1026,21 @@ describe "DataMapper" do
1003
1026
  parent = AssocContent.first
1004
1027
  @database.sqls
1005
1028
  @database.fetch = [
1006
- { id: 8, type_sid:"MockContent" },
1029
+ { id: 8, type_sid:"MockContent2" },
1007
1030
  { id: 9, type_sid:"AssocContent" }
1008
1031
  ]
1009
1032
  children = parent.children
1010
1033
  @database.sqls.must_equal [
1011
- "SELECT * FROM content WHERE (content.parent_id = 7)"
1034
+ "SELECT * FROM content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (content.parent_id = 7))"
1012
1035
  ]
1013
1036
  children.map(&:id).must_equal [8, 9]
1014
- children.map(&:class).must_equal [MockContent, AssocContent]
1037
+ children.map(&:class).must_equal [MockContent2, AssocContent]
1015
1038
  end
1016
1039
 
1017
1040
  it "cache the result" do
1018
1041
  children = @parent.children
1019
1042
  @database.sqls.must_equal [
1020
- "SELECT * FROM content WHERE (content.parent_id = 7)"
1043
+ "SELECT * FROM content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (content.parent_id = 7))"
1021
1044
  ]
1022
1045
  children = @parent.children
1023
1046
  @database.sqls.must_equal [ ]
@@ -1026,11 +1049,11 @@ describe "DataMapper" do
1026
1049
  it "reload the result if forced" do
1027
1050
  children = @parent.children
1028
1051
  @database.sqls.must_equal [
1029
- "SELECT * FROM content WHERE (content.parent_id = 7)"
1052
+ "SELECT * FROM content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (content.parent_id = 7))"
1030
1053
  ]
1031
1054
  children = @parent.children(reload: true)
1032
1055
  @database.sqls.must_equal [
1033
- "SELECT * FROM content WHERE (content.parent_id = 7)"
1056
+ "SELECT * FROM content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (content.parent_id = 7))"
1034
1057
  ]
1035
1058
  end
1036
1059
 
@@ -1038,18 +1061,18 @@ describe "DataMapper" do
1038
1061
  ds = @parent.children_dataset
1039
1062
  ds.filter { id > 3}.all
1040
1063
  @database.sqls.must_equal [
1041
- "SELECT * FROM content WHERE ((content.parent_id = 7) AND (id > 3))"
1064
+ "SELECT * FROM content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (content.parent_id = 7) AND (id > 3))"
1042
1065
  ]
1043
1066
  end
1044
1067
 
1045
1068
  it "return correctly typed results" do
1046
1069
  @database.fetch = [
1047
- { id: 8, type_sid:"MockContent" },
1070
+ { id: 8, type_sid:"MockContent2" },
1048
1071
  { id: 9, type_sid:"AssocContent" }
1049
1072
  ]
1050
1073
  children = @parent.children
1051
1074
  children.map(&:id).must_equal [8, 9]
1052
- children.map(&:class).must_equal [MockContent, AssocContent]
1075
+ children.map(&:class).must_equal [MockContent2, AssocContent]
1053
1076
  end
1054
1077
 
1055
1078
  it "correctly set the relation key when adding members" do
@@ -1069,7 +1092,7 @@ describe "DataMapper" do
1069
1092
  children = parent.children
1070
1093
  end
1071
1094
  @database.sqls.must_equal [
1072
- "SELECT * FROM __r00099_content WHERE (__r00099_content.parent_id = 7)"
1095
+ "SELECT * FROM __r00099_content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (__r00099_content.parent_id = 7))"
1073
1096
  ]
1074
1097
  end
1075
1098
 
@@ -1084,7 +1107,7 @@ describe "DataMapper" do
1084
1107
  end
1085
1108
  end
1086
1109
  @database.sqls.must_equal [
1087
- "SELECT * FROM __r00011_content WHERE (__r00011_content.parent_id = 7)"
1110
+ "SELECT * FROM __r00011_content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (__r00011_content.parent_id = 7))"
1088
1111
  ]
1089
1112
  end
1090
1113
 
@@ -1096,9 +1119,9 @@ describe "DataMapper" do
1096
1119
  ]
1097
1120
  @parent.destroy
1098
1121
  @database.sqls.must_equal [
1099
- "SELECT * FROM content WHERE (content.source_id = 7)",
1100
- "SELECT * FROM content WHERE (content.source_id = 8)",
1101
- "SELECT * FROM content WHERE (content.source_id = 9)",
1122
+ "SELECT * FROM content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (content.source_id = 7))",
1123
+ "SELECT * FROM content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (content.source_id = 8))",
1124
+ "SELECT * FROM content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (content.source_id = 9))",
1102
1125
  "DELETE FROM content WHERE (id = 9)",
1103
1126
  "DELETE FROM content WHERE (id = 8)",
1104
1127
  "DELETE FROM content WHERE (id = 7)"
@@ -1113,7 +1136,7 @@ describe "DataMapper" do
1113
1136
  ]
1114
1137
  @parent.destroy
1115
1138
  @database.sqls.must_equal [
1116
- "DELETE FROM content WHERE (content.source_id = 7)",
1139
+ "DELETE FROM content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (content.source_id = 7))",
1117
1140
  "DELETE FROM content WHERE (id = 7)"
1118
1141
  ]
1119
1142
  end
@@ -1183,28 +1206,28 @@ describe "DataMapper" do
1183
1206
  it "load the owner" do
1184
1207
  @database.fetch = { id: 7, type_sid:"AssocContent", parent_id: nil }
1185
1208
  parent = @child.parent
1186
- @database.sqls.must_equal ["SELECT * FROM content WHERE (id = 7) LIMIT 1"]
1209
+ @database.sqls.must_equal ["SELECT * FROM content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (id = 7)) LIMIT 1"]
1187
1210
  parent.must_be_instance_of AssocContent
1188
1211
  parent.id.must_equal 7
1189
1212
  end
1190
1213
 
1191
1214
  it "cache the result" do
1192
1215
  parent = @child.parent
1193
- @database.sqls.must_equal ["SELECT * FROM content WHERE (id = 7) LIMIT 1"]
1216
+ @database.sqls.must_equal ["SELECT * FROM content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (id = 7)) LIMIT 1"]
1194
1217
  parent = @child.parent
1195
1218
  @database.sqls.must_equal [ ]
1196
1219
  end
1197
1220
 
1198
1221
  it "reload the result if asked" do
1199
1222
  parent = @child.parent
1200
- @database.sqls.must_equal ["SELECT * FROM content WHERE (id = 7) LIMIT 1"]
1223
+ @database.sqls.must_equal ["SELECT * FROM content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (id = 7)) LIMIT 1"]
1201
1224
  parent = @child.parent(reload: true)
1202
- @database.sqls.must_equal ["SELECT * FROM content WHERE (id = 7) LIMIT 1"]
1225
+ @database.sqls.must_equal ["SELECT * FROM content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (id = 7)) LIMIT 1"]
1203
1226
  end
1204
1227
 
1205
1228
  it "allow access to the relation dataset" do
1206
1229
  results = @child.parent_dataset.filter { id > 3 }.first
1207
- @database.sqls.must_equal ["SELECT * FROM content WHERE ((content.id = 7) AND (id > 3)) LIMIT 1"]
1230
+ @database.sqls.must_equal ["SELECT * FROM content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (content.id = 7) AND (id > 3)) LIMIT 1"]
1208
1231
  end
1209
1232
 
1210
1233
  it "allow setting of owner for instance" do
@@ -1228,7 +1251,7 @@ describe "DataMapper" do
1228
1251
  children = parent.children
1229
1252
  children.map { |c| c.parent.object_id }.uniq.must_equal [parent.object_id]
1230
1253
  @database.sqls.must_equal [
1231
- "SELECT * FROM content WHERE (content.parent_id = 7)"
1254
+ "SELECT * FROM content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (content.parent_id = 7))"
1232
1255
  ]
1233
1256
  end
1234
1257
 
@@ -1253,7 +1276,7 @@ describe "DataMapper" do
1253
1276
  it "can load association members" do
1254
1277
  @instance.other
1255
1278
  @database.sqls.must_equal [
1256
- "SELECT * FROM other WHERE (other.id = 34) LIMIT 1"
1279
+ "SELECT * FROM other WHERE (id = 34) LIMIT 1"
1257
1280
  ]
1258
1281
  end
1259
1282
 
@@ -1279,7 +1302,7 @@ describe "DataMapper" do
1279
1302
  @database.sqls
1280
1303
  @instance.other
1281
1304
  @database.sqls.must_equal [
1282
- "SELECT * FROM other WHERE (other.id = 34) LIMIT 1"
1305
+ "SELECT * FROM other WHERE (id = 34) LIMIT 1"
1283
1306
  ]
1284
1307
  end
1285
1308
  end
@@ -1336,7 +1359,7 @@ describe "DataMapper" do
1336
1359
  describe "performance" do
1337
1360
  it "use a cached version within revision blocks" do
1338
1361
  @mapper.revision(20) do
1339
- assert @mapper.dataset.equal?(@mapper.dataset), "Dataset it be the same object"
1362
+ assert @mapper.active_scope.equal?(@mapper.active_scope), "Dataset it be the same object"
1340
1363
  end
1341
1364
  end
1342
1365
 
@@ -1369,9 +1392,9 @@ describe "DataMapper" do
1369
1392
  it "not create new scope if revisions are the same" do
1370
1393
  a = b = nil
1371
1394
  @mapper.revision(20) do
1372
- a = @mapper.dataset
1395
+ a = @mapper.active_scope
1373
1396
  @mapper.revision(20) do
1374
- b = @mapper.dataset
1397
+ b = @mapper.active_scope
1375
1398
  end
1376
1399
  end
1377
1400
  assert a.object_id == b.object_id, "Mappers it be same object"
@@ -1380,9 +1403,9 @@ describe "DataMapper" do
1380
1403
  it "not create new scope if visibility are the same" do
1381
1404
  a = b = nil
1382
1405
  @mapper.scope(20, true) do
1383
- a = @mapper.dataset
1406
+ a = @mapper.active_scope
1384
1407
  @mapper.visible do
1385
- b = @mapper.dataset
1408
+ b = @mapper.active_scope
1386
1409
  end
1387
1410
  end
1388
1411
  assert a.object_id == b.object_id, "Mappers it be same object"
@@ -1391,9 +1414,9 @@ describe "DataMapper" do
1391
1414
  it "not create new scope if parameters are the same" do
1392
1415
  a = b = nil
1393
1416
  @mapper.scope(20, true) do
1394
- a = @mapper.dataset
1417
+ a = @mapper.active_scope
1395
1418
  @mapper.scope(20, true) do
1396
- b = @mapper.dataset
1419
+ b = @mapper.active_scope
1397
1420
  end
1398
1421
  end
1399
1422
  assert a.object_id == b.object_id, "Mappers it be same object"
@@ -1409,7 +1432,7 @@ describe "DataMapper" do
1409
1432
  b = @mapper.with_cache("key") { @mapper.filter(nil, label: "frog").first }
1410
1433
  end
1411
1434
  @database.sqls.must_equal [
1412
- "SELECT * FROM __r00020_content WHERE (label = 'frog') LIMIT 1"
1435
+ "SELECT * FROM __r00020_content WHERE ((type_sid IN ('MockContent2', 'MockContent3')) AND (label = 'frog')) LIMIT 1"
1413
1436
  ]
1414
1437
  end
1415
1438