sinatra-dm 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/spec/spec_helper.rb CHANGED
@@ -7,9 +7,10 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
7
  require 'rubygems'
8
8
  require 'sinatra/dm'
9
9
  require 'sinatra/tests'
10
-
11
10
  require 'dm-core'
12
11
 
12
+ ENV['RACK_ENV'] = 'test'
13
+
13
14
 
14
15
  Spec::Runner.configure do |config|
15
16
  config.include RspecHpricotMatchers
@@ -22,44 +23,19 @@ def fixtures_path
22
23
  end
23
24
 
24
25
 
25
- class MyTestApp < Sinatra::Base
26
-
27
- register(Sinatra::DataMapperExtension)
28
-
29
- set :environment, :test
30
- # set :dm_logger_level, :info
31
-
32
- # NOTE:: The database configuration must be set
33
- # in order for the DataMapper.auto_migrate! /auto_upgrade! migrations work
34
-
35
- set :database, "sqlite3://#{APP_ROOT}/db/db.test.db"
36
-
37
- # ::DataMapper.auto_migrate!
38
-
39
-
40
- ## LOAD MODELS
41
- require "dm_model.rb"
42
-
43
- ## Migrate only in test environments, else upgrade
44
- # test? ? ::DataMapper.auto_migrate! : ::DataMapper.auto_upgrade!
45
-
46
-
47
-
48
- ## ROUTES TEST (IF DATA COMES THROUGH)
49
- get '/db' do
50
- @posts = Post.all
51
- out = []
52
- @posts.each { |p| out << p.name }
53
- # out = @posts.map { |p| p.name }
54
- out.join(', ')
55
- end
56
-
26
+ # class MyTestApp < Sinatra::Base
27
+ #
28
+ # Declared in each test suite
29
+ #
30
+ # end
31
+
32
+
33
+ class Test::Unit::TestCase
34
+ include Sinatra::Tests::TestCase
35
+ Sinatra::Base.set :environment, :test
57
36
  end
58
37
 
59
- def dm_bootstrap
60
-
61
- # DataMapper.setup :default, "sqlite3://#{APP_ROOT}/db/db.bootstrap.db"
62
- # Post.auto_upgrade!
63
- # ::DataMapper::Migrations.auto_upgrade!
64
-
65
- end
38
+
39
+ ### BOOTSTRAP ###
40
+
41
+ require 'dm_bootstrap.rb'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-dm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - kematzy
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-06 00:00:00 +08:00
12
+ date: 2010-02-22 00:00:00 +08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -32,6 +32,16 @@ dependencies:
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.10.1
34
34
  version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: kematzy-tasks
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.1.0
44
+ version:
35
45
  - !ruby/object:Gem::Dependency
36
46
  name: sinatra-tests
37
47
  type: :development
@@ -59,12 +69,13 @@ files:
59
69
  - Rakefile
60
70
  - VERSION
61
71
  - lib/sinatra/dm.rb
62
- - lib/sinatra/dm/rake.rb
63
72
  - sinatra-dm.gemspec
64
- - spec/dm_model.rb
73
+ - spec/dm_bootstrap.rb
65
74
  - spec/fixtures/db/.gitignore
75
+ - spec/fixtures/db/custom/.gitignore
66
76
  - spec/fixtures/log/.gitignore
67
- - spec/sinatra/dm_spec.rb
77
+ - spec/sinatra/dm_mysql_spec.rb
78
+ - spec/sinatra/dm_sqlite3_spec.rb
68
79
  - spec/spec_helper.rb
69
80
  has_rdoc: true
70
81
  homepage: http://github.com/kematzy/sinatra-dm
@@ -95,6 +106,7 @@ signing_key:
95
106
  specification_version: 3
96
107
  summary: Sinatra Extension for working with DataMapper
97
108
  test_files:
98
- - spec/dm_model.rb
99
- - spec/sinatra/dm_spec.rb
109
+ - spec/dm_bootstrap.rb
110
+ - spec/sinatra/dm_mysql_spec.rb
111
+ - spec/sinatra/dm_sqlite3_spec.rb
100
112
  - spec/spec_helper.rb
@@ -1,128 +0,0 @@
1
-
2
- namespace :db do
3
-
4
- namespace :production do
5
-
6
- desc "Convert development.db into production.db"
7
- task :setup do
8
- sh "cp db/development.db db/production.db"
9
- end
10
- end #/ namespace production
11
-
12
-
13
- desc "Backup database to .tar.gz file (=> db:backup:db)"
14
- task :backup => ['db:backup:db']
15
-
16
- desc "Backups DBs into .sql files (=> db:backup:sql)"
17
- task :backups => ['db:backup:sql']
18
-
19
- namespace :backup do
20
-
21
- desc "Backups DBs into .sql file"
22
- task :sql => ['db:dump']
23
-
24
- desc "Backups DB .db file and compresses it"
25
- task :db, [:db] do |t, args|
26
- unless args.db
27
- puts %Q[\nERROR:\n\n You must define the DB variable like this:\n rake db:backup:db db=db/name-of-database.db\n\n]
28
- else
29
- db_name = args.db.sub(/^db\//,'')
30
- `cd db/ && tar zcf ../db/backups/#{Time.now.strftime("%Y%d%m-%H%M%S")}-#{db_name}.tar.gz #{db_name} `
31
- puts "\n-- created a compressed backup version of [ #{args.db} ]\n\n"
32
- end
33
- end
34
-
35
- end #/namespace :backup
36
-
37
-
38
- desc "Bootstrap database with .sql files (db=db/name.db)"
39
- task :bootstrap, [:db] do |t, args|
40
- # To put the data into a SQLite database from a sql file use:
41
- # sqlite database < database.sql
42
- unless args.db
43
- msg = %Q[\nERROR:\n\n You must define the :db variable like this:\n]
44
- msg << %Q[ rake db:bootstrap db=db/name-of-database.db\n\n]
45
- puts msg
46
- else
47
- sh "sqlite3 #{args.db} < db/bootstraps/#{args.db.sub(/^db\//,'')}.sql"
48
- puts "-- DB [ #{args.db}] bootstrapped with [ db/bootstraps/#{args.db.sub(/^db\//,'')}.sql ]l\n\n"
49
- # if test(?d, '.git/config')
50
- # sh "git add db/bootstraps/#{args.db.sub(/^db\//,'')}.sql"
51
- # sh %Q{git commit -m "#{Time.now.strftime("%Y-%d-%m at %H:%M:%S")} : updated DB bootstraps for #{args.db}" }
52
- # end
53
- end
54
-
55
- end
56
-
57
- namespace :bootstrap do
58
-
59
- desc "Bootstrap NEW DB (db=db/name.db, bf=db/bootstraps/name.sql)"
60
- task :new, [:db, :bf] do |t, args|
61
- unless args.db && args.bf
62
- msg = %Q[\nERROR:\n\n You must define the DB variable like this:\n]
63
- msg << %Q[ rake db:bootstrap:new db=db/name-of-database.db\n]
64
- msg << %Q[ bf=db/bootstraps/name.sql \n\n]
65
- puts msg
66
- else
67
- sh "sqlite3 #{args.db} < #{args.bf}"
68
- puts "-- created new DB [ #{args.db} ]\n"
69
- puts "-- - bootstrapped with [ #{args.bf} ]\n\n"
70
- end
71
- end
72
-
73
- end #/namespace :bootstrap
74
-
75
- desc "Dump database(s) to .sql file(s)"
76
- task :dump do
77
- # In order to dump a SQLite database you can use the following command:
78
- # sqlite database .dump > database.sql
79
- dump_all_dbs_and_wrap_dumps_with_comments(:backups)
80
- puts "-- dumped all DBs into .sql files\n\n"
81
- end
82
-
83
- namespace :dump do
84
-
85
- desc "Dump current database as a bootstrap .sql file"
86
- task :bootstrap do
87
- dump_all_dbs_and_wrap_dumps_with_comments(:bootstraps)
88
- end
89
-
90
- end #/ namespace :dump
91
-
92
- end #/ namespace :db
93
-
94
-
95
- ##
96
- # TODO: add some comments here
97
- #
98
- # ==== Examples
99
- #
100
- #
101
- # @api private
102
- def dump_all_dbs_and_wrap_dumps_with_comments(dump_dir = :backups )
103
- Dir["db/*.db"].each do |db|
104
-
105
- if dump_dir == :bootstraps
106
- backup_file = "db/#{dump_dir}/#{File.basename(db)}.sql"
107
- else
108
- backup_file = "db/#{dump_dir}/#{Time.now.strftime("%Y%d%m-%H%M%S")}-#{File.basename(db)}.sql"
109
- end
110
-
111
- comment = %Q['-- ++++ ]
112
- if dump_dir == :bootstraps
113
- comment << %Q[\n-- BOOTSTRAP FILE FOR DB [ #{File.basename(db)} ] ]
114
- else
115
- comment << %Q[\n-- BACKUP OF DB [ #{File.basename(db)} ] ]
116
- end
117
- comment << %Q[\n-- IN APP [ #{File.dirname(File.expand_path(__FILE__))}/ ] ]
118
- comment << %Q[\n-- Created on [ #{Time.now.strftime("%Y-%d-%m at %H:%M:%S")} ] ]
119
- comment << %Q[\n-- ]
120
- comment << %Q[\n-- /++++ \n']
121
-
122
- `echo #{comment} > #{backup_file}`
123
- sh "sqlite3 #{db} .dump >> #{backup_file}"
124
- `echo '\n-- \n-- /EOF \n-- ' >> #{backup_file}`
125
- end
126
-
127
- end
128
-
data/spec/dm_model.rb DELETED
@@ -1,14 +0,0 @@
1
- class ::Post
2
- include DataMapper::Resource
3
- property :id, Serial
4
- property :name, String
5
- end #/ Post
6
-
7
-
8
- # Post.auto_migrate!
9
- DataMapper.auto_migrate!
10
-
11
-
12
- Post.create!(:name => "Post1" )
13
- Post.create!(:name => "Post2" )
14
- Post.create!(:name => "Post3" )
@@ -1,84 +0,0 @@
1
-
2
- require File.expand_path(File.dirname(__FILE__) + '../../spec_helper')
3
-
4
- # dm_bootstrap
5
-
6
- describe "Sinatra" do
7
-
8
- describe "DM" do
9
-
10
- before(:each) do
11
- class ::Test::Unit::TestCase
12
- def app; ::MyTestApp.new ; end
13
- end
14
- @app = app
15
- end
16
-
17
- after(:each) do
18
- class ::Test::Unit::TestCase
19
- def app; nil ; end
20
- end
21
- @app = nil
22
- end
23
-
24
- # it_should_behave_like "MyTestApp"
25
-
26
- describe "Using Defaults" do
27
-
28
- it "should set the correct adapter" do
29
- MyTestApp.database.options['adapter'].should == "sqlite3"
30
- end
31
-
32
- it "should set the correct db path" do
33
- MyTestApp.database.options['path'].should == "#{fixtures_path}/db/db.test.db"
34
- end
35
-
36
- it "should set the correct dm_logger_level" do
37
- MyTestApp.database_logger.init_args[1].should == :debug
38
- end
39
-
40
- it "should set the correct dm_logger_level" do
41
- MyTestApp.database_logger.init_args[0].should == "#{fixtures_path}/log/dm.test.log"
42
- end
43
-
44
- it "should return the data from the database" do
45
- get("/db")
46
- body.should == "Post1, Post2, Post3"
47
- end
48
-
49
- end #/ Using Defaults
50
-
51
- describe "Using Custom Settings" do
52
-
53
- class MySQLTestApp < Sinatra::Base
54
- register(Sinatra::DataMapperExtension)
55
-
56
- # NOTE:: :dm_logger_level & :dm_logger_path must be set before :database
57
- # in order to use custom settings
58
- set :dm_logger_level, :info
59
- set :dm_logger_path, "#{::APP_ROOT}/log/dm.custom.log"
60
-
61
- set :database, 'mysql://localhost/the_database_name'
62
- end
63
-
64
- it "should set the correct adapter" do
65
- MySQLTestApp.database.options['adapter'].should == "mysql"
66
- end
67
-
68
- it "should set the correct db path" do
69
- MySQLTestApp.database.options['path'].should == "/the_database_name"
70
- end
71
-
72
- it "should set the correct dm_logger_level" do
73
- MySQLTestApp.database_logger.init_args[1].should == :info
74
- end
75
-
76
- it "should set the correct dm_logger_level" do
77
- MySQLTestApp.database_logger.init_args[0].should == "#{fixtures_path}/log/dm.custom.log"
78
- end
79
-
80
- end #/ Using Custom Settings
81
-
82
-
83
- end #/ DM
84
- end #/ Sinatra