rack-datamapper 0.2.6 → 0.3.2

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.
@@ -1,6 +1,14 @@
1
- === 0.2.6 / 2010-06-15
1
+ === 0.3.2 / 2010-06-15
2
2
 
3
- * just disallow datamapper 1.0.0 which does not work for some parts, use rack_datamapper 0.3.0 gem if you need datamapper 1.0.0
3
+ * fixed now the session store works also with dm-validations
4
+
5
+ === 0.3.1 / 2010-06-15
6
+
7
+ * maven did not handle the declared deps nicely, repush the gem with proper deps version
8
+
9
+ === 0.3.0 / 2010-06-15
10
+
11
+ * removed hoe use gemspec or maven instead, works only with datamapper version '~>1.0.0'
4
12
 
5
13
  === 0.2.5 / 2009-12-04
6
14
 
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Kristian Meier
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,18 +1,24 @@
1
1
  # -*- ruby -*-
2
2
 
3
3
  require 'rubygems'
4
- require 'hoe'
5
- require './lib/rack_datamapper/version.rb'
6
4
 
7
5
  require 'spec'
8
6
  require 'spec/rake/spectask'
9
7
  require 'pathname'
10
8
  require 'yard'
11
9
 
12
- Hoe.spec('rack-datamapper') do |p|
13
- p.developer('mkristian', 'm.kristian@web.de')
14
- p.extra_deps = [['dm-core', ['>0.9.10', '<1.0.0']]]
15
- p.rspec_options << '--options' << 'spec/spec.opts'
10
+ desc "Run specs"
11
+ Spec::Rake::SpecTask.new('spec')
12
+
13
+ task :clean do
14
+ sh "rm -r pkg"
15
+ end
16
+
17
+ desc 'Package as a gem.'
18
+ task :package do
19
+ sh "gem build rack_datamapper.gemspec"
20
+ sh "mkdir -p pkg"
21
+ sh "mv rack-datamapper-*.gem pkg"
16
22
  end
17
23
 
18
24
  desc 'Install the package as a gem.'
@@ -6,11 +6,9 @@ module DataMapper
6
6
  end
7
7
 
8
8
  def call(env)
9
- status, headers, response = nil, nil, nil
10
9
  DataMapper.repository(@name) do
11
- status, headers, response = @app.call(env)
10
+ @app.call(env)
12
11
  end
13
- [status, headers, response]
14
12
  end
15
13
  end
16
14
  end
@@ -84,6 +84,7 @@ module DataMapper
84
84
  elsif session.save
85
85
  session.session_id
86
86
  else
87
+ warn session.errors.inspect if session.errors.size > 0
87
88
  false
88
89
  end
89
90
  ensure
@@ -101,16 +102,16 @@ module DataMapper
101
102
 
102
103
  property :session_id, String, :key => true
103
104
 
104
- property :data, Text, :nullable => false, :default => ::Base64.encode64(Marshal.dump({}))
105
+ property :raw_data, Text, :required => true, :default => ::Base64.encode64(Marshal.dump({})), :field => 'data'
105
106
 
106
- property :updated_at, DateTime, :nullable => true, :index => true
107
+ property :updated_at, DateTime, :required => false, :index => true
107
108
 
108
109
  def data=(data)
109
- attribute_set(:data, ::Base64.encode64(Marshal.dump(data)))
110
+ attribute_set(:raw_data, ::Base64.encode64(Marshal.dump(data)))
110
111
  end
111
112
 
112
113
  def data
113
- Marshal.load(::Base64.decode64(attribute_get(:data)))
114
+ Marshal.load(::Base64.decode64(attribute_get(:raw_data)))
114
115
  end
115
116
  end
116
117
  end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module DataMapper
3
- VERSION = '0.2.6'.freeze
3
+ VERSION = '0.3.2'.freeze
4
4
  end
5
5
  end
@@ -0,0 +1,143 @@
1
+ $LOAD_PATH << File.dirname(__FILE__)
2
+ require 'spec_helper'
3
+
4
+ describe DataMapper::Session::Abstract::Store do
5
+
6
+ describe 'without cache' do
7
+
8
+ def mock_session(stubs={})
9
+ @mock_session ||= mock(DataMapper::Session::Abstract::Session, stubs)
10
+ end
11
+
12
+ before :each do
13
+ @store = DataMapper::Session::Abstract::Store.new(nil,
14
+ {:cache => false},
15
+ Proc.new do
16
+ 1
17
+ end
18
+ )
19
+ end
20
+
21
+ it 'should get the session data' do
22
+ DataMapper::Session::Abstract::Session.stub!(:get).and_return(mock_session)
23
+ mock_session.should_receive(:data).and_return({:id => "id"})
24
+ @store.get_session({}, "sid").should == ["sid",{:id => "id"}]
25
+ end
26
+
27
+ it 'should create a new session' do
28
+ DataMapper::Session::Abstract::Session.should_receive(:create).and_return(mock_session)
29
+ mock_session.should_receive(:data).and_return({})
30
+ result = @store.get_session({}, nil)
31
+ result[0].should_not be_nil
32
+ result[1].should == {}
33
+ end
34
+
35
+ it 'should set the session data' do
36
+ DataMapper::Session::Abstract::Session.should_receive(:create).and_return(mock_session)
37
+ DataMapper::Session::Abstract::Session.should_receive(:get).twice.and_return(mock_session)
38
+ mock_session.should_receive(:data).and_return({})
39
+ mock_session.should_receive(:data=).with({:id => 432})
40
+ mock_session.should_receive(:save).and_return(true)
41
+ mock_session.should_receive(:data).and_return({:id => 123})
42
+
43
+ session_id = @store.get_session({}, nil)[0]
44
+ mock_session.should_receive(:session_id).and_return(session_id);
45
+ @store.set_session({}, session_id, {:id => 432}, {}).should == session_id
46
+ result = @store.get_session({}, session_id)
47
+
48
+ result[0].should_not be_nil
49
+ result[1].should == {:id => 123}
50
+ end
51
+
52
+ it 'should delete empty sessions' do
53
+ DataMapper::Session::Abstract::Session.should_receive(:create).and_return(mock_session)
54
+ DataMapper::Session::Abstract::Session.should_receive(:get).and_return(mock_session)
55
+ mock_session.should_receive(:data).and_return({})
56
+ mock_session.should_receive(:data=).with({})
57
+ mock_session.should_receive(:destroy).and_return(true)
58
+
59
+ session_id = @store.get_session({}, nil)[0]
60
+ @store.set_session({}, session_id, {}, {}).should be_false
61
+ end
62
+ end
63
+
64
+ describe 'with cache' do
65
+
66
+ def mock_session(stubs={})
67
+ @mock_session ||= mock(DataMapper::Session::Abstract::Session, stubs)
68
+ end
69
+
70
+ before :each do
71
+ @store = DataMapper::Session::Abstract::Store.new(nil,
72
+ {:cache => true},
73
+ Proc.new do
74
+ 1
75
+ end)
76
+ end
77
+
78
+ it 'should create a new session' do
79
+ DataMapper::Session::Abstract::Session.should_receive(:create).and_return(mock_session)
80
+ mock_session.should_receive(:data).and_return({})
81
+ result = @store.get_session({}, nil)
82
+ result[0].should_not be_nil
83
+ result[1].should == {}
84
+ end
85
+
86
+ it 'should get the session data from storage' do
87
+ DataMapper::Session::Abstract::Session.stub!(:get).and_return(mock_session)
88
+ mock_session.should_receive(:data).twice.and_return({:id => "id"})
89
+ @store.get_session({}, "sid").should == ["sid",{:id => "id"}]
90
+ # second get should use the cache
91
+ @store.get_session({}, "sid").should == ["sid",{:id => "id"}]
92
+ end
93
+
94
+ it 'should get the session data from cache' do
95
+ DataMapper::Session::Abstract::Session.should_receive(:create).and_return(mock_session)
96
+ mock_session.should_receive(:data).twice.and_return({})
97
+ session_id = @store.get_session({}, nil)[0]
98
+
99
+ result = @store.get_session({}, session_id)
100
+ result[0].should_not be_nil
101
+ result[1].should == {}
102
+ end
103
+
104
+ it 'should set the session data with empty cache' do
105
+ DataMapper::Session::Abstract::Session.should_receive(:get).and_return(mock_session)
106
+ mock_session.should_receive(:data=).with({:id => 432})
107
+ mock_session.should_receive(:save).and_return(true)
108
+ mock_session.should_receive(:session_id).and_return("sid")
109
+ mock_session.should_receive(:data).and_return({:id => 123})
110
+ @store.set_session({}, "sid", {:id => 432},{}).should == "sid"
111
+ result = @store.get_session({}, "sid")
112
+
113
+ result[0].should_not be_nil
114
+ result[1].should == {:id => 123}
115
+ end
116
+
117
+ it 'should set the session data' do
118
+ DataMapper::Session::Abstract::Session.should_receive(:create).and_return(mock_session)
119
+ mock_session.should_receive(:data).and_return({})
120
+ mock_session.should_receive(:data=).with({:id => 432})
121
+ mock_session.should_receive(:save).and_return(true)
122
+ mock_session.should_receive(:data).and_return({:id => 123})
123
+
124
+ session_id = @store.get_session({}, nil)[0]
125
+ mock_session.should_receive(:session_id).and_return(session_id);
126
+ @store.set_session({}, session_id, {:id => 432},{}).should == session_id
127
+ result = @store.get_session({}, session_id)
128
+
129
+ result[0].should_not be_nil
130
+ result[1].should == {:id => 123}
131
+ end
132
+
133
+ it 'should delete empty sessions' do
134
+ DataMapper::Session::Abstract::Session.should_receive(:create).and_return(mock_session)
135
+ mock_session.should_receive(:data).and_return({})
136
+ mock_session.should_receive(:data=).with({})
137
+ mock_session.should_receive(:destroy).and_return(true)
138
+
139
+ session_id = @store.get_session({}, nil)[0]
140
+ @store.set_session({}, session_id, {}, {}).should be_false
141
+ end
142
+ end
143
+ end
@@ -1,9 +1,10 @@
1
1
  require 'pathname'
2
2
  require 'rubygems'
3
- #gem 'dm-core', '0.9.10'
4
3
  $LOAD_PATH << Pathname(__FILE__).dirname.parent.expand_path + 'lib'
5
4
  require 'rack_datamapper'
6
5
  require 'dm-core/version'
6
+ require 'dm-migrations'
7
+ require 'dm-transactions'
7
8
  p DataMapper::VERSION
8
9
  def load_driver(name, default_uri)
9
10
  return false if ENV['ADAPTER'] != name.to_s
metadata CHANGED
@@ -1,92 +1,122 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-datamapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
- - mkristian
7
+ - mkristian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-06-15 00:00:00 +05:30
12
+ date: 2010-06-13 00:00:00 +05:30
13
13
  default_executable:
14
14
  dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: dm-core
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.9.10
24
- - - <
25
- - !ruby/object:Gem::Version
26
- version: 1.0.0
27
- version:
28
- - !ruby/object:Gem::Dependency
29
- name: hoe
30
- type: :development
31
- version_requirement:
32
- version_requirements: !ruby/object:Gem::Requirement
33
- requirements:
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: 2.3.3
37
- version:
15
+ - !ruby/object:Gem::Dependency
16
+ name: dm-core
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 1.0.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rack
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: "1.0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: dm-migrations
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.0
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: dm-transactions
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.0.0
54
+ version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: dm-sqlite-adapter
57
+ type: :development
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ~>
62
+ - !ruby/object:Gem::Version
63
+ version: 1.0.0
64
+ version:
65
+ - !ruby/object:Gem::Dependency
66
+ name: rspec
67
+ type: :development
68
+ version_requirement:
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ~>
72
+ - !ruby/object:Gem::Version
73
+ version: 1.3.0
74
+ version:
38
75
  description: this collection of plugins helps to add datamapper functionality to Rack. there is a IdentityMaps plugin which wrappes the request and with it all database actions are using that identity map. the transaction related plugin TransactionBoundaries and RestfulTransactions wrappes the request into a transaction. for using datamapper to store session data there is the DatamapperStore.
39
76
  email:
40
- - m.kristian@web.de
77
+ - m.kristian@web.de
41
78
  executables: []
42
79
 
43
80
  extensions: []
44
81
 
45
82
  extra_rdoc_files:
46
- - History.txt
47
- - Manifest.txt
48
- - README.txt
83
+ - History.txt
84
+ - README.txt
49
85
  files:
50
- - History.txt
51
- - Manifest.txt
52
- - README.txt
53
- - Rakefile
54
- - lib/rack-datamapper.rb
55
- - lib/rack_datamapper.rb
56
- - lib/softhashmap.jar
57
- - lib/rack_datamapper/identity_maps.rb
58
- - lib/rack_datamapper/restful_transactions.rb
59
- - lib/rack_datamapper/session/abstract/store.rb
60
- - lib/rack_datamapper/session/datamapper.rb
61
- - lib/rack_datamapper/transaction_boundaries.rb
62
- - lib/rack_datamapper/version.rb
63
- - spec/datamapper_session_spec.rb
64
- - spec/identity_maps_spec.rb
65
- - spec/restful_transactions_spec.rb
66
- - spec/spec.opts
67
- - spec/spec_helper.rb
68
- - spec/transaction_boundaries_spec.rb
86
+ - History.txt
87
+ - MIT-LICENSE
88
+ - README.txt
89
+ - Rakefile
90
+ - lib/softhashmap.jar
91
+ - lib/rack_datamapper.rb
92
+ - lib/rack-datamapper.rb
93
+ - lib/rack_datamapper/transaction_boundaries.rb
94
+ - lib/rack_datamapper/restful_transactions.rb
95
+ - lib/rack_datamapper/identity_maps.rb
96
+ - lib/rack_datamapper/version.rb
97
+ - lib/rack_datamapper/session/datamapper.rb
98
+ - lib/rack_datamapper/session/abstract/store.rb
69
99
  has_rdoc: true
70
100
  homepage: http://github.com/mkristian/rack_datamapper
71
101
  licenses: []
72
102
 
73
103
  post_install_message:
74
104
  rdoc_options:
75
- - --main
76
- - README.txt
105
+ - --main
106
+ - README.txt
77
107
  require_paths:
78
- - lib
108
+ - lib
79
109
  required_ruby_version: !ruby/object:Gem::Requirement
80
110
  requirements:
81
- - - ">="
82
- - !ruby/object:Gem::Version
83
- version: "0"
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: "0"
84
114
  version:
85
115
  required_rubygems_version: !ruby/object:Gem::Requirement
86
116
  requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: "0"
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: "0"
90
120
  version:
91
121
  requirements: []
92
122
 
@@ -95,5 +125,10 @@ rubygems_version: 1.3.5
95
125
  signing_key:
96
126
  specification_version: 3
97
127
  summary: this collection of plugins helps to add datamapper functionality to Rack
98
- test_files: []
99
-
128
+ test_files:
129
+ - spec/identity_maps_spec.rb
130
+ - spec/transaction_boundaries_spec.rb
131
+ - spec/spec_helper.rb
132
+ - spec/restful_transactions_spec.rb
133
+ - spec/datamapper_session_spec.rb
134
+ - spec/datamapper_store_spec.rb
@@ -1,19 +0,0 @@
1
- History.txt
2
- Manifest.txt
3
- README.txt
4
- Rakefile
5
- lib/rack-datamapper.rb
6
- lib/rack_datamapper.rb
7
- lib/softhashmap.jar
8
- lib/rack_datamapper/identity_maps.rb
9
- lib/rack_datamapper/restful_transactions.rb
10
- lib/rack_datamapper/session/abstract/store.rb
11
- lib/rack_datamapper/session/datamapper.rb
12
- lib/rack_datamapper/transaction_boundaries.rb
13
- lib/rack_datamapper/version.rb
14
- spec/datamapper_session_spec.rb
15
- spec/identity_maps_spec.rb
16
- spec/restful_transactions_spec.rb
17
- spec/spec.opts
18
- spec/spec_helper.rb
19
- spec/transaction_boundaries_spec.rb
@@ -1 +0,0 @@
1
- --colour