merb_datamapper 0.9.5 → 0.9.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +1 -0
- data/Rakefile +1 -1
- data/lib/generators/data_mapper_migration.rb +3 -3
- data/lib/generators/data_mapper_model.rb +3 -3
- data/lib/generators/data_mapper_resource_controller.rb +6 -6
- data/lib/generators/templates/views/edit.html.erb +4 -6
- data/lib/generators/templates/views/index.html.erb +0 -1
- data/lib/generators/templates/views/new.html.erb +4 -6
- data/lib/merb/orms/data_mapper/connection.rb +1 -4
- data/lib/merb/session/data_mapper_session.rb +48 -99
- data/lib/merb_datamapper.rb +33 -16
- data/lib/merb_datamapper/merbtasks.rb +7 -3
- data/lib/merb_datamapper/version.rb +1 -1
- data/spec/generators/spec_helper.rb +5 -4
- data/spec/session_store_spec.rb +125 -0
- data/spec/spec_helper.rb +2 -8
- metadata +7 -6
data/Manifest.txt
CHANGED
@@ -23,6 +23,7 @@ lib/merb_datamapper.rb
|
|
23
23
|
lib/merb_datamapper/merbtasks.rb
|
24
24
|
lib/merb_datamapper/version.rb
|
25
25
|
spec/connection_spec.rb
|
26
|
+
spec/session_store_spec.rb
|
26
27
|
spec/generators/data_mapper_migration_spec.rb
|
27
28
|
spec/generators/data_mapper_model_spec.rb
|
28
29
|
spec/generators/data_mapper_resource_controller_spec.rb
|
data/Rakefile
CHANGED
@@ -10,7 +10,7 @@ AUTHOR = "Jason Toy"
|
|
10
10
|
EMAIL = "jtoy@rubynow.com"
|
11
11
|
GEM_NAME = "merb_datamapper"
|
12
12
|
GEM_VERSION = DataMapper::MerbDataMapper::VERSION
|
13
|
-
GEM_DEPENDENCIES = [["dm-core", GEM_VERSION], ["dm-migrations", GEM_VERSION], ["merb-core", ">=0.9.
|
13
|
+
GEM_DEPENDENCIES = [["dm-core", GEM_VERSION], ["dm-migrations", GEM_VERSION], ["merb-core", ">=0.9.6"], ['templater', ">=0.2.0"]]
|
14
14
|
GEM_CLEAN = ["log", "pkg", "coverage"]
|
15
15
|
GEM_EXTRAS = { :has_rdoc => true, :extra_rdoc_files => %w[ README.txt LICENSE TODO ] }
|
16
16
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
Merb::Generators::MigrationGenerator.template :migration_datamapper, :orm => :datamapper do
|
2
|
-
source(File.dirname(__FILE__), 'templates/migration.rb')
|
3
|
-
destination
|
1
|
+
Merb::Generators::MigrationGenerator.template :migration_datamapper, :orm => :datamapper do |t|
|
2
|
+
t.source = File.join(File.dirname(__FILE__), 'templates/migration.rb')
|
3
|
+
t.destination = "#{destination_directory}/#{file_name}.rb"
|
4
4
|
end
|
@@ -9,7 +9,7 @@ class Merb::Generators::ModelGenerator
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
Merb::Generators::ModelGenerator.template :model_datamapper, :orm => :datamapper do
|
13
|
-
source(File.dirname(__FILE__), "templates", "model.rb")
|
14
|
-
destination("app/models", base_path, "#{file_name}.rb")
|
12
|
+
Merb::Generators::ModelGenerator.template :model_datamapper, :orm => :datamapper do |t|
|
13
|
+
t.source = File.join(File.dirname(__FILE__), "templates", "model.rb")
|
14
|
+
t.destination = File.join("app/models", base_path, "#{file_name}.rb")
|
15
15
|
end
|
@@ -11,15 +11,15 @@ class Merb::Generators::ResourceControllerGenerator
|
|
11
11
|
end
|
12
12
|
|
13
13
|
|
14
|
-
Merb::Generators::ResourceControllerGenerator.template :controller_datamapper, :orm => :datamapper do
|
15
|
-
source(File.dirname(__FILE__), "templates/resource_controller.rb")
|
16
|
-
destination("app/controllers", base_path, "#{file_name}.rb")
|
14
|
+
Merb::Generators::ResourceControllerGenerator.template :controller_datamapper, :orm => :datamapper do |t|
|
15
|
+
t.source = File.join(File.dirname(__FILE__), "templates/resource_controller.rb")
|
16
|
+
t.destination = File.join("app/controllers", base_path, "#{file_name}.rb")
|
17
17
|
end
|
18
18
|
|
19
19
|
[:index, :show, :edit, :new].each do |view|
|
20
20
|
Merb::Generators::ResourceControllerGenerator.template "view_#{view}_datamapper".to_sym,
|
21
|
-
:orm => :datamapper, :template_engine => :erb do
|
22
|
-
source(File.dirname(__FILE__), "templates/views/#{view}.html.erb")
|
23
|
-
destination("app/views", base_path, "#{file_name}/#{view}.html.erb")
|
21
|
+
:orm => :datamapper, :template_engine => :erb do |t|
|
22
|
+
t.source = File.join(File.dirname(__FILE__), "templates/views/#{view}.html.erb")
|
23
|
+
t.destination = File.join("app/views", base_path, "#{file_name}/#{view}.html.erb")
|
24
24
|
end
|
25
25
|
end
|
@@ -2,19 +2,17 @@
|
|
2
2
|
|
3
3
|
<p>Edit this file in <tt>app/views/<%= file_name %>/edit.html.erb</tt></p>
|
4
4
|
|
5
|
-
<%%=
|
6
|
-
|
7
|
-
<%% form_for(@<%= singular_model %>, :action => url(:<%= singular_model %>, @<%= singular_model %>)) do %>
|
5
|
+
<%%= form_for(@<%= singular_model %>, :action => url(:<%= singular_model %>, @<%= singular_model %>)) do %>
|
8
6
|
<% for property in properties.select{|p| !p.key?} -%>
|
9
7
|
<p>
|
10
|
-
<%%=
|
8
|
+
<%%= text_field :<%= property %>, :label => "<%= Extlib::Inflection.humanize(property) %>" %>
|
11
9
|
</p>
|
12
10
|
|
13
11
|
<% end -%>
|
14
12
|
<p>
|
15
|
-
<%%=
|
13
|
+
<%%= submit "Update" %>
|
16
14
|
</p>
|
17
|
-
<%% end
|
15
|
+
<%% end =%>
|
18
16
|
|
19
17
|
<%%= link_to 'Show', url(:<%= singular_model %>, @<%= singular_model %>) %> |
|
20
18
|
<%%= link_to 'Back', url(:<%= plural_model %>) %>
|
@@ -16,7 +16,6 @@
|
|
16
16
|
<% end -%>
|
17
17
|
<td><%%= link_to 'Show', url(:<%= singular_model %>, <%= singular_model %>) %></td>
|
18
18
|
<td><%%= link_to 'Edit', url(:edit_<%= singular_model %>, <%= singular_model %>) %></td>
|
19
|
-
<td><%%= delete_button :<%= singular_model %>, <%= singular_model %> %></td>
|
20
19
|
</tr>
|
21
20
|
<%% end %>
|
22
21
|
</table>
|
@@ -2,18 +2,16 @@
|
|
2
2
|
|
3
3
|
<p>Edit this file in <tt>app/views/<%= file_name %>/new.html.erb</tt></p>
|
4
4
|
|
5
|
-
<%%=
|
6
|
-
|
7
|
-
<%% form_for(@<%= singular_model %>, :action => url(:<%= plural_model %>) ) do |f| %>
|
5
|
+
<%%= form_for(@<%= singular_model %>, :action => url(:<%= plural_model %>) ) do %>
|
8
6
|
<% for property in properties.select{|p| !p.key?} -%>
|
9
7
|
<p>
|
10
|
-
<%%=
|
8
|
+
<%%= text_field :<%= property %>, :label => "<%= Extlib::Inflection.humanize(property) %>" %>
|
11
9
|
</p>
|
12
10
|
|
13
11
|
<% end -%>
|
14
12
|
<p>
|
15
|
-
<%%=
|
13
|
+
<%%= submit "Create" %>
|
16
14
|
</p>
|
17
|
-
<%% end
|
15
|
+
<%% end =%>
|
18
16
|
|
19
17
|
<%%= link_to 'Back', url(:<%= plural_model %>) %>
|
@@ -17,10 +17,7 @@ module Merb
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def config
|
20
|
-
|
21
|
-
Merb::Plugins.config[:merb_datamapper] = get_config_for_environment
|
22
|
-
end
|
23
|
-
@config ||= Merb::Plugins.config[:merb_datamapper] ||= get_config_for_environment
|
20
|
+
@config ||= Merb::Plugins.config[:merb_datamapper][:connection] ||= (get_config_for_environment)
|
24
21
|
end
|
25
22
|
|
26
23
|
# Database connects as soon as the gem is loaded
|
@@ -1,119 +1,68 @@
|
|
1
1
|
begin
|
2
|
-
gem 'dm-core', '=0.9.
|
2
|
+
gem 'dm-core', '=0.9.6'
|
3
3
|
require 'dm-core'
|
4
4
|
rescue LoadError => e
|
5
5
|
require 'data_mapper'
|
6
6
|
end
|
7
7
|
|
8
|
-
require '
|
9
|
-
module Merb
|
10
|
-
module SessionMixin
|
11
|
-
def setup_session
|
12
|
-
before_value = cookies[_session_id_key]
|
13
|
-
request.session, cookies[_session_id_key] = Merb::DataMapperSession.persist(cookies[_session_id_key])
|
14
|
-
@_fingerprint = Marshal.dump(request.session.data).hash
|
15
|
-
@_new_cookie = cookies[_session_id_key] != before_value
|
16
|
-
end
|
17
|
-
|
18
|
-
def finalize_session
|
19
|
-
request.session.save if @_fingerprint != Marshal.dump(request.session.data).hash
|
20
|
-
set_cookie(_session_id_key, request.session.session_id, Time.now + _session_expiry) if (@_new_cookie || request.session.needs_new_cookie)
|
21
|
-
end
|
22
|
-
|
23
|
-
def session_store_type
|
24
|
-
"datamapper"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
table_name = (Merb::Plugins.config[:merb_datamapper][:session_table_name] || "sessions")
|
8
|
+
require 'merb-core/dispatch/session'
|
29
9
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
# If none is found, generates a new session.
|
51
|
-
def persist(session_id)
|
52
|
-
if !session_id.blank?
|
53
|
-
session = self.first :session_id => session_id
|
54
|
-
end
|
55
|
-
unless session
|
56
|
-
session = generate
|
57
|
-
end
|
58
|
-
[session, session.session_id]
|
10
|
+
module Merb
|
11
|
+
class DataMapperSessionStore
|
12
|
+
include ::DataMapper::Resource
|
13
|
+
|
14
|
+
table_name = Merb::Plugins.config[:merb_datamapper][:session_storage_name] || 'sessions'
|
15
|
+
storage_names[default_repository_name] = table_name
|
16
|
+
|
17
|
+
property :session_id, String, :size => 32, :nullable => false, :key => true
|
18
|
+
property :data, Object, :default => {}, :lazy => false
|
19
|
+
property :created_at, DateTime, :default => Proc.new { |r, p| DateTime.now }
|
20
|
+
|
21
|
+
##
|
22
|
+
# Retrieves a session from the session store
|
23
|
+
#
|
24
|
+
# @param session_id<String> The session_id to retrieve the session for
|
25
|
+
#
|
26
|
+
# @returns <nil, DataMapperSessionStore> The session corresponding to the id, or nil
|
27
|
+
def self.retrieve_session(session_id)
|
28
|
+
if session = get(session_id)
|
29
|
+
session.data
|
59
30
|
end
|
60
|
-
|
61
|
-
def marshal(data) Base64.encode64(Marshal.dump(data)) if data end
|
62
|
-
def unmarshal(data) Marshal.load(Base64.decode64(data)) if data end
|
63
|
-
end
|
64
|
-
|
65
|
-
# Regenerate the Session ID
|
66
|
-
def regenerate
|
67
|
-
self.session_id = Merb::SessionMixin::rand_uuid
|
68
|
-
self.needs_new_cookie = true
|
69
|
-
self.save
|
70
|
-
end
|
71
|
-
|
72
|
-
# Recreates the cookie with the default expiration time
|
73
|
-
# Useful during log in for pushing back the expiration date
|
74
|
-
def refresh_expiration
|
75
|
-
self.needs_new_cookie = true
|
76
|
-
end
|
77
|
-
|
78
|
-
# Lazy-delete of session data
|
79
|
-
def delete(key = nil)
|
80
|
-
key ? self.data.delete(key) : self.data.clear
|
81
|
-
end
|
82
|
-
|
83
|
-
def empty?
|
84
|
-
data.empty?
|
85
|
-
end
|
86
|
-
|
87
|
-
def each(&b)
|
88
|
-
data.each(&b)
|
89
|
-
end
|
90
|
-
|
91
|
-
def each_with_index(&b)
|
92
|
-
data.each_with_index(&b)
|
93
|
-
end
|
94
|
-
|
95
|
-
def [](key)
|
96
|
-
data[key]
|
97
31
|
end
|
98
32
|
|
99
|
-
|
100
|
-
|
33
|
+
##
|
34
|
+
# Stores the data in a session with the given session_id, creating it if
|
35
|
+
# required
|
36
|
+
#
|
37
|
+
# @param session_id<String> The session_id to find the session by, or the id of the new session
|
38
|
+
# @param data<Object> The data to be stored in the session. Probably a hash
|
39
|
+
def self.store_session(session_id, data)
|
40
|
+
if session = get(session_id)
|
41
|
+
session.update_attributes(:data => data)
|
42
|
+
else
|
43
|
+
create(:session_id => session_id, :data => data)
|
44
|
+
end
|
101
45
|
end
|
102
46
|
|
103
|
-
|
104
|
-
|
47
|
+
##
|
48
|
+
# Deletes a session with the given id
|
49
|
+
#
|
50
|
+
# @param session_id<String> The session to destroy
|
51
|
+
def self.delete_session(session_id)
|
52
|
+
all(:session_id => session_id).destroy!
|
105
53
|
end
|
106
54
|
|
107
|
-
def
|
108
|
-
|
55
|
+
def self.default_repository_name
|
56
|
+
Merb::Plugins.config[:merb_datamapper][:session_repository_name] || :default
|
109
57
|
end
|
58
|
+
end
|
110
59
|
|
111
|
-
|
60
|
+
class DataMapperSession < SessionStoreContainer
|
112
61
|
|
113
|
-
|
62
|
+
# The session store type
|
63
|
+
self.session_store_type = :datamapper
|
114
64
|
|
115
|
-
|
116
|
-
|
117
|
-
end
|
65
|
+
# The store object is the model class itself
|
66
|
+
self.store = DataMapperSessionStore
|
118
67
|
end
|
119
68
|
end
|
data/lib/merb_datamapper.rb
CHANGED
@@ -1,24 +1,41 @@
|
|
1
1
|
if defined?(Merb::Plugins)
|
2
|
-
|
3
|
-
require 'merb_datamapper/version'
|
2
|
+
dependency 'dm-core'
|
4
3
|
|
5
|
-
|
6
|
-
|
4
|
+
require File.dirname(__FILE__) / "merb" / "orms" / "data_mapper" / "connection"
|
5
|
+
Merb::Plugins.add_rakefiles "merb_datamapper" / "merbtasks"
|
7
6
|
|
8
|
-
|
9
|
-
|
7
|
+
class Merb::Orms::DataMapper::Connect < Merb::BootLoader
|
8
|
+
after BeforeAppLoads
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
else
|
14
|
-
Merb.logger.info "No database.yml file found in #{Merb.dir_for(:config)}, assuming database connection(s) established in the environment file in #{Merb.dir_for(:config)}/environments"
|
15
|
-
end
|
10
|
+
def self.run
|
11
|
+
Merb.logger.debug "Merb::Orms::DataMapper::Connect block."
|
16
12
|
|
17
|
-
|
13
|
+
# check for the presence of database.yml
|
14
|
+
if File.file?(Merb.dir_for(:config) / "database.yml")
|
15
|
+
# if we have it, connect
|
16
|
+
Merb::Orms::DataMapper.connect
|
17
|
+
else
|
18
|
+
# assume we'll be told at some point
|
19
|
+
Merb.logger.info "No database.yml file found in #{Merb.dir_for(:config)}, assuming database connection(s) established in the environment file in #{Merb.dir_for(:config)}/environments"
|
20
|
+
end
|
21
|
+
|
22
|
+
# if we use a datamapper session store, require it.
|
23
|
+
Merb.logger.debug "Checking if we need to use DataMapper sessions"
|
24
|
+
if Merb::Config.session_stores.include?(:datamapper)
|
25
|
+
Merb.logger.debug "Using DataMapper sessions"
|
26
|
+
require File.dirname(__FILE__) / "merb" / "session" / "data_mapper_session"
|
27
|
+
end
|
28
|
+
|
29
|
+
# required to provide 'to_param'
|
30
|
+
require File.dirname(__FILE__) / "merb" / "orms" / "data_mapper" / "resource"
|
31
|
+
|
32
|
+
Merb.logger.debug "Merb::Orms::DataMapper::Connect complete"
|
33
|
+
end
|
34
|
+
end
|
18
35
|
|
19
|
-
Merb::Plugins.add_rakefiles "merb_datamapper" / "merbtasks"
|
20
36
|
|
21
|
-
|
22
|
-
Merb.add_generators
|
23
|
-
Merb.add_generators
|
37
|
+
generators = File.join(File.dirname(__FILE__), 'generators')
|
38
|
+
Merb.add_generators generators / 'data_mapper_model'
|
39
|
+
Merb.add_generators generators / 'data_mapper_resource_controller'
|
40
|
+
Merb.add_generators generators / 'data_mapper_migration'
|
24
41
|
end
|
@@ -48,15 +48,19 @@ namespace :dm do
|
|
48
48
|
desc "Migrate the database to the latest version"
|
49
49
|
task :migrate => 'dm:db:migrate:up'
|
50
50
|
|
51
|
-
desc "Create the database
|
51
|
+
desc "Create the database"
|
52
52
|
task :create do
|
53
53
|
config = Merb::Orms::DataMapper.config
|
54
54
|
puts "Creating database '#{config[:database]}'"
|
55
55
|
case config[:adapter]
|
56
56
|
when 'postgres'
|
57
57
|
`createdb -U #{config[:username]} #{config[:database]}`
|
58
|
+
when 'mysql'
|
59
|
+
`mysqladmin -u #{config[:username]} #{config[:password] ? "-p'#{config[:password]}'" : ''} create #{config[:database]}`
|
60
|
+
when 'sqlite3'
|
61
|
+
Rake::Task['rake:dm:db:automigrate'].invoke
|
58
62
|
else
|
59
|
-
raise "Adapter #{config[:adapter]} not supported yet."
|
63
|
+
raise "Adapter #{config[:adapter]} not supported for creating databases yet."
|
60
64
|
end
|
61
65
|
end
|
62
66
|
|
@@ -68,7 +72,7 @@ namespace :dm do
|
|
68
72
|
when 'postgres'
|
69
73
|
`dropdb -U #{config[:username]} #{config[:database]}`
|
70
74
|
else
|
71
|
-
raise "Adapter #{config[:adapter]} not supported yet
|
75
|
+
raise "Adapter #{config[:adapter]} not supported for dropping databases yet.\ntry dm:db:automigrate"
|
72
76
|
end
|
73
77
|
end
|
74
78
|
|
@@ -1,9 +1,10 @@
|
|
1
|
+
# require our other spec helpers
|
2
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
3
|
+
|
1
4
|
# require merb-gen and the spec helpers
|
2
5
|
require 'merb-gen'
|
3
|
-
require '
|
6
|
+
require 'templater/spec/helpers'
|
4
7
|
|
5
|
-
# require our other spec helpers
|
6
|
-
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
7
8
|
|
8
9
|
# require the generators
|
9
10
|
require 'generators/data_mapper_migration'
|
@@ -12,7 +13,7 @@ require 'generators/data_mapper_resource_controller'
|
|
12
13
|
|
13
14
|
# include the helpers
|
14
15
|
Spec::Runner.configure do |config|
|
15
|
-
config.include
|
16
|
+
config.include Templater::Spec::Helpers
|
16
17
|
end
|
17
18
|
|
18
19
|
# copied from merb-more/merb-gen/spec/spec_helpers.rb
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
require 'merb/session/data_mapper_session'
|
4
|
+
describe Merb::DataMapperSessionStore do
|
5
|
+
before(:all) do
|
6
|
+
DataMapper.setup(:default, "sqlite3::memory:")
|
7
|
+
end
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
Merb::Plugins.config[:merb_datamapper] = {}
|
11
|
+
@session_container = Merb::DataMapperSessionStore
|
12
|
+
@session_container.auto_migrate!
|
13
|
+
@sess_id = 'a'*32
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
describe "#retrieve_session" do
|
18
|
+
it "responds to retrieve_session" do
|
19
|
+
@session_container.should respond_to(:retrieve_session)
|
20
|
+
end
|
21
|
+
it "returns the data when given an existing session id" do
|
22
|
+
@session_container.create(:session_id => @sess_id, :data => {:foo => 'bar'})
|
23
|
+
session_data = @session_container.retrieve_session(@sess_id)
|
24
|
+
session_data.should_not be_nil
|
25
|
+
session_data[:foo].should == 'bar'
|
26
|
+
end
|
27
|
+
it "returns nil when a non-existent session_id is used" do
|
28
|
+
@session_container.retrieve_session(@sess_id).should be_nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
describe "#store_session" do
|
34
|
+
it "responds to store_session" do
|
35
|
+
@session_container.should respond_to(:store_session)
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "when a session_id doesn't exist" do
|
39
|
+
it "creates a new record" do
|
40
|
+
@session_container.all.should be_empty
|
41
|
+
@session_container.store_session(@sess_id, {:foo => 'bar'})
|
42
|
+
@session_container.all.should_not be_empty
|
43
|
+
end
|
44
|
+
|
45
|
+
it "saves the data" do
|
46
|
+
@session_container.store_session(@sess_id, {:foo => 'bar'})
|
47
|
+
session_data = @session_container.retrieve_session(@sess_id)
|
48
|
+
session_data.should_not be_nil
|
49
|
+
session_data[:foo].should == 'bar'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "when a session_id does exist" do
|
54
|
+
before(:each) do
|
55
|
+
@session_container.store_session(@sess_id, {:foo => 'bar'})
|
56
|
+
end
|
57
|
+
|
58
|
+
it "doesn't create a new session" do
|
59
|
+
@session_container.all.size.should == 1
|
60
|
+
@session_container.store_session(@sess_id, {:foo => 'FOOOO'})
|
61
|
+
@session_container.all.size.should == 1
|
62
|
+
end
|
63
|
+
|
64
|
+
it "saves the data" do
|
65
|
+
@session_container.store_session(@sess_id, {:foo => 'FOOOO'})
|
66
|
+
session_data = @session_container.retrieve_session(@sess_id)
|
67
|
+
session_data.should_not be_nil
|
68
|
+
session_data[:foo].should == 'FOOOO'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
describe "#delete_session" do
|
75
|
+
before(:each) do
|
76
|
+
@session_container.store_session(@sess_id, {:foo => 'bar'})
|
77
|
+
end
|
78
|
+
|
79
|
+
it "responds to #delete_session" do
|
80
|
+
@session_container.should respond_to(:delete_session)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "destroys an existing session" do
|
84
|
+
@session_container.all.size.should == 1
|
85
|
+
@session_container.delete_session(@sess_id)
|
86
|
+
@session_container.all.size.should == 0
|
87
|
+
end
|
88
|
+
|
89
|
+
it "doesn't destroy a session when the key doesn't match" do
|
90
|
+
@session_container.all.size.should == 1
|
91
|
+
@session_container.delete_session('b'*32)
|
92
|
+
@session_container.all.size.should == 1
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
describe "configuration options" do
|
97
|
+
before(:each) do
|
98
|
+
@session_container = Merb::DataMapperSessionStore
|
99
|
+
end
|
100
|
+
after(:each) do
|
101
|
+
Merb::Plugins.config[:merb_datamapper].clear
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "repository" do
|
105
|
+
it "uses the :default repository when no options are set" do
|
106
|
+
@session_container.default_repository_name.should == :default
|
107
|
+
end
|
108
|
+
it "uses the set name when provided" do
|
109
|
+
Merb::Plugins.config[:merb_datamapper][:session_repository_name] = :other
|
110
|
+
@session_container.default_repository_name.should == :other
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
describe "table name" do
|
116
|
+
it "uses the 'sessions' when no options are set" do
|
117
|
+
@session_container.storage_names[:default].should == 'sessions'
|
118
|
+
end
|
119
|
+
it "uses the set table name when it is set" do
|
120
|
+
pending "this should work but doesn't"
|
121
|
+
Merb::Plugins.config[:merb_datamapper][:session_storage_name] = 'foos'
|
122
|
+
@session_container.storage_names[:default].should == 'foos'
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,13 +3,7 @@ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
|
|
3
3
|
|
4
4
|
require 'rubygems'
|
5
5
|
|
6
|
-
gem 'dm-core', '=0.9.
|
6
|
+
gem 'dm-core', '=0.9.6'
|
7
7
|
require 'dm-core'
|
8
|
+
require 'merb-core'
|
8
9
|
|
9
|
-
module Merb
|
10
|
-
module Plugins
|
11
|
-
def self.config
|
12
|
-
@config ||= {}
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: merb_datamapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Toy
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-09-09 00:00:00 +03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - "="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.9.
|
23
|
+
version: 0.9.6
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: dm-migrations
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.9.
|
33
|
+
version: 0.9.6
|
34
34
|
version:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: merb-core
|
@@ -40,7 +40,7 @@ dependencies:
|
|
40
40
|
requirements:
|
41
41
|
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: 0.9.
|
43
|
+
version: 0.9.6
|
44
44
|
version:
|
45
45
|
- !ruby/object:Gem::Dependency
|
46
46
|
name: templater
|
@@ -50,7 +50,7 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: 0.
|
53
|
+
version: 0.2.0
|
54
54
|
version:
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: hoe
|
@@ -99,6 +99,7 @@ files:
|
|
99
99
|
- lib/merb_datamapper/merbtasks.rb
|
100
100
|
- lib/merb_datamapper/version.rb
|
101
101
|
- spec/connection_spec.rb
|
102
|
+
- spec/session_store_spec.rb
|
102
103
|
- spec/generators/data_mapper_migration_spec.rb
|
103
104
|
- spec/generators/data_mapper_model_spec.rb
|
104
105
|
- spec/generators/data_mapper_resource_controller_spec.rb
|