merb_datamapper 1.0.15 → 1.1.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/README +40 -0
- data/Rakefile +48 -70
- data/lib/generators/templates/resource_controller.rb +3 -2
- data/lib/{merb/orms/data_mapper → merb_datamapper}/connection.rb +0 -0
- data/lib/{merb/session → merb_datamapper}/data_mapper_session.rb +2 -2
- data/lib/{merb/orms/data_mapper → merb_datamapper}/database.yml.sample +0 -0
- data/lib/merb_datamapper/merbtasks.rb +8 -4
- data/lib/merb_datamapper/version.rb +4 -3
- data/lib/merb_datamapper.rb +15 -5
- data/spec/connection_spec.rb +67 -0
- data/spec/datamapper_id_map_controller.rb +10 -0
- data/spec/datamapper_model.rb +6 -0
- data/spec/datamapper_session_controller.rb +9 -0
- data/spec/identity_map_spec.rb +10 -0
- data/spec/session_spec.rb +23 -0
- data/spec/session_store_spec.rb +124 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +44 -0
- metadata +49 -21
data/README
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
= merb_datamapper
|
2
|
+
|
3
|
+
A plugin for the Merb framework that provides DataMapper access
|
4
|
+
|
5
|
+
== Features
|
6
|
+
|
7
|
+
* Automatic connection to a data-store through DataMapper, via database.yml
|
8
|
+
* Easy use of multiple repositories.
|
9
|
+
* Generators for models, controllers and migrations.
|
10
|
+
* Sessions stored in a data-store managed by DataMapper
|
11
|
+
* wraps actions in DataMapper repository blocks, to enable the IdentityMap
|
12
|
+
|
13
|
+
=== Sessions
|
14
|
+
|
15
|
+
To use sessions:
|
16
|
+
|
17
|
+
1. set the session store to datamapper in init.rb:
|
18
|
+
Merb::Config.use { |c|
|
19
|
+
c[:session_store] = 'datamapper'
|
20
|
+
}
|
21
|
+
|
22
|
+
2. add the dependency in init.rb:
|
23
|
+
use_orm :datamapper
|
24
|
+
|
25
|
+
Sessions can be configured by a few plugin options:
|
26
|
+
|
27
|
+
[:session_storage_name] The name of the table to use to store the sessions (defaults to 'session')
|
28
|
+
[:session_repository_name] The repository to use for sessions. (defaults to <tt>:default</tt>)
|
29
|
+
|
30
|
+
=== Repository Blocks
|
31
|
+
|
32
|
+
Repository Blocks are a DataMapper feature, which enables the use of the
|
33
|
+
DataMapper IdentityMap, which can help with certain DataMapper features such as
|
34
|
+
strategic eager loading. Read on http://www.datamapper.org for more information
|
35
|
+
on these features.
|
36
|
+
|
37
|
+
If, for whatever reason, it doesn't suit you, it can be disabled via setting the
|
38
|
+
<tt>:use_reposity_block</tt> option to <tt>false</tt>.
|
39
|
+
|
40
|
+
Merb::Plugins[:merb_datamapper][:use_reposity_block] = false
|
data/Rakefile
CHANGED
@@ -1,80 +1,58 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
##############################################################################
|
4
|
-
# Package && release
|
5
|
-
##############################################################################
|
6
|
-
RUBY_FORGE_PROJECT = "merb"
|
7
|
-
PROJECT_URL = "http://merbivore.com"
|
8
|
-
PROJECT_SUMMARY = "DataMapper plugin providing DataMapper support for Merb"
|
9
|
-
PROJECT_DESCRIPTION = PROJECT_SUMMARY
|
10
|
-
|
11
|
-
GEM_AUTHOR = "Jason Toy"
|
12
|
-
GEM_EMAIL = "jtoy@rubynow.com"
|
13
|
-
|
14
|
-
GEM_NAME = "merb_datamapper"
|
15
|
-
PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
|
16
|
-
GEM_VERSION = Merb::VERSION + PKG_BUILD
|
17
|
-
|
18
|
-
RELEASE_NAME = "REL #{GEM_VERSION}"
|
19
|
-
|
20
|
-
GEM_DEPENDENCIES = [
|
21
|
-
["dm-core", "~> #{Merb::DM_VERSION}"],
|
22
|
-
["dm-migrations", "~> #{Merb::DM_VERSION}"],
|
23
|
-
["merb-core", "~> #{GEM_VERSION}"]
|
24
|
-
]
|
25
|
-
|
26
|
-
require "extlib/tasks/release"
|
27
|
-
|
28
|
-
spec = Gem::Specification.new do |s|
|
29
|
-
s.rubyforge_project = RUBY_FORGE_PROJECT
|
30
|
-
s.name = GEM_NAME
|
31
|
-
s.version = GEM_VERSION
|
32
|
-
s.platform = Gem::Platform::RUBY
|
33
|
-
s.has_rdoc = true
|
34
|
-
s.extra_rdoc_files = ["LICENSE", 'TODO']
|
35
|
-
s.summary = PROJECT_SUMMARY
|
36
|
-
s.description = PROJECT_DESCRIPTION
|
37
|
-
s.author = GEM_AUTHOR
|
38
|
-
s.email = GEM_EMAIL
|
39
|
-
s.homepage = PROJECT_URL
|
40
|
-
GEM_DEPENDENCIES.each do |gem, version|
|
41
|
-
s.add_dependency gem, version
|
42
|
-
end
|
43
|
-
s.require_path = 'lib'
|
44
|
-
s.files = %w(LICENSE Rakefile TODO Generators) + Dir.glob("{lib}/**/*")
|
45
|
-
end
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
46
3
|
|
47
|
-
|
48
|
-
|
49
|
-
end
|
4
|
+
# Assume a typical dev checkout to fetch the current merb-core version
|
5
|
+
require File.expand_path('../../merb/merb-core/lib/merb-core/version', __FILE__)
|
50
6
|
|
51
|
-
|
52
|
-
|
53
|
-
Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
|
54
|
-
end
|
7
|
+
# Load this library's version information
|
8
|
+
require File.expand_path('../lib/merb_datamapper/version', __FILE__)
|
55
9
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
10
|
+
begin
|
11
|
+
|
12
|
+
gem 'jeweler', '~> 1.4'
|
13
|
+
require 'jeweler'
|
14
|
+
|
15
|
+
Jeweler::Tasks.new do |gemspec|
|
16
|
+
|
17
|
+
gemspec.version = Merb::DataMapper::VERSION
|
18
|
+
|
19
|
+
gemspec.name = "merb_datamapper"
|
20
|
+
gemspec.description = "Merb plugin that provides support for datamapper"
|
21
|
+
gemspec.summary = "Merb plugin that allows you to use datamapper with your merb app"
|
22
|
+
|
23
|
+
gemspec.authors = [ "Jason Toy" ]
|
24
|
+
gemspec.email = "jtoy@rubynow.com"
|
25
|
+
gemspec.homepage = "http://github.com/merb/merb_datamapper"
|
26
|
+
|
27
|
+
gemspec.files = %w(Generators LICENSE Rakefile README TODO) + Dir['{lib,spec}/**/*']
|
28
|
+
|
29
|
+
# Runtime dependencies
|
30
|
+
gemspec.add_dependency 'merb-core', "= #{Merb::VERSION}"
|
31
|
+
gemspec.add_dependency 'dm-core', Merb::DataMapper::DM_VERSION_REQUIREMENT
|
32
|
+
gemspec.add_dependency 'dm-migrations', Merb::DataMapper::DM_VERSION_REQUIREMENT
|
33
|
+
|
34
|
+
# Development dependencies
|
35
|
+
gemspec.add_development_dependency 'rspec', '>= 1.2.9'
|
60
36
|
|
61
|
-
desc "Create a gemspec file"
|
62
|
-
task :gemspec do
|
63
|
-
File.open("#{GEM_NAME}.gemspec", "w") do |file|
|
64
|
-
file.puts spec.to_ruby
|
65
37
|
end
|
38
|
+
|
39
|
+
Jeweler::GemcutterTasks.new
|
40
|
+
|
41
|
+
rescue LoadError
|
42
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
66
43
|
end
|
67
44
|
|
68
|
-
|
69
|
-
Spec::Rake::SpecTask.new(
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
45
|
+
require 'spec/rake/spectask'
|
46
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
47
|
+
spec.spec_opts << '--options' << 'spec/spec.opts' if File.exists?('spec/spec.opts')
|
48
|
+
spec.libs << 'lib' << 'spec'
|
49
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
50
|
+
end
|
51
|
+
|
52
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
53
|
+
spec.libs << 'lib' << 'spec'
|
54
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
55
|
+
spec.rcov = true
|
78
56
|
end
|
79
57
|
|
80
58
|
desc 'Default: run spec examples'
|
@@ -40,8 +40,9 @@ class <%= class_name %> < Application
|
|
40
40
|
@<%= singular_model %> = <%= model_class_name %>.get(id)
|
41
41
|
raise NotFound unless @<%= singular_model %>
|
42
42
|
if @<%= singular_model %>.update(<%= singular_model %>)
|
43
|
-
redirect resource(@<%= singular_model %>)
|
43
|
+
redirect resource(@<%= singular_model %>), :message => {:notice => "<%= model_class_name %> was successfully updated"}
|
44
44
|
else
|
45
|
+
message[:error] = "<%= model_class_name %> failed to be updated"
|
45
46
|
display @<%= singular_model %>, :edit
|
46
47
|
end
|
47
48
|
end
|
@@ -50,7 +51,7 @@ class <%= class_name %> < Application
|
|
50
51
|
@<%= singular_model %> = <%= model_class_name %>.get(id)
|
51
52
|
raise NotFound unless @<%= singular_model %>
|
52
53
|
if @<%= singular_model %>.destroy
|
53
|
-
redirect resource(:<%= plural_model %>)
|
54
|
+
redirect resource(:<%= plural_model %>), :message => {:notice => "<%= model_class_name %> was successfully deleted"}
|
54
55
|
else
|
55
56
|
raise InternalServerError
|
56
57
|
end
|
File without changes
|
@@ -7,10 +7,10 @@ module Merb
|
|
7
7
|
def self.default_repository_name
|
8
8
|
Merb::Plugins.config[:merb_datamapper][:session_repository_name]
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
storage_names[default_repository_name] = Merb::Plugins.config[:merb_datamapper][:session_storage_name]
|
12
12
|
|
13
|
-
property :session_id, String, :length => 32, :
|
13
|
+
property :session_id, String, :length => 32, :required => true, :key => true
|
14
14
|
property :data, Object, :default => {}, :lazy => false
|
15
15
|
property :created_at, DateTime, :default => Proc.new { |r, p| DateTime.now }
|
16
16
|
|
File without changes
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'fileutils'
|
2
|
-
require '
|
2
|
+
require 'merb_datamapper/connection'
|
3
3
|
|
4
4
|
namespace :db do
|
5
5
|
|
@@ -10,7 +10,7 @@ namespace :db do
|
|
10
10
|
|
11
11
|
desc "Create a sample database.yml file"
|
12
12
|
task :database_yaml => :merb_env do
|
13
|
-
sample_location = File.
|
13
|
+
sample_location = File.expand_path('../database.yml.sample', __FILE__)
|
14
14
|
target_location = Merb.dir_for(:config)
|
15
15
|
FileUtils.cp sample_location, target_location
|
16
16
|
end
|
@@ -54,7 +54,8 @@ namespace :db do
|
|
54
54
|
when 'postgres'
|
55
55
|
`createdb -U #{config[:username]} #{config[:database]}`
|
56
56
|
when 'mysql'
|
57
|
-
|
57
|
+
user, password, database = config[:username], config[:password], config[:database]
|
58
|
+
`mysql -u #{user} #{password ? "-p #{password}" : ''} -e "create database #{database}"`
|
58
59
|
when 'sqlite3'
|
59
60
|
Rake::Task['rake:db:automigrate'].invoke
|
60
61
|
else
|
@@ -62,13 +63,16 @@ namespace :db do
|
|
62
63
|
end
|
63
64
|
end
|
64
65
|
|
65
|
-
desc "Drop the database (postgres only)"
|
66
|
+
desc "Drop the database (postgres and mysql only)"
|
66
67
|
task :drop do
|
67
68
|
config = Merb::Orms::DataMapper.config
|
68
69
|
puts "Dropping database '#{config[:database]}'"
|
69
70
|
case config[:adapter]
|
70
71
|
when 'postgres'
|
71
72
|
`dropdb -U #{config[:username]} #{config[:database]}`
|
73
|
+
when 'mysql'
|
74
|
+
user, password, database = config[:username], config[:password], config[:database]
|
75
|
+
`mysql -u #{user} #{password ? "-p #{password}" : ''} -e "drop database #{database}"`
|
72
76
|
else
|
73
77
|
raise "Adapter #{config[:adapter]} not supported for dropping databases yet.\ntry db:automigrate"
|
74
78
|
end
|
data/lib/merb_datamapper.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
if defined?(Merb::Plugins)
|
2
|
+
|
2
3
|
require 'dm-core'
|
4
|
+
require 'merb_datamapper/connection'
|
3
5
|
|
4
|
-
require File.dirname(__FILE__) / "merb" / "orms" / "data_mapper" / "connection"
|
5
6
|
Merb::Plugins.add_rakefiles "merb_datamapper" / "merbtasks"
|
6
7
|
|
7
8
|
# conditionally assign things, so as not to override previously set options.
|
@@ -18,6 +19,14 @@ if defined?(Merb::Plugins)
|
|
18
19
|
Merb::Plugins.config[:merb_datamapper][:session_repository_name] = :default
|
19
20
|
end
|
20
21
|
|
22
|
+
module DataMapper
|
23
|
+
module Resource
|
24
|
+
|
25
|
+
# actionorm compliance
|
26
|
+
alias new_record? new?
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
21
30
|
|
22
31
|
class Merb::Orms::DataMapper::Connect < Merb::BootLoader
|
23
32
|
after BeforeAppLoads
|
@@ -38,7 +47,7 @@ if defined?(Merb::Plugins)
|
|
38
47
|
Merb.logger.verbose! "Checking if we need to use DataMapper sessions"
|
39
48
|
if Merb::Config.session_store == 'datamapper'
|
40
49
|
Merb.logger.verbose! "Using DataMapper sessions"
|
41
|
-
require
|
50
|
+
require 'merb_datamapper/data_mapper_session'
|
42
51
|
end
|
43
52
|
|
44
53
|
# take advantage of the fact #id returns the key of the model, unless #id is a property
|
@@ -52,14 +61,15 @@ if defined?(Merb::Plugins)
|
|
52
61
|
after LoadClasses
|
53
62
|
|
54
63
|
def self.run
|
64
|
+
|
55
65
|
Merb.logger.verbose! 'Merb::Orms::DataMapper::Associations - defining lazy relationship properties'
|
56
|
-
|
66
|
+
|
57
67
|
DataMapper::Model.descendants.each do |model|
|
58
68
|
model.relationships.each_value { |r| r.child_key }
|
59
69
|
end
|
60
70
|
|
61
71
|
Merb.logger.verbose! 'Merb::Orms::DataMapper::Associations - complete'
|
62
|
-
|
72
|
+
|
63
73
|
end
|
64
74
|
end
|
65
75
|
|
@@ -88,5 +98,5 @@ if defined?(Merb::Plugins)
|
|
88
98
|
Merb.add_generators generators / 'data_mapper_model'
|
89
99
|
Merb.add_generators generators / 'data_mapper_resource_controller'
|
90
100
|
Merb.add_generators generators / 'data_mapper_migration'
|
91
|
-
|
101
|
+
|
92
102
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'merb_datamapper/connection'
|
3
|
+
|
4
|
+
describe 'Merb datamapper' do
|
5
|
+
it "should read the configuration file" do
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should return an option hash with symbol keys' do
|
10
|
+
Merb.should_receive(:environment).once.and_return('development')
|
11
|
+
|
12
|
+
config = {
|
13
|
+
'development' => {
|
14
|
+
'adapter' => 'myadapter',
|
15
|
+
'more_stuff' => 'more_stuff',
|
16
|
+
'repositories' => {
|
17
|
+
'repo1' => {
|
18
|
+
'adapter' => 'mysql',
|
19
|
+
},
|
20
|
+
},
|
21
|
+
},
|
22
|
+
}
|
23
|
+
|
24
|
+
Merb::Orms::DataMapper.should_receive(:full_config).once.and_return(config)
|
25
|
+
Merb::Orms::DataMapper.config.should have_key(:adapter)
|
26
|
+
Merb::Orms::DataMapper.config[:adapter].should == 'myadapter'
|
27
|
+
Merb::Orms::DataMapper.config.should have_key(:repositories)
|
28
|
+
Merb::Orms::DataMapper.config[:repositories].should have_key(:repo1)
|
29
|
+
Merb::Orms::DataMapper.config[:repositories][:repo1].should have_key(:adapter)
|
30
|
+
Merb::Orms::DataMapper.config[:repositories][:repo1][:adapter].should == 'mysql'
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should create a default repository" do
|
34
|
+
config = {
|
35
|
+
:adapter => 'mysql',
|
36
|
+
:database => 'mydb'
|
37
|
+
}
|
38
|
+
|
39
|
+
Merb::Orms::DataMapper.should_receive(:config).and_return(config)
|
40
|
+
DataMapper.should_receive(:setup).with(:default, config)
|
41
|
+
|
42
|
+
Merb::Orms::DataMapper.setup_connections
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should create additional repositories" do
|
46
|
+
conf_mysql = {
|
47
|
+
:adapter => "mysql",
|
48
|
+
:database => "db"
|
49
|
+
}
|
50
|
+
conf_postgres = {
|
51
|
+
:adapter => "postgres",
|
52
|
+
:database => "dbp"
|
53
|
+
}
|
54
|
+
config = {
|
55
|
+
:repositories => {
|
56
|
+
:repo1 => conf_mysql,
|
57
|
+
:repo2 => conf_postgres
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
Merb::Orms::DataMapper.should_receive(:config).and_return(config)
|
62
|
+
DataMapper.should_receive(:setup).with(:repo1, conf_mysql)
|
63
|
+
DataMapper.should_receive(:setup).with(:repo2, conf_postgres)
|
64
|
+
|
65
|
+
Merb::Orms::DataMapper.setup_connections
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'merb_datamapper/data_mapper_session'
|
3
|
+
|
4
|
+
describe Merb::DataMapperSession do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@session_class = Merb::DataMapperSession
|
8
|
+
@session = @session_class.generate
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should have a session_store_type class attribute" do
|
12
|
+
@session.class.session_store_type.should == :datamapper
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should persist values" do
|
16
|
+
response = request('/session/set')
|
17
|
+
response.should be_successful
|
18
|
+
response.body.should == 'value'
|
19
|
+
response = request('/session/get')
|
20
|
+
response.should be_successful
|
21
|
+
response.body.should == 'value'
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'merb_datamapper/data_mapper_session'
|
3
|
+
|
4
|
+
describe Merb::DataMapperSessionStore do
|
5
|
+
before(:all) do
|
6
|
+
DataMapper.setup(:default, "sqlite3::memory:")
|
7
|
+
end
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
@session_container = Merb::DataMapperSessionStore
|
11
|
+
@session_container.auto_migrate!
|
12
|
+
@sess_id = 'a'*32
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
describe "#retrieve_session" do
|
17
|
+
it "responds to retrieve_session" do
|
18
|
+
@session_container.should respond_to(:retrieve_session)
|
19
|
+
end
|
20
|
+
it "returns the data when given an existing session id" do
|
21
|
+
@session_container.create(:session_id => @sess_id, :data => {:foo => 'bar'})
|
22
|
+
session_data = @session_container.retrieve_session(@sess_id)
|
23
|
+
session_data.should_not be_nil
|
24
|
+
session_data[:foo].should == 'bar'
|
25
|
+
end
|
26
|
+
it "returns nil when a non-existent session_id is used" do
|
27
|
+
@session_container.retrieve_session(@sess_id).should be_nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
describe "#store_session" do
|
33
|
+
it "responds to store_session" do
|
34
|
+
@session_container.should respond_to(:store_session)
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "when a session_id doesn't exist" do
|
38
|
+
it "creates a new record" do
|
39
|
+
@session_container.all.should be_empty
|
40
|
+
@session_container.store_session(@sess_id, {:foo => 'bar'})
|
41
|
+
@session_container.all.should_not be_empty
|
42
|
+
end
|
43
|
+
|
44
|
+
it "saves the data" do
|
45
|
+
@session_container.store_session(@sess_id, {:foo => 'bar'})
|
46
|
+
session_data = @session_container.retrieve_session(@sess_id)
|
47
|
+
session_data.should_not be_nil
|
48
|
+
session_data[:foo].should == 'bar'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "when a session_id does exist" do
|
53
|
+
before(:each) do
|
54
|
+
@session_container.store_session(@sess_id, {:foo => 'bar'})
|
55
|
+
end
|
56
|
+
|
57
|
+
it "doesn't create a new session" do
|
58
|
+
@session_container.all.size.should == 1
|
59
|
+
@session_container.store_session(@sess_id, {:foo => 'FOOOO'})
|
60
|
+
@session_container.all.size.should == 1
|
61
|
+
end
|
62
|
+
|
63
|
+
it "saves the data" do
|
64
|
+
@session_container.store_session(@sess_id, {:foo => 'FOOOO'})
|
65
|
+
session_data = @session_container.retrieve_session(@sess_id)
|
66
|
+
session_data.should_not be_nil
|
67
|
+
session_data[:foo].should == 'FOOOO'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
describe "#delete_session" do
|
74
|
+
before(:each) do
|
75
|
+
@session_container.store_session(@sess_id, {:foo => 'bar'})
|
76
|
+
end
|
77
|
+
|
78
|
+
it "responds to #delete_session" do
|
79
|
+
@session_container.should respond_to(:delete_session)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "destroys an existing session" do
|
83
|
+
@session_container.all.size.should == 1
|
84
|
+
@session_container.delete_session(@sess_id)
|
85
|
+
@session_container.all.size.should == 0
|
86
|
+
end
|
87
|
+
|
88
|
+
it "doesn't destroy a session when the key doesn't match" do
|
89
|
+
@session_container.all.size.should == 1
|
90
|
+
@session_container.delete_session('b'*32)
|
91
|
+
@session_container.all.size.should == 1
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
describe "configuration options" do
|
96
|
+
before(:each) do
|
97
|
+
@session_container = Merb::DataMapperSessionStore
|
98
|
+
end
|
99
|
+
after(:each) do
|
100
|
+
Merb::Plugins.config[:merb_datamapper].clear
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "repository" do
|
104
|
+
it "uses the :default repository when no options are set" do
|
105
|
+
@session_container.default_repository_name.should == :default
|
106
|
+
end
|
107
|
+
it "uses the set name when provided" do
|
108
|
+
Merb::Plugins.config[:merb_datamapper][:session_repository_name] = :other
|
109
|
+
@session_container.default_repository_name.should == :other
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
describe "table name" do
|
115
|
+
it "uses the 'sessions' when no options are set" do
|
116
|
+
@session_container.storage_names[:default].should == 'sessions'
|
117
|
+
end
|
118
|
+
it "uses the set table name when it is set" do
|
119
|
+
pending "this should work but doesn't"
|
120
|
+
Merb::Plugins.config[:merb_datamapper][:session_storage_name] = 'foos'
|
121
|
+
@session_container.storage_names[:default].should == 'foos'
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
|
3
|
+
# Use current merb-core sources if running from a typical dev checkout.
|
4
|
+
lib = File.expand_path('../../../merb/merb-core/lib', __FILE__)
|
5
|
+
$LOAD_PATH.unshift(lib) if File.directory?(lib)
|
6
|
+
require 'merb-core'
|
7
|
+
require 'merb-core/test'
|
8
|
+
require 'merb-core/test/helpers'
|
9
|
+
|
10
|
+
# The lib under test
|
11
|
+
require "merb_datamapper"
|
12
|
+
|
13
|
+
# Satisfies Autotest and anyone else not using the Rake tasks
|
14
|
+
require 'spec'
|
15
|
+
|
16
|
+
|
17
|
+
Merb.start(
|
18
|
+
:environment => 'test',
|
19
|
+
:adapter => 'runner',
|
20
|
+
:session_store => 'datamapper',
|
21
|
+
:merb_root => File.dirname(__FILE__),
|
22
|
+
:log_level => :debug
|
23
|
+
)
|
24
|
+
|
25
|
+
Spec::Runner.configure do |config|
|
26
|
+
config.include Merb::Test::RequestHelper
|
27
|
+
end
|
28
|
+
|
29
|
+
Merb::Router.prepare do
|
30
|
+
default_routes
|
31
|
+
end
|
32
|
+
|
33
|
+
class Application < Merb::Controller
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
require 'datamapper_id_map_controller'
|
38
|
+
require 'datamapper_session_controller'
|
39
|
+
require 'datamapper_model'
|
40
|
+
|
41
|
+
DataMapper.setup(:default, 'sqlite3::memory:')
|
42
|
+
DataObjects::Sqlite3.logger = Merb.logger
|
43
|
+
DataMapper.auto_migrate!
|
44
|
+
Post.create(:title => 'foo')
|
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: 1.0.
|
4
|
+
version: 1.1.0.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Toy
|
@@ -9,9 +9,19 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-01-23 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: merb-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.1.0.pre
|
24
|
+
version:
|
15
25
|
- !ruby/object:Gem::Dependency
|
16
26
|
name: dm-core
|
17
27
|
type: :runtime
|
@@ -33,16 +43,16 @@ dependencies:
|
|
33
43
|
version: "0.10"
|
34
44
|
version:
|
35
45
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
37
|
-
type: :
|
46
|
+
name: rspec
|
47
|
+
type: :development
|
38
48
|
version_requirement:
|
39
49
|
version_requirements: !ruby/object:Gem::Requirement
|
40
50
|
requirements:
|
41
|
-
- -
|
51
|
+
- - ">="
|
42
52
|
- !ruby/object:Gem::Version
|
43
|
-
version: 1.
|
53
|
+
version: 1.2.9
|
44
54
|
version:
|
45
|
-
description:
|
55
|
+
description: Merb plugin that provides support for datamapper
|
46
56
|
email: jtoy@rubynow.com
|
47
57
|
executables: []
|
48
58
|
|
@@ -50,12 +60,14 @@ extensions: []
|
|
50
60
|
|
51
61
|
extra_rdoc_files:
|
52
62
|
- LICENSE
|
63
|
+
- README
|
53
64
|
- TODO
|
54
65
|
files:
|
66
|
+
- Generators
|
55
67
|
- LICENSE
|
68
|
+
- README
|
56
69
|
- Rakefile
|
57
70
|
- TODO
|
58
|
-
- Generators
|
59
71
|
- lib/generators/data_mapper_migration.rb
|
60
72
|
- lib/generators/data_mapper_model.rb
|
61
73
|
- lib/generators/data_mapper_resource_controller.rb
|
@@ -67,19 +79,28 @@ files:
|
|
67
79
|
- lib/generators/templates/views/index.html.erb
|
68
80
|
- lib/generators/templates/views/new.html.erb
|
69
81
|
- lib/generators/templates/views/show.html.erb
|
70
|
-
- lib/
|
71
|
-
- lib/
|
72
|
-
- lib/
|
82
|
+
- lib/merb_datamapper.rb
|
83
|
+
- lib/merb_datamapper/connection.rb
|
84
|
+
- lib/merb_datamapper/data_mapper_session.rb
|
85
|
+
- lib/merb_datamapper/database.yml.sample
|
73
86
|
- lib/merb_datamapper/merbtasks.rb
|
74
87
|
- lib/merb_datamapper/version.rb
|
75
|
-
-
|
88
|
+
- spec/connection_spec.rb
|
89
|
+
- spec/datamapper_id_map_controller.rb
|
90
|
+
- spec/datamapper_model.rb
|
91
|
+
- spec/datamapper_session_controller.rb
|
92
|
+
- spec/identity_map_spec.rb
|
93
|
+
- spec/session_spec.rb
|
94
|
+
- spec/session_store_spec.rb
|
95
|
+
- spec/spec.opts
|
96
|
+
- spec/spec_helper.rb
|
76
97
|
has_rdoc: true
|
77
|
-
homepage: http://
|
98
|
+
homepage: http://github.com/merb/merb_datamapper
|
78
99
|
licenses: []
|
79
100
|
|
80
101
|
post_install_message:
|
81
|
-
rdoc_options:
|
82
|
-
|
102
|
+
rdoc_options:
|
103
|
+
- --charset=UTF-8
|
83
104
|
require_paths:
|
84
105
|
- lib
|
85
106
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -90,16 +111,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
90
111
|
version:
|
91
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
113
|
requirements:
|
93
|
-
- - "
|
114
|
+
- - ">"
|
94
115
|
- !ruby/object:Gem::Version
|
95
|
-
version:
|
116
|
+
version: 1.3.1
|
96
117
|
version:
|
97
118
|
requirements: []
|
98
119
|
|
99
|
-
rubyforge_project:
|
120
|
+
rubyforge_project:
|
100
121
|
rubygems_version: 1.3.5
|
101
122
|
signing_key:
|
102
123
|
specification_version: 3
|
103
|
-
summary:
|
104
|
-
test_files:
|
105
|
-
|
124
|
+
summary: Merb plugin that allows you to use datamapper with your merb app
|
125
|
+
test_files:
|
126
|
+
- spec/connection_spec.rb
|
127
|
+
- spec/datamapper_id_map_controller.rb
|
128
|
+
- spec/datamapper_model.rb
|
129
|
+
- spec/datamapper_session_controller.rb
|
130
|
+
- spec/identity_map_spec.rb
|
131
|
+
- spec/session_spec.rb
|
132
|
+
- spec/session_store_spec.rb
|
133
|
+
- spec/spec_helper.rb
|