maglevrecord 0.0.3 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +35 -0
- data/.travis.yml +19 -0
- data/Gemfile +13 -0
- data/README.md +89 -0
- data/Rakefile +22 -0
- data/install.sh +238 -0
- data/lib/maglev_record/base.rb +10 -62
- data/lib/maglev_record/enumerable.rb +13 -24
- data/lib/maglev_record/errors.rb +10 -0
- data/lib/maglev_record/integration.rb +7 -0
- data/lib/maglev_record/maglev_record.rb +13 -0
- data/lib/maglev_record/maglev_support/active_support_patch.rb +31 -0
- data/lib/maglev_record/maglev_support/concern.rb +19 -0
- data/lib/maglev_record/maglev_support/maglev_support.rb +15 -0
- data/lib/maglev_record/maglev_support/secure_password.rb +39 -0
- data/lib/maglev_record/migration/loader.rb +38 -0
- data/lib/maglev_record/migration/migration.rb +142 -0
- data/lib/maglev_record/migration/migrator.rb +40 -0
- data/lib/maglev_record/migration/operations.rb +92 -0
- data/lib/maglev_record/migration.rb +5 -0
- data/lib/maglev_record/persistence.rb +23 -48
- data/lib/maglev_record/raketasks.rb +9 -0
- data/lib/maglev_record/read_write.rb +20 -10
- data/lib/maglev_record/rooted_base.rb +8 -0
- data/lib/maglev_record/rooted_enumerable.rb +25 -0
- data/lib/maglev_record/rooted_persistence.rb +36 -0
- data/lib/maglev_record/sensible.rb +28 -0
- data/lib/maglev_record/snapshot/change.rb +53 -0
- data/lib/maglev_record/snapshot/snapshot.rb +67 -0
- data/lib/maglev_record/snapshot/snapshotable.rb +58 -0
- data/lib/maglev_record/snapshot.rb +5 -0
- data/lib/maglev_record/tools/object_reference.rb +189 -0
- data/lib/maglev_record/tools/submodule_finder.rb +42 -0
- data/lib/maglev_record/tools.rb +2 -0
- data/lib/maglev_record.rb +60 -4
- data/lib/tasks/database.rake +38 -0
- data/maglevrecord.gemspec +17 -0
- data/rails/init.rb +1 -0
- data/test/_test_object_reference.rb +70 -0
- data/test/example_model.rb +26 -13
- data/test/migration/dummy_migrations/migration_1.rb +8 -0
- data/test/migration/dummy_migrations/migration_2.rb +8 -0
- data/test/migration/dummy_migrations/migration_3.rb +8 -0
- data/test/migration/migrations/migration_1.rb +12 -0
- data/test/migration/migrations/migration_2.rb +12 -0
- data/test/migration/migrations/migration_3.rb +12 -0
- data/test/migration/operation_setup.rb +91 -0
- data/test/migration/projects/project1/.gitignore +15 -0
- data/test/migration/projects/project1/Gemfile +43 -0
- data/test/migration/projects/project1/Gemfile.lock +114 -0
- data/test/migration/projects/project1/README.rdoc +261 -0
- data/test/migration/projects/project1/Rakefile +17 -0
- data/test/migration/projects/project1/app/assets/images/rails.png +0 -0
- data/test/migration/projects/project1/app/assets/javascripts/application.js +15 -0
- data/test/migration/projects/project1/app/assets/stylesheets/application.css +13 -0
- data/test/migration/projects/project1/app/controllers/application_controller.rb +3 -0
- data/test/migration/projects/project1/app/helpers/application_helper.rb +2 -0
- data/test/migration/projects/project1/app/mailers/.gitkeep +0 -0
- data/test/migration/projects/project1/app/models/.gitkeep +0 -0
- data/test/migration/projects/project1/app/views/layouts/application.html.erb +14 -0
- data/test/migration/projects/project1/config/application.rb +62 -0
- data/test/migration/projects/project1/config/boot.rb +6 -0
- data/test/migration/projects/project1/config/database.yml +25 -0
- data/test/migration/projects/project1/config/environment.rb +5 -0
- data/test/migration/projects/project1/config/environments/development.rb +37 -0
- data/test/migration/projects/project1/config/environments/production.rb +67 -0
- data/test/migration/projects/project1/config/initializers/backtrace_silencers.rb +7 -0
- data/test/migration/projects/project1/config/initializers/inflections.rb +15 -0
- data/test/migration/projects/project1/config/initializers/mime_types.rb +5 -0
- data/test/migration/projects/project1/config/initializers/secret_token.rb +7 -0
- data/test/migration/projects/project1/config/initializers/session_store.rb +8 -0
- data/test/migration/projects/project1/config/initializers/wrap_parameters.rb +14 -0
- data/test/migration/projects/project1/config/locales/en.yml +5 -0
- data/test/migration/projects/project1/config/routes.rb +58 -0
- data/test/migration/projects/project1/config.ru +4 -0
- data/test/migration/projects/project1/db/seeds.rb +7 -0
- data/test/migration/projects/project1/lib/assets/.gitkeep +0 -0
- data/test/migration/projects/project1/lib/tasks/.gitkeep +0 -0
- data/test/migration/projects/project1/log/.gitkeep +0 -0
- data/test/migration/projects/project1/public/404.html +26 -0
- data/test/migration/projects/project1/public/422.html +26 -0
- data/test/migration/projects/project1/public/500.html +25 -0
- data/test/migration/projects/project1/public/favicon.ico +0 -0
- data/test/migration/projects/project1/public/index.html +241 -0
- data/test/migration/projects/project1/public/robots.txt +5 -0
- data/test/migration/projects/project1/script/rails +6 -0
- data/test/migration/projects/project2/.gitignore +15 -0
- data/test/migration/projects/project2/Gemfile +44 -0
- data/test/migration/projects/project2/Gemfile.lock +115 -0
- data/test/migration/projects/project2/README.rdoc +261 -0
- data/test/migration/projects/project2/Rakefile +17 -0
- data/test/migration/projects/project2/app/assets/images/rails.png +0 -0
- data/test/migration/projects/project2/app/assets/javascripts/application.js +15 -0
- data/test/migration/projects/project2/app/assets/stylesheets/application.css +13 -0
- data/test/migration/projects/project2/app/controllers/application_controller.rb +3 -0
- data/test/migration/projects/project2/app/helpers/application_helper.rb +2 -0
- data/test/migration/projects/project2/app/mailers/.gitkeep +0 -0
- data/test/migration/projects/project2/app/models/.gitkeep +0 -0
- data/test/migration/projects/project2/app/models/project_model.rb +8 -0
- data/test/migration/projects/project2/app/views/layouts/application.html.erb +14 -0
- data/test/migration/projects/project2/config/application.rb +62 -0
- data/test/migration/projects/project2/config/boot.rb +6 -0
- data/test/migration/projects/project2/config/database.yml +25 -0
- data/test/migration/projects/project2/config/environment.rb +5 -0
- data/test/migration/projects/project2/config/environments/development.rb +37 -0
- data/test/migration/projects/project2/config/environments/production.rb +67 -0
- data/test/migration/projects/project2/config/initializers/backtrace_silencers.rb +7 -0
- data/test/migration/projects/project2/config/initializers/inflections.rb +15 -0
- data/test/migration/projects/project2/config/initializers/mime_types.rb +5 -0
- data/test/migration/projects/project2/config/initializers/secret_token.rb +7 -0
- data/test/migration/projects/project2/config/initializers/session_store.rb +8 -0
- data/test/migration/projects/project2/config/initializers/wrap_parameters.rb +14 -0
- data/test/migration/projects/project2/config/locales/en.yml +5 -0
- data/test/migration/projects/project2/config/routes.rb +58 -0
- data/test/migration/projects/project2/config.ru +4 -0
- data/test/migration/projects/project2/db/seeds.rb +7 -0
- data/test/migration/projects/project2/lib/assets/.gitkeep +0 -0
- data/test/migration/projects/project2/lib/tasks/.gitkeep +0 -0
- data/test/migration/projects/project2/log/.gitkeep +0 -0
- data/test/migration/projects/project2/migrations/migration_2013-04-Apr-23_17.31.38.rb +16 -0
- data/test/migration/projects/project2/migrations/migration_2013-04-Apr-23_17.31.52.rb +16 -0
- data/test/migration/projects/project2/migrations/migration_2013-04-Apr-23_17.32.07.rb +16 -0
- data/test/migration/projects/project2/public/404.html +26 -0
- data/test/migration/projects/project2/public/422.html +26 -0
- data/test/migration/projects/project2/public/500.html +25 -0
- data/test/migration/projects/project2/public/favicon.ico +0 -0
- data/test/migration/projects/project2/public/index.html +241 -0
- data/test/migration/projects/project2/public/robots.txt +5 -0
- data/test/migration/projects/project2/script/rails +6 -0
- data/test/migration/test_loader.rb +78 -0
- data/test/migration/test_migration.rb +127 -0
- data/test/migration/test_nonexistent_classes.rb +120 -0
- data/test/migration/test_operations_fit_together.rb +68 -0
- data/test/migration/test_project.rb +105 -0
- data/test/migration/test_project1.slow.rb +58 -0
- data/test/migration/test_project2.slow.rb +34 -0
- data/test/migration/test_remove.rb +219 -0
- data/test/migration/test_rename.rb +238 -0
- data/test/migration/test_scenario.rb +37 -0
- data/test/migration/todo.txt +17 -0
- data/test/more_asserts.rb +63 -0
- data/test/snapshot/test_snapshot.rb +99 -0
- data/test/snapshot/test_snapshot_attributes.slow.rb +57 -0
- data/test/snapshot/test_snapshot_classes.slow.rb +32 -0
- data/test/snapshot/test_snapshotable.rb +53 -0
- data/test/test_accessors.rb +46 -0
- data/test/test_active_model_like_interface.rb +1 -1
- data/test/test_model_timestamps.rb +22 -0
- data/test/test_more_asserts.rb +68 -0
- data/test/test_naming.rb +22 -0
- data/test/test_persistence.rb +127 -0
- data/test/test_query_interface.rb +20 -25
- data/test/test_sensibles.rb +38 -0
- data/test/test_validation.rb +20 -57
- data/todo.txt +1 -0
- data/update.sh +180 -0
- metadata +156 -12
- data/lib/maglev_record/model_not_saved_or_reset.rb +0 -15
- data/test/test_dirty_object.rb +0 -50
- data/test/test_maglev_record_base.rb +0 -22
- data/test/test_maglev_simple_persistance.rb +0 -45
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require "snapshot/test_snapshot"
|
|
2
|
+
|
|
3
|
+
class AttrSnapshotTest < SnapshotTest
|
|
4
|
+
|
|
5
|
+
def self.changes
|
|
6
|
+
@changes
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
as_instance_method :changes
|
|
10
|
+
|
|
11
|
+
def self.startup
|
|
12
|
+
super
|
|
13
|
+
clean
|
|
14
|
+
@changes = compare(
|
|
15
|
+
class_string('MyTestClass2', 'attr_accessor :no_value, :lala'),
|
|
16
|
+
class_string('MyTestClass2', 'attr_accessor :students, :lala'))
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.shutdown
|
|
20
|
+
super
|
|
21
|
+
clean
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_snapshot_without_error
|
|
25
|
+
assert_not_nil changes
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_no_class_removed
|
|
29
|
+
assert_equal changes.removed_classes, []
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_class_changed
|
|
33
|
+
assert_equal changes.changed_classes.size, 1
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_no_class_was_added
|
|
37
|
+
assert_equal [], changes.new_classes
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def changed_class
|
|
41
|
+
assert_not_nil changes.changed_classes[0], 'a class must have changed'
|
|
42
|
+
changes.changed_classes[0]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_accessor_added
|
|
46
|
+
assert_equal changed_class.new_attr_accessors, [:students]
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_accessor_removed
|
|
50
|
+
assert_equal changed_class.removed_attr_accessors, [:no_value]
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# TODO: add tests for attr_reader and attr_writer ...
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require "snapshot/test_snapshot"
|
|
2
|
+
|
|
3
|
+
class ClassSnapshotTest < SnapshotTest
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
super
|
|
7
|
+
clean
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def teardown
|
|
11
|
+
super
|
|
12
|
+
clean
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_new_class
|
|
16
|
+
changes = compare('', class_string('MyTestClass', 'def x;end'))
|
|
17
|
+
assert_equal 1, changes.new_classes.size
|
|
18
|
+
classdiv = changes.new_classes[0]
|
|
19
|
+
assert_equal classdiv.class_name, 'MyTestClass'
|
|
20
|
+
assert_equal classdiv.snapshot_class, MyTestClass
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_class_removed_from_file_but_still_in_stone
|
|
24
|
+
changes= compare(class_string('MyTestClass2', 'def x;end'), '')
|
|
25
|
+
assert_equal 1, changes.removed_classes.size
|
|
26
|
+
classdiv = changes.removed_classes[0]
|
|
27
|
+
assert_equal classdiv.class_name, 'MyTestClass2'
|
|
28
|
+
assert_equal classdiv.snapshot_class, MyTestClass2
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
require "maglev_record"
|
|
2
|
+
require "more_asserts"
|
|
3
|
+
|
|
4
|
+
class MySnapshotableClass
|
|
5
|
+
include MaglevRecord::Snapshotable
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
class MySnapshotableSubclass < MySnapshotableClass
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class MyNotSnapshotableClass
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class MyBaseClass
|
|
15
|
+
include MaglevRecord::Base
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
class SnapshotableTest < Test::Unit::TestCase
|
|
19
|
+
|
|
20
|
+
def self.startup
|
|
21
|
+
@snapshotable_classes = MaglevRecord::Snapshotable.snapshotable_classes
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.snapshotable_classes
|
|
25
|
+
@snapshotable_classes
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def snapshotable_classes
|
|
29
|
+
self.class.snapshotable_classes
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_includes_MySnapshotableClass
|
|
33
|
+
assert_include? snapshotable_classes, MySnapshotableClass
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_deas_not_include_Bases
|
|
37
|
+
assert_not_include? snapshotable_classes, MaglevRecord::Base
|
|
38
|
+
assert_not_include? snapshotable_classes, MaglevRecord::RootedBase
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def test_does_not_include_some_other_class
|
|
42
|
+
assert_not_include? snapshotable_classes, MyNotSnapshotableClass
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_includes_subclass
|
|
46
|
+
assert_include? snapshotable_classes, MySnapshotableSubclass
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_classes_including_base
|
|
50
|
+
assert_include? snapshotable_classes, MyBaseClass
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require "more_asserts"
|
|
2
|
+
require "maglev_record"
|
|
3
|
+
require "example_model"
|
|
4
|
+
|
|
5
|
+
class AccessorTest < Test::Unit::TestCase
|
|
6
|
+
|
|
7
|
+
def rooted_example_book
|
|
8
|
+
RootedBook.example
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def unrooted_example_book
|
|
12
|
+
UnrootedBook.example
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_accessors_working
|
|
16
|
+
[rooted_example_book, unrooted_example_book].each do |b|
|
|
17
|
+
assert_equal b.author, "Author"
|
|
18
|
+
assert_equal b.title, "Title"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_accessors_are_not_instance_variables
|
|
23
|
+
[rooted_example_book, unrooted_example_book].each do |b|
|
|
24
|
+
# In ruby 1.9 these are Symbols!
|
|
25
|
+
assert_not b.instance_variables.include? "@author"
|
|
26
|
+
assert_not b.instance_variables.include? "@title"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_accessors_are_stored_in_a_hash
|
|
31
|
+
[rooted_example_book, unrooted_example_book].each do |b|
|
|
32
|
+
assert b.attributes.is_a? Hash
|
|
33
|
+
assert b.attributes.has_key? :author
|
|
34
|
+
assert b.attributes.has_key? :title
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def test_updating_attributes
|
|
39
|
+
[rooted_example_book, unrooted_example_book].each do |b|
|
|
40
|
+
b.update_attributes(:title => "New Title", :author => 2)
|
|
41
|
+
assert_equal b.title, "New Title"
|
|
42
|
+
assert_equal b.author, 2
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require "more_asserts"
|
|
2
|
+
require "maglev_record"
|
|
3
|
+
require "example_model"
|
|
4
|
+
require "timecop"
|
|
5
|
+
|
|
6
|
+
class ModelTimestampTest < Test::Unit::TestCase
|
|
7
|
+
|
|
8
|
+
def test_time
|
|
9
|
+
@test_time ||= Time.local(2008, 9, 1, 10, 5, 0)
|
|
10
|
+
end
|
|
11
|
+
def test_created_at
|
|
12
|
+
Timecop.freeze(test_time)
|
|
13
|
+
model = RootedBook.example
|
|
14
|
+
assert_equal model.created_at, test_time
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def teardown
|
|
18
|
+
Timecop.return
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
require 'more_asserts'
|
|
2
|
+
|
|
3
|
+
class MyTest < Test::Unit::TestCase
|
|
4
|
+
|
|
5
|
+
def self.startup
|
|
6
|
+
#puts 'runs only once at start2'
|
|
7
|
+
if @startup_called.nil?
|
|
8
|
+
@startup_called = 1
|
|
9
|
+
else
|
|
10
|
+
@startup_called += 1
|
|
11
|
+
end
|
|
12
|
+
super
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.shutdown
|
|
16
|
+
#puts 'runs only once at end2'
|
|
17
|
+
if @shutdown_called.nil?
|
|
18
|
+
@shutdown_called = 1
|
|
19
|
+
else
|
|
20
|
+
@shutdown_called += 1
|
|
21
|
+
end
|
|
22
|
+
super
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def setup
|
|
26
|
+
@setup_called = true
|
|
27
|
+
#puts 'runs before each test'
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def teardown
|
|
31
|
+
@teardown_called = true
|
|
32
|
+
#puts 'runs after each test'
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_stuff
|
|
36
|
+
assert_equal @setup_called, true
|
|
37
|
+
assert_equal @teardown_called, nil
|
|
38
|
+
assert_equal self.class.instance_variable_get( :@shutdown_called ), nil
|
|
39
|
+
assert_equal self.class.instance_variable_get( :@startup_called ), 1
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_stuff2
|
|
43
|
+
test_stuff
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
class << self
|
|
47
|
+
alias :old_suite123 :suite
|
|
48
|
+
|
|
49
|
+
def suite
|
|
50
|
+
raise unless MyTest.instance_variable_get(:@shutdown_called) == nil
|
|
51
|
+
raise unless MyTest.instance_variable_get(:@startup_called) == nil
|
|
52
|
+
ret = old_suite123
|
|
53
|
+
class << ret
|
|
54
|
+
alias :run_old123 :run
|
|
55
|
+
|
|
56
|
+
def run(*args, &block)
|
|
57
|
+
raise unless MyTest.instance_variable_get(:@shutdown_called) == nil
|
|
58
|
+
raise unless MyTest.instance_variable_get(:@startup_called) == nil
|
|
59
|
+
ret = run_old123(*args, &block)
|
|
60
|
+
raise unless MyTest.instance_variable_get(:@shutdown_called) == 1
|
|
61
|
+
raise unless MyTest.instance_variable_get(:@startup_called) == 1
|
|
62
|
+
ret
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
ret
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
data/test/test_naming.rb
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require "more_asserts"
|
|
2
|
+
require "maglev_record"
|
|
3
|
+
require "example_model"
|
|
4
|
+
|
|
5
|
+
class NamingTest < Test::Unit::TestCase
|
|
6
|
+
|
|
7
|
+
def rooted_example_book
|
|
8
|
+
RootedBook.example
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def unrooted_example_book
|
|
12
|
+
UnrootedBook.example
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_models_respond_to_model_name
|
|
16
|
+
[rooted_example_book, unrooted_example_book].each do |b|
|
|
17
|
+
assert b.class.respond_to?(:model_name)
|
|
18
|
+
end
|
|
19
|
+
assert_equal "RootedBook", rooted_example_book.class.model_name
|
|
20
|
+
assert_equal "UnrootedBook", unrooted_example_book.class.model_name
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
require "more_asserts"
|
|
2
|
+
require "maglev_record"
|
|
3
|
+
require "example_model"
|
|
4
|
+
|
|
5
|
+
class UnrootedPersistanceTest < Test::Unit::TestCase
|
|
6
|
+
|
|
7
|
+
def setup
|
|
8
|
+
MaglevRecord.reset
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def new_unrooted_example_book
|
|
12
|
+
UnrootedBook.example
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_new_creates_new_object
|
|
16
|
+
b = new_unrooted_example_book
|
|
17
|
+
assert_not_nil b
|
|
18
|
+
assert_equal b.author, "Author"
|
|
19
|
+
assert_equal b.title, "Title"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_new_object_is_maglev_persistable
|
|
23
|
+
assert new_unrooted_example_book.class.maglev_persistable?
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_new_object_is_not_persisted
|
|
27
|
+
b = new_unrooted_example_book
|
|
28
|
+
assert b.new_record?
|
|
29
|
+
assert_not b.persisted?
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_persisted_object_is_persisted
|
|
33
|
+
b = new_unrooted_example_book
|
|
34
|
+
Maglev::PERSISTENT_ROOT[:test] = b
|
|
35
|
+
assert b.new_record?
|
|
36
|
+
assert_not b.persisted?
|
|
37
|
+
MaglevRecord.save
|
|
38
|
+
assert b.persisted?
|
|
39
|
+
assert_not b.new_record?
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_create_on_unrooted_model_should_raise_error
|
|
43
|
+
assert_raise MaglevRecord::InvalidOperationError do
|
|
44
|
+
UnrootedBook.create
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_clear_on_unrooted_model_should_raise_error
|
|
49
|
+
assert_raise MaglevRecord::InvalidOperationError do
|
|
50
|
+
UnrootedBook.clear
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def test_id_returns_object_id
|
|
55
|
+
b = new_unrooted_example_book
|
|
56
|
+
assert_equal b.id, b.object_id
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
class RootedPersistanceTest < Test::Unit::TestCase
|
|
62
|
+
|
|
63
|
+
def new_rooted_example_book
|
|
64
|
+
RootedBook.example
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def setup
|
|
68
|
+
MaglevRecord.reset
|
|
69
|
+
# RootedBook.clear
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def test_new_creates_new_object
|
|
73
|
+
b = new_rooted_example_book
|
|
74
|
+
assert_not_nil b
|
|
75
|
+
assert_equal b.author, "Author"
|
|
76
|
+
assert_equal b.title, "Title"
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def test_new_stores_object_in_persistent_root
|
|
80
|
+
b = new_rooted_example_book
|
|
81
|
+
assert RootedBook.object_pool.has_value? b
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def test_new_object_is_maglev_persistable
|
|
85
|
+
assert new_rooted_example_book.class.maglev_persistable?
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def test_new_object_is_not_persisted
|
|
89
|
+
b = new_rooted_example_book
|
|
90
|
+
assert b.new_record?
|
|
91
|
+
assert_not b.persisted?
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def test_persisted_object_is_persisted
|
|
95
|
+
b = new_rooted_example_book
|
|
96
|
+
Maglev::PERSISTENT_ROOT[:test] = b
|
|
97
|
+
assert b.new_record?
|
|
98
|
+
assert_not b.persisted?
|
|
99
|
+
MaglevRecord.save
|
|
100
|
+
assert b.persisted?
|
|
101
|
+
assert_not b.new_record?
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def test_object_pool_key_is_a_class
|
|
105
|
+
assert_equal RootedBook.object_pool_key, RootedBook
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def test_object_pool_is_a_hash
|
|
109
|
+
assert RootedBook.object_pool.is_a? Hash
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def test_clear_clears
|
|
113
|
+
RootedBook.new(RootedBook.example_params)
|
|
114
|
+
assert_not_equal RootedBook.object_pool.size, 0
|
|
115
|
+
MaglevRecord.save
|
|
116
|
+
RootedBook.clear
|
|
117
|
+
assert_equal RootedBook.object_pool.size, 0
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# def test_create_commits_model
|
|
121
|
+
# assert_equal RootedBook.size, 0
|
|
122
|
+
# RootedBook.create(RootedBook.example_params)
|
|
123
|
+
# MaglevRecord.reset
|
|
124
|
+
# assert_equal RootedBook.size, 1
|
|
125
|
+
# end
|
|
126
|
+
|
|
127
|
+
end
|
|
@@ -5,46 +5,41 @@ require "example_model"
|
|
|
5
5
|
class QueryInterfaceTest < Test::Unit::TestCase
|
|
6
6
|
|
|
7
7
|
def setup
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
Book.new(:title => "Harry Potter and the Half-blood Prince", :author => "Joanne K. Rowling"),
|
|
15
|
-
Book.new(:title => "Harry Potter and the Deathly Hallows", :author => "Joanne K. Rowling"),
|
|
16
|
-
Book.new(:title => "The Magician's Guild", :author => "Trudi Canavan")
|
|
17
|
-
].each do |book|
|
|
18
|
-
book.save
|
|
19
|
-
end
|
|
8
|
+
RootedBook.clear
|
|
9
|
+
RootedBook.create(:title => "Harry Potter and the Philosopher's stone", :author => "Joanne K. Rowling")
|
|
10
|
+
RootedBook.create(:title => "The Hobbit", :author => "J. R. R. Tolkien")
|
|
11
|
+
RootedBook.create(:title => "The Lord of the Rings", :author => "J. R. R. Tolkien")
|
|
12
|
+
RootedBook.create(:title => "Charlie and the Chocolate Factory", :author => "Roald Dahl")
|
|
13
|
+
RootedBook.create(:title => "A Christmas Carol", :author => "Charles Dickens")
|
|
20
14
|
end
|
|
21
15
|
|
|
22
|
-
def
|
|
23
|
-
|
|
16
|
+
def test_all_returns_all_books
|
|
17
|
+
all_books = RootedBook.all
|
|
18
|
+
assert_equal all_books.class, Array
|
|
19
|
+
assert_equal all_books.size, 5
|
|
24
20
|
end
|
|
25
21
|
|
|
26
22
|
def test_size_returns_correct_amount_of_books
|
|
27
|
-
assert_equal
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def test_clear_clears_the_database
|
|
31
|
-
assert Book.size > 0
|
|
32
|
-
Book.clear
|
|
33
|
-
assert Book.size == 0
|
|
23
|
+
assert_equal RootedBook.size, 5
|
|
34
24
|
end
|
|
35
25
|
|
|
36
26
|
def test_first_returns_the_first_book
|
|
37
|
-
assert
|
|
27
|
+
assert RootedBook.first.title.include? "Philosopher"
|
|
38
28
|
end
|
|
39
29
|
|
|
40
30
|
def test_normal_enumerable_methods_work
|
|
41
|
-
assert_equal
|
|
31
|
+
assert_equal 2, RootedBook.count { |b| b.author == "J. R. R. Tolkien" }
|
|
42
32
|
end
|
|
43
33
|
|
|
44
34
|
def test_work_on_real_objects
|
|
45
|
-
book =
|
|
35
|
+
book = RootedBook.first
|
|
46
36
|
book.author = "William Shakespeare"
|
|
47
|
-
assert_equal
|
|
37
|
+
assert_equal RootedBook.first.author, "William Shakespeare"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_find_object_by_id
|
|
41
|
+
book = RootedBook.all[2]
|
|
42
|
+
assert_equal book, RootedBook.find_by_objectid(book.object_id)
|
|
48
43
|
end
|
|
49
44
|
|
|
50
45
|
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require "more_asserts"
|
|
2
|
+
require "maglev_record"
|
|
3
|
+
|
|
4
|
+
class User
|
|
5
|
+
include MaglevRecord::RootedBase
|
|
6
|
+
attr_accessor :password_digest
|
|
7
|
+
|
|
8
|
+
has_secure_password
|
|
9
|
+
# TODO: No validations so far
|
|
10
|
+
# validates_presence_of :password, :on => :create
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class SensibleTest #< Test::Unit::TestCase
|
|
14
|
+
|
|
15
|
+
def pass
|
|
16
|
+
"some_pass"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def example_user
|
|
20
|
+
attr_hash = {
|
|
21
|
+
:password => pass,
|
|
22
|
+
:password_confirmation => pass,
|
|
23
|
+
}
|
|
24
|
+
User.new(attr_hash)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_sensible_deletion
|
|
28
|
+
user = example_user
|
|
29
|
+
|
|
30
|
+
assert_equal user.password, pass
|
|
31
|
+
assert_equal user.password_confirmation, pass
|
|
32
|
+
|
|
33
|
+
user.clear_sensibles
|
|
34
|
+
|
|
35
|
+
assert_equal user.password, nil
|
|
36
|
+
assert_equal user.password_confirmation, nil
|
|
37
|
+
end
|
|
38
|
+
end
|
data/test/test_validation.rb
CHANGED
|
@@ -1,81 +1,44 @@
|
|
|
1
|
-
require "
|
|
1
|
+
require "more_asserts"
|
|
2
2
|
require "maglev_record"
|
|
3
3
|
require "example_model"
|
|
4
4
|
|
|
5
5
|
class ValidationTest < Test::Unit::TestCase
|
|
6
6
|
|
|
7
7
|
def setup
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
].each do |book|
|
|
12
|
-
book.save
|
|
13
|
-
end
|
|
8
|
+
MaglevRecord.reset
|
|
9
|
+
RootedBook.clear
|
|
10
|
+
MaglevRecord.save
|
|
14
11
|
end
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
book = Book.find { |b| b.title == "Harry Potter and the Philosopher's stone" }
|
|
22
|
-
book.author = "J. R. R. Tolkien"
|
|
23
|
-
book.reset_author!
|
|
24
|
-
assert_equal book.author, "Joanne K. Rowling"
|
|
25
|
-
end
|
|
13
|
+
# TODO
|
|
14
|
+
# def test_reset
|
|
15
|
+
# book = Book.find { |b| b.title == "Harry Potter and the Philosopher's stone" }
|
|
16
|
+
# book.author = "J. R. R. Tolkien"
|
|
17
|
+
# book.title = "The Lord of the Rings"
|
|
26
18
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
book.title = "The Lord of the Rings"
|
|
31
|
-
#book.reset!
|
|
32
|
-
#assert_equal book.author, "Joanne K. Rowling"
|
|
33
|
-
#assert_equal book.title, "Harry Potter and the Philosopher's stone"
|
|
34
|
-
end
|
|
19
|
+
# MaglevRecord.reset
|
|
20
|
+
# assert_not_nil Book.find { |b| b.title == "Harry Potter and the Philosopher's stone" }
|
|
21
|
+
# end
|
|
35
22
|
|
|
36
|
-
def
|
|
37
|
-
|
|
23
|
+
def test_validation_works
|
|
24
|
+
book = RootedBook.new(:author => "Book")
|
|
25
|
+
assert book.valid?
|
|
26
|
+
assert_not book.invalid?
|
|
27
|
+
MaglevRecord.save
|
|
38
28
|
end
|
|
39
29
|
|
|
40
30
|
def test_validation_fails
|
|
41
|
-
book =
|
|
31
|
+
book = RootedBook.new()
|
|
42
32
|
assert !book.valid?
|
|
43
33
|
assert book.invalid?
|
|
34
|
+
MaglevRecord.save
|
|
44
35
|
end
|
|
45
36
|
|
|
46
37
|
def test_errors_not_empty
|
|
47
|
-
book =
|
|
38
|
+
book = RootedBook.new()
|
|
48
39
|
book.valid?
|
|
49
40
|
assert book.errors.count > 0
|
|
50
41
|
end
|
|
51
42
|
|
|
52
|
-
def test_validation_succeeds
|
|
53
|
-
book = Book.new(:author => "J. R. R. Tolkien", :title => "Harry Potter and the Philosopher's stone")
|
|
54
|
-
assert book.valid?
|
|
55
|
-
assert !book.invalid?
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def test_save_excl_invalid_throws_error
|
|
59
|
-
book = invalid_model
|
|
60
|
-
|
|
61
|
-
@catch = false
|
|
62
|
-
begin
|
|
63
|
-
book.save!
|
|
64
|
-
rescue StandardError
|
|
65
|
-
@catch = true
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
assert @catch
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def test_save_invalid_returns_false
|
|
72
|
-
book = invalid_model
|
|
73
|
-
assert !book.save
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def test_save_skip_validation
|
|
77
|
-
book = invalid_model
|
|
78
|
-
assert book.save(:validate => false)
|
|
79
|
-
end
|
|
80
43
|
end
|
|
81
44
|
|
data/todo.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
be rake testslow TEST=/home/nicco/Documents/maglevrecord/test/migration/test_snapshot.rb ; buildtest
|