lims-core 3.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +5 -0
  3. data/.rspec +1 -0
  4. data/.rvmrc +2 -0
  5. data/.travis.yml +2 -0
  6. data/.vimrc +27 -0
  7. data/.yard_templates/default/layout/html/footer.erb +0 -0
  8. data/.yardopts +1 -0
  9. data/Gemfile +54 -0
  10. data/Gemfile.lock +197 -0
  11. data/Guardfile +21 -0
  12. data/Guardfile.tmux +28 -0
  13. data/README.markdown +67 -0
  14. data/Rakefile +16 -0
  15. data/config/database.yml +16 -0
  16. data/doc/Array.html +116 -0
  17. data/doc/Array/ArrayLoggerPersistor.html +152 -0
  18. data/doc/Lims.html +114 -0
  19. data/doc/Lims/Core.html +178 -0
  20. data/doc/Lims/Core/Action.html +91 -0
  21. data/doc/Lims/Core/Actions.html +116 -0
  22. data/doc/Lims/Core/Actions/Action.html +216 -0
  23. data/doc/Lims/Core/Actions/Action/AfterEval.html +853 -0
  24. data/doc/Lims/Core/Actions/Action/InvalidParameters.html +268 -0
  25. data/doc/Lims/Core/Actions/ActionGroup.html +196 -0
  26. data/doc/Lims/Core/Actions/ActionGroup/AfterEval.html +315 -0
  27. data/doc/Lims/Core/Actions/BulkAction.html +224 -0
  28. data/doc/Lims/Core/Actions/BulkAction/AfterEval.html +253 -0
  29. data/doc/Lims/Core/Actions/TestActionGroup.html +101 -0
  30. data/doc/Lims/Core/Actions/TestActionGroup/Action.html +133 -0
  31. data/doc/Lims/Core/Actions/TestActionGroup/ActionGroup.html +127 -0
  32. data/doc/Lims/Core/Base.html +287 -0
  33. data/doc/Lims/Core/Base/AccessibleViaSuper.html +252 -0
  34. data/doc/Lims/Core/Base/ClassMethod.html +177 -0
  35. data/doc/Lims/Core/Base/HashString.html +177 -0
  36. data/doc/Lims/Core/Base/IsArrayOf.html +606 -0
  37. data/doc/Lims/Core/Base/State.html +130 -0
  38. data/doc/Lims/Core/Organization.html +113 -0
  39. data/doc/Lims/Core/Organization/Batch.html +106 -0
  40. data/doc/Lims/Core/Persistence.html +267 -0
  41. data/doc/Lims/Core/Persistence/ComparisonFilter.html +318 -0
  42. data/doc/Lims/Core/Persistence/Filter.html +252 -0
  43. data/doc/Lims/Core/Persistence/IdentityMap.html +409 -0
  44. data/doc/Lims/Core/Persistence/IdentityMap/Class.html +144 -0
  45. data/doc/Lims/Core/Persistence/IdentityMap/DuplicateError.html +126 -0
  46. data/doc/Lims/Core/Persistence/IdentityMap/DuplicateIdError.html +136 -0
  47. data/doc/Lims/Core/Persistence/IdentityMap/DuplicateObjectError.html +136 -0
  48. data/doc/Lims/Core/Persistence/IdentityMapClass.html +133 -0
  49. data/doc/Lims/Core/Persistence/Logger.html +105 -0
  50. data/doc/Lims/Core/Persistence/Logger/Persistor.html +334 -0
  51. data/doc/Lims/Core/Persistence/Logger/Session.html +452 -0
  52. data/doc/Lims/Core/Persistence/Logger/Store.html +470 -0
  53. data/doc/Lims/Core/Persistence/MessageBus.html +871 -0
  54. data/doc/Lims/Core/Persistence/MessageBus/ConnectionError.html +123 -0
  55. data/doc/Lims/Core/Persistence/MessageBus/InvalidSettingsError.html +122 -0
  56. data/doc/Lims/Core/Persistence/MultiCriteriaFilter.html +293 -0
  57. data/doc/Lims/Core/Persistence/PersistAssociationTrait.html +91 -0
  58. data/doc/Lims/Core/Persistence/PersistableTrait.html +91 -0
  59. data/doc/Lims/Core/Persistence/Persistor.html +3072 -0
  60. data/doc/Lims/Core/Persistence/Persistor/DuplicateError.html +205 -0
  61. data/doc/Lims/Core/Persistence/Persistor/DuplicateIdError.html +147 -0
  62. data/doc/Lims/Core/Persistence/Persistor/DuplicateObjectError.html +147 -0
  63. data/doc/Lims/Core/Persistence/PersistorTrait.html +91 -0
  64. data/doc/Lims/Core/Persistence/ResourceState.html +1738 -0
  65. data/doc/Lims/Core/Persistence/Search.html +269 -0
  66. data/doc/Lims/Core/Persistence/Search/CreateSearch.html +251 -0
  67. data/doc/Lims/Core/Persistence/Search/SearchPersistor.html +240 -0
  68. data/doc/Lims/Core/Persistence/Search/SearchSequelPersistor.html +396 -0
  69. data/doc/Lims/Core/Persistence/Sequel.html +117 -0
  70. data/doc/Lims/Core/Persistence/Sequel/Filters.html +462 -0
  71. data/doc/Lims/Core/Persistence/Sequel/ForTest.html +101 -0
  72. data/doc/Lims/Core/Persistence/Sequel/ForTest/Name.html +137 -0
  73. data/doc/Lims/Core/Persistence/Sequel/ForTest/Name/NamePersitor.html +143 -0
  74. data/doc/Lims/Core/Persistence/Sequel/Migrations.html +266 -0
  75. data/doc/Lims/Core/Persistence/Sequel/Persistor.html +665 -0
  76. data/doc/Lims/Core/Persistence/Sequel/Session.html +501 -0
  77. data/doc/Lims/Core/Persistence/Sequel/Store.html +417 -0
  78. data/doc/Lims/Core/Persistence/Session.html +2751 -0
  79. data/doc/Lims/Core/Persistence/Session/UnmanagedObjectError.html +111 -0
  80. data/doc/Lims/Core/Persistence/StateGroup.html +696 -0
  81. data/doc/Lims/Core/Persistence/StateList.html +498 -0
  82. data/doc/Lims/Core/Persistence/Store.html +695 -0
  83. data/doc/Lims/Core/Persistence/UuidResource.html +1044 -0
  84. data/doc/Lims/Core/Persistence/UuidResource/InvalidUuidError.html +111 -0
  85. data/doc/Lims/Core/Persistence/UuidResource/UuidResourcePersistor.html +337 -0
  86. data/doc/Lims/Core/Persistence/Uuidable.html +799 -0
  87. data/doc/Lims/Core/Persistor.html +320 -0
  88. data/doc/Lims/Core/Resource.html +165 -0
  89. data/doc/Object.html +228 -0
  90. data/doc/SessionSpec.html +101 -0
  91. data/doc/SessionSpec/Model.html +279 -0
  92. data/doc/SessionSpec/Model/ModelPersistor.html +327 -0
  93. data/doc/_index.html +732 -0
  94. data/doc/class_list.html +47 -0
  95. data/doc/css/common.css +1 -0
  96. data/doc/css/full_list.css +55 -0
  97. data/doc/css/style.css +322 -0
  98. data/doc/file.README.html +127 -0
  99. data/doc/file_list.html +49 -0
  100. data/doc/frames.html +13 -0
  101. data/doc/index.html +127 -0
  102. data/doc/js/app.js +205 -0
  103. data/doc/js/full_list.js +167 -0
  104. data/doc/js/jquery.js +16 -0
  105. data/doc/method_list.html +1894 -0
  106. data/doc/top-level-namespace.html +100 -0
  107. data/lib/common.rb +18 -0
  108. data/lib/lims-core.rb +29 -0
  109. data/lib/lims-core/actions.rb +10 -0
  110. data/lib/lims-core/actions/action.rb +185 -0
  111. data/lib/lims-core/actions/action_group.rb +54 -0
  112. data/lib/lims-core/actions/bulk_action.rb +65 -0
  113. data/lib/lims-core/base.rb +132 -0
  114. data/lib/lims-core/helpers.rb +41 -0
  115. data/lib/lims-core/persistence.rb +15 -0
  116. data/lib/lims-core/persistence/comparison_filter.rb +54 -0
  117. data/lib/lims-core/persistence/filter.rb +23 -0
  118. data/lib/lims-core/persistence/identity_map.rb +55 -0
  119. data/lib/lims-core/persistence/logger/all.rb +5 -0
  120. data/lib/lims-core/persistence/logger/persistor.rb +35 -0
  121. data/lib/lims-core/persistence/logger/session.rb +30 -0
  122. data/lib/lims-core/persistence/logger/store.rb +37 -0
  123. data/lib/lims-core/persistence/message_bus.rb +131 -0
  124. data/lib/lims-core/persistence/multi_criteria_filter.rb +50 -0
  125. data/lib/lims-core/persistence/persist_association_trait.rb +96 -0
  126. data/lib/lims-core/persistence/persistable_trait.rb +150 -0
  127. data/lib/lims-core/persistence/persistor.rb +495 -0
  128. data/lib/lims-core/persistence/resource_state.rb +157 -0
  129. data/lib/lims-core/persistence/search.rb +3 -0
  130. data/lib/lims-core/persistence/search/all.rb +3 -0
  131. data/lib/lims-core/persistence/search/create_search.rb +55 -0
  132. data/lib/lims-core/persistence/search/search_persistor.rb +45 -0
  133. data/lib/lims-core/persistence/search/search_sequel_persistor.rb +40 -0
  134. data/lib/lims-core/persistence/sequel.rb +14 -0
  135. data/lib/lims-core/persistence/sequel/filters.rb +106 -0
  136. data/lib/lims-core/persistence/sequel/migrations.rb +14 -0
  137. data/lib/lims-core/persistence/sequel/migrations/add_audit_tables.rb +147 -0
  138. data/lib/lims-core/persistence/sequel/migrations/initial.rb +156 -0
  139. data/lib/lims-core/persistence/sequel/persistor.rb +200 -0
  140. data/lib/lims-core/persistence/sequel/session.rb +136 -0
  141. data/lib/lims-core/persistence/sequel/store.rb +37 -0
  142. data/lib/lims-core/persistence/session.rb +409 -0
  143. data/lib/lims-core/persistence/state_group.rb +97 -0
  144. data/lib/lims-core/persistence/state_list.rb +56 -0
  145. data/lib/lims-core/persistence/store.rb +73 -0
  146. data/lib/lims-core/persistence/uuid_resource.rb +115 -0
  147. data/lib/lims-core/persistence/uuid_resource_persistor.rb +43 -0
  148. data/lib/lims-core/persistence/uuidable.rb +107 -0
  149. data/lib/lims-core/resource.rb +21 -0
  150. data/lib/lims-core/subclass_tracker.rb +30 -0
  151. data/lib/lims-core/version.rb +5 -0
  152. data/lims-core.gemspec +40 -0
  153. data/makefile +52 -0
  154. data/showoff/core-2012-06-11/core/01_slide.md +237 -0
  155. data/showoff/core-2012-06-11/core/02_slide.md +110 -0
  156. data/showoff/core-2012-06-11/custom.css +44 -0
  157. data/showoff/core-2012-06-11/main/01_slide.md +53 -0
  158. data/showoff/core-2012-06-11/showoff.json +10 -0
  159. data/showoff/core-2012-06-11/tp1.tpl +1 -0
  160. data/spec/actions/action_group_spec.rb +39 -0
  161. data/spec/actions/spec_helper.rb +1 -0
  162. data/spec/persistence/identity_map_spec.rb +55 -0
  163. data/spec/persistence/logger/spec_helper.rb +7 -0
  164. data/spec/persistence/logger/store_spec.rb +48 -0
  165. data/spec/persistence/message_bus_spec.rb +76 -0
  166. data/spec/persistence/sequel/session_spec.rb +125 -0
  167. data/spec/persistence/sequel/spec_helper.rb +39 -0
  168. data/spec/persistence/sequel/store_shared.rb +25 -0
  169. data/spec/persistence/sequel/store_spec.rb +22 -0
  170. data/spec/persistence/session_spec.rb +199 -0
  171. data/spec/persistence/spec_helper.rb +2 -0
  172. data/spec/persistence/uuid_resource_spec.rb +80 -0
  173. data/spec/spec_helper.rb +10 -0
  174. data/spec/subclass_tracker_sperc.rb +62 -0
  175. data/utils/constant_tree.rb +29 -0
  176. data/utils/stack.rb +48 -0
  177. metadata +402 -0
@@ -0,0 +1,44 @@
1
+ .content {
2
+ color: black;
3
+ font-family: helvetica, arial;
4
+ }
5
+
6
+ h1, h2 {
7
+ color: rgb(79, 180, 226);
8
+ font-family: Georgia;
9
+ margin : 1em;
10
+ }
11
+
12
+ h3 {
13
+ font-size : 2.5 em;
14
+ text-align : left;
15
+ margin-left : 1em;
16
+ }
17
+
18
+ .subsection h1 {
19
+ color : white;
20
+ background : rgb(79, 180, 226);
21
+ font-size : 3em;
22
+ text-align : right;
23
+
24
+ }
25
+
26
+ h2 {
27
+ #background : #ccc;
28
+ text-align : left;
29
+ margin-left : 1em;
30
+ }
31
+ .content::after {
32
+ position: absolute;
33
+ right: 120px;
34
+ bottom: 120px;
35
+ content: url(jay_small.png);
36
+ }
37
+
38
+ .red { color: #f33;}
39
+
40
+ pre.sh_sourceCode {
41
+ background-color : #eee;
42
+ #border-radius : 0.5em;
43
+ box-shadow: -10px 10px 5px #888;
44
+ }
@@ -0,0 +1,53 @@
1
+ !SLIDE top
2
+ # New LIMS Core
3
+ Maxime Bourget - Monday 2012/06/11
4
+ !SLIDE subsection transition=scrollLeft
5
+ # Overview
6
+ * What it is and why.
7
+ * How it works/design.
8
+ * What's done
9
+ * To do
10
+
11
+ !SLIDE transition=scrollUp small subsection
12
+ # New LIMS Core
13
+ ## Set of gems, core of the new LIMS.
14
+
15
+ * Contains the domain model.
16
+ * Interface for different persistence layers.
17
+ * Organized in components.
18
+ * No web/GUI *knowledge*.
19
+
20
+ ### Needs to be embedded in a server/application.
21
+
22
+
23
+ !SLIDE smaller subsection transition=scrollUp
24
+ # New LIMS Core
25
+ ## Lessons learned from Sequencescape
26
+ ### Persistence mixed with the domain implementation, adds *noise* to the code :
27
+
28
+ * Domain code *aware* of persistence (`reload`, no identity map).
29
+ * Domain tests have to take persistence into account (`save`, `reload`).
30
+ * Object model too close from database model.
31
+ * No identity map.
32
+ * Tests slow.
33
+ * Hard to maintain.
34
+
35
+ .notes ActiveRecord is magic, but hard to customize and optimize.
36
+
37
+ !SLIDE small subsection transition=scrollUp
38
+ # New LIMS Core
39
+ ## Goal
40
+ ### Decouple domain model from persistence layer.
41
+ * Code easier to split into component.
42
+ * Domains of *responsibilities* clearer.
43
+ * Less side effect.
44
+ * Test suites small and faster.
45
+ ### ... How do we do it ?
46
+
47
+
48
+ !SLIDE small transition=scrollLeft
49
+ # New LIMS server internal architecture
50
+
51
+ * `lims::api` Sinatra application
52
+ * Core extensions (clients specific) (optional)
53
+ * `lims:core` gem domain model + persistence.
@@ -0,0 +1,10 @@
1
+ { "name": "New core"
2
+ ,
3
+ "author" : "Maxime Bourget"
4
+ , "description" : "Prestentation of the new core"
5
+ , "sections": [
6
+ { "section" : "main" },
7
+ { "section" : "core" }
8
+ ]
9
+ , "templates": { "default" : "tp1.tpl" }
10
+ }
@@ -0,0 +1 @@
1
+ Hello, this is my template
@@ -0,0 +1,39 @@
1
+ require 'actions/spec_helper'
2
+
3
+ require 'lims-core/actions/action_group'
4
+ module Lims::Core
5
+ module Actions
6
+ module TestActionGroup
7
+ class Action
8
+ include Actions::Action
9
+ end
10
+ class ActionGroup
11
+ include Actions::ActionGroup
12
+ end
13
+ describe ActionGroup do
14
+ context "with 2 actions" do
15
+ let(:store) { Lims::Core::Persistence::Store.new }
16
+ let(:user) { mock :user }
17
+ let(:application) { "test" }
18
+ let(:action_parameters) { {:user => user, :application => application, :store => store } }
19
+ let!(:action1) { Action.new(action_parameters).tap do |action|
20
+ end }
21
+ let!(:action2) { Action.new(action_parameters).tap do |action|
22
+ end }
23
+
24
+ subject{ ActionGroup.new(action_parameters.merge(:actions => [action1, action2])) do |action, session|
25
+ end
26
+ }
27
+
28
+ it "executes both action" do
29
+ action1.should_receive(:_call_in_session) { :result_1 }
30
+ action2.should_receive(:_call_in_session) { :result_2 }
31
+
32
+ subject.call();
33
+ subject.result.should == [:result_1, :result_2]
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1 @@
1
+ require 'spec_helper'
@@ -0,0 +1,55 @@
1
+ # Spec requirements
2
+ require 'persistence/spec_helper'
3
+
4
+ # Model requirements
5
+ require 'lims-core/persistence/identity_map'
6
+
7
+
8
+
9
+
10
+ module Lims::Core::Persistence
11
+ class IdentityMapClass
12
+ include IdentityMap
13
+ end
14
+
15
+ describe IdentityMapClass, :identity_map => true, :persistence => true do
16
+
17
+ context "with a object mapped to an id" do
18
+ let(:id) { 1 }
19
+ let(:object) { "Object 1" }
20
+ before {subject.map_id_object(id,object) }
21
+
22
+ it "must find the object by id" do
23
+ subject.object_for(id).should == object
24
+ end
25
+
26
+ it "must find the id by object" do
27
+ subject.id_for(object).should == id
28
+ end
29
+
30
+ it "must fail when mapping another object with the same id" do
31
+ expect { subject.map_id_object(id, "Object #2") }.to raise_error(IdentityMap::DuplicateIdError)
32
+ end
33
+
34
+ it "must fail when mapping another id with the same object" do
35
+ expect { subject.map_id_object(2, object) }.to raise_error(IdentityMap::DuplicateObjectError)
36
+ end
37
+
38
+ it "must not fail when mapping it again" do
39
+ expect { subject.map_id_object(id, object) }.not_to raise_error(IdentityMap::DuplicateError)
40
+ end
41
+
42
+ it "must yield the object" do
43
+ subject.object_for(id) do |o|
44
+ o.should == object
45
+ end
46
+ end
47
+
48
+ it "must not yield if the object can't be found" do
49
+ subject.object_for("wrong id") do |o|
50
+ raise "not found"
51
+ end.should be_nil
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ require 'lims-core/persistence/logger/store'
4
+
5
+ RSpec.configure do |c|
6
+ c.filter_run_excluding :logger => true
7
+ end
@@ -0,0 +1,48 @@
1
+ # Spec requirements
2
+ require 'persistence/logger/spec_helper'
3
+
4
+ # Model requirements
5
+ require 'logger'
6
+ require 'lims-core/persistence/logger/store'
7
+ require 'lims-core/persistence/logger/persistor'
8
+
9
+ class Array
10
+ class ArrayLoggerPersistor < Lims::Core::Persistence::Persistor
11
+ include Lims::Core::Persistence::Logger::Persistor
12
+ end
13
+ end
14
+
15
+ module Lims::Core
16
+ module Persistence
17
+ describe Logger::Store, :store => true, :logger => true, :persistence => true do
18
+ def self.initialized_with_a_logger(method)
19
+ context "initialized with a logger" do
20
+ let (:logger) { ::Logger.new($stdout) }
21
+ subject { described_class.new(logger, method) }
22
+ it "should log objects to stdout" do
23
+ logger.should_receive(:send).with(method, '["A1", "A2", "B1", "B2"]')
24
+ subject.with_session do |session|
25
+ session << %w(A1 A2 B1 B2)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ def self.initialized_with_an_IO(io)
31
+ context "initialized to stdout" do
32
+ subject { described_class.new(io) }
33
+ it "should log objects to stdout" do
34
+ io.should_receive(:write)
35
+ subject.with_session do |session|
36
+ session << %w(A1 A2 B1 B2)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ initialized_with_an_IO(STDOUT)
42
+ initialized_with_an_IO(STDERR)
43
+
44
+ initialized_with_a_logger(:info)
45
+ initialized_with_a_logger(:warn)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,76 @@
1
+ require 'lims-core/persistence/message_bus'
2
+
3
+ module Lims::Core
4
+ module Persistence
5
+ describe MessageBus, :message_bus => true do
6
+ context "to be valid" do
7
+ let(:url) { "amqp://user:password@localhost:55672" }
8
+ let(:exchange_name) { "exchange_name" }
9
+ let(:durable) { true }
10
+ let(:prefetch_number) { 30 }
11
+ let(:heart_beat) { 0 }
12
+ let(:backend_application_id) { "test backend app" }
13
+ let(:another_backend_application_id) { "another backend app id" }
14
+ let(:bus_settings) { { "url" => url,
15
+ "exchange_name" => exchange_name,
16
+ "durable" => durable,
17
+ "prefetch_number" => prefetch_number,
18
+ "heart_beat" => heart_beat,
19
+ "backend_application_id" => backend_application_id}
20
+ }
21
+
22
+ it "requires a RabbitMQ host" do
23
+ described_class.new(bus_settings - ["url"]).valid?.should == false
24
+ end
25
+
26
+ it "requires an exchange name" do
27
+ described_class.new(bus_settings - ["exchange_name"]).valid?.should == false
28
+ end
29
+
30
+ it "requires the durable option" do
31
+ described_class.new(bus_settings - ["durable"]).valid?.should == false
32
+ end
33
+
34
+ it "requires a prefetch number" do
35
+ described_class.new(bus_settings - ["prefetch_number"]).valid?.should == false
36
+ end
37
+
38
+ it "not requires a heart_beat value" do
39
+ described_class.new(bus_settings - ["heart_beat"]).valid?.should == true
40
+ end
41
+
42
+ it "requires the backend_application_id value" do
43
+ described_class.new(bus_settings - ["backend_application_id"]).valid?.should == false
44
+ end
45
+
46
+ it "requires correct settings" do
47
+ described_class.new(bus_settings).valid?.should == true
48
+ end
49
+
50
+ it "sets the exchange type to topic by default" do
51
+ described_class.new(bus_settings).exchange_type.should == "topic"
52
+ end
53
+
54
+ it "requires correct settings to connect to the message bus" do
55
+ expect do
56
+ described_class.new(bus_settings - ["url"]).connect
57
+ end.to raise_error(MessageBus::InvalidSettingsError)
58
+ end
59
+
60
+ it "requires an exchange to publish a message" do
61
+ expect do
62
+ described_class.new(bus_settings).publish("message")
63
+ end.to raise_error(MessageBus::ConnectionError)
64
+ end
65
+
66
+ it "raise an error if set the backend app id more then once" do
67
+ expect do
68
+ message_bus = described_class.new(bus_settings)
69
+ message_bus.backend_application_id = another_backend_application_id
70
+ end.to raise_error(MessageBus::InvalidSettingsError)
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+
@@ -0,0 +1,125 @@
1
+ # Spec requirements
2
+ require 'persistence/sequel/spec_helper'
3
+
4
+ # Model requirements
5
+ require 'lims-core/persistence/sequel/store'
6
+ require 'lims-core/persistence/sequel/session'
7
+ require 'lims-core/persistence/sequel/persistor'
8
+
9
+ module Lims::Core::Persistence
10
+ module ForTest
11
+ class Name
12
+ include Lims::Core::Resource
13
+ attribute :name, String
14
+ class NamePersitor < Lims::Core::Persistence::Persistor
15
+ Model = Name
16
+ end
17
+ end
18
+ end
19
+
20
+ module Sequel
21
+ describe Session, :session => true, :persistence => true, :persistence => true, :sequel => true do
22
+ context "with mysql underlying" do
23
+ include_context "mysql db"
24
+ let(:store) { Store.new(db).tap do
25
+ db.create_table :sessions do
26
+ primary_key :id
27
+ String :user
28
+ String :backend_application_id
29
+ String :parameters, :text => true
30
+ boolean :success
31
+ timestamp :start_time
32
+ DateTime :end_time
33
+ end unless db.table_exists?(:sessions)
34
+ end}
35
+ xit "sets a new session_id to work with" do
36
+ begin
37
+ my_session_id=nil
38
+ store.with_session do |s|
39
+ my_session_id = s.get_current_session
40
+ end
41
+ rescue
42
+ end
43
+ (my_session_id == nil).should == false
44
+ end
45
+ xit "session is reseted after scope" do
46
+ begin
47
+ my_session_id=nil
48
+ store.with_session do |s|
49
+ my_session_id = s.get_current_session
50
+ end
51
+ my_session_after_scope = s.get_current_session
52
+ rescue
53
+ end
54
+ (my_session_after_scope == my_session_id).should == false
55
+ (my_session_after_scope == nil).should == true
56
+ end
57
+ xit "a different session if I create a new scope" do
58
+ begin
59
+ my_session_id=nil
60
+ my_session_id_2=nil
61
+ store.with_session do |s|
62
+ my_session_id = s.get_current_session
63
+ end
64
+ my_session_after_scope = s.get_current_session
65
+ store.with_session do |s|
66
+ my_session_id_2 = s.get_current_session
67
+ end
68
+ my_session_after_scope_2 = s.get_current_session
69
+ rescue
70
+ end
71
+ (my_session_id == my_session_id_2).should == false
72
+ end
73
+ end
74
+
75
+ context "with sqlite underlying" do
76
+ include_context "sqlite db"
77
+ let(:store) { Store.new(db).tap do
78
+ db.create_table :primary_keys do
79
+ primary_key :id
80
+ String :table_name
81
+ Integer :current_key
82
+ end
83
+ end
84
+ }
85
+
86
+ context "#transaction" do
87
+ let(:a) { ForTest::Name.new(:name => "A") }
88
+ let(:b) { ForTest::Name.new(:name => "B") }
89
+ let(:c) { ForTest::Name.new(:name => "C") }
90
+
91
+ before() do
92
+ db.create_table :names do
93
+ primary_key :id
94
+ String :name
95
+ end
96
+
97
+ c.stub(:attributes) do
98
+ raise RuntimeError, "Can't save '#{inspect}'"
99
+ end
100
+ end
101
+
102
+ it "save the 2 if no problem" do
103
+ expect { store.with_session do |s|
104
+ s << a << b
105
+ end }.to change{db[:names].count}.by(2)
106
+ end
107
+
108
+ it "saves 0 if the second doesn't save" do
109
+ expect {
110
+ begin
111
+ store.with_session do |s|
112
+ s << a << c
113
+ end
114
+ rescue
115
+ end
116
+ }.to change{db[:names].count}.by(0)
117
+ end
118
+
119
+ xit "saves 0 if the second is not valid" do
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end