sinatra-activerecord 1.3.0 → 1.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7edc0684bddd8d0f9cc24239a89dc19361301dea
4
- data.tar.gz: c51d1ade72ed09fda8477a1dc375aa33136eaa8c
3
+ metadata.gz: ebc762631ec940416f6da6a0556185e825435d19
4
+ data.tar.gz: 803dbda8bdd9f0d0337a1b5a76e498325b759d07
5
5
  SHA512:
6
- metadata.gz: 8d5eef19d30808bb280a1eb32743e63224f678f2a8c646a5c88629d39e2e071821e4c72b3163263ba80c18fc6475a0f6816786d7822869459b4cc9cb3a18fbcf
7
- data.tar.gz: 006139024a60db57dbb2967045aee49ef8819981b39599b4c281f7457982284268e740d0463034465795fe263b0d13f3e7d7a885c14f62fd845fbcb16e2fede8
6
+ metadata.gz: c549c27517bf69e71989ca6c0e538e69bf81f83876a3236ad5dcc65b48f3c5a276365ae2c46046b00fcbab7d5cdc9fdcf767a8b35f3b2ebb416ca668a8fbc1bd
7
+ data.tar.gz: e26325d3743f08312be6d94feeb67edd44864d1cbf4f1a22f25ae5c343ba8ce6632b9fe1b8a95bfb046303f5dfc8560a7a83f7a6b8a095d2564d513f37c34622
data/README.md CHANGED
@@ -47,11 +47,15 @@ In the Terminal test that it works:
47
47
 
48
48
  ```sh
49
49
  $ rake -T
50
- rake db:create_migration # create an ActiveRecord migration
51
- rake db:migrate # migrate the database (use version with VERSION=n)
52
- rake db:rollback # roll back the migration (use steps with STEP=n)
53
- rake db:schema:dump # dump schema into file
54
- rake db:schema:load # load schema into database
50
+ rake db:create # create the database from config/database.yml from the current Sinatra env
51
+ rake db:create_migration # create an ActiveRecord migration
52
+ rake db:drop # drops the data from config/database.yml from the current Sinatra env
53
+ rake db:migrate # migrate the database (use version with VERSION=n)
54
+ rake db:rollback # roll back the migration (use steps with STEP=n)
55
+ rake db:schema:dump # dump schema into file
56
+ rake db:schema:load # load schema into database
57
+ rake db:seed # load the seed data from db/seeds.rb
58
+ rake db:setup # create the database and load the schema
55
59
  ```
56
60
 
57
61
  And that's it, you're all set :)
@@ -78,14 +78,40 @@ module Sinatra
78
78
  end
79
79
  end
80
80
 
81
+ def purge
82
+ if config
83
+ ActiveRecord::Tasks::DatabaseTasks.purge(config)
84
+ else
85
+ raise ActiveRecord::ConnectionNotEstablished
86
+ end
87
+ end
88
+
81
89
  def load_schema(file_name = 'db/schema.rb')
82
90
  load(file_name)
83
91
  end
84
92
 
93
+ def with_config_environment(environment, &block)
94
+ previous_environment = config_environment
95
+ begin
96
+ config_environment(environment)
97
+ yield
98
+ ensure
99
+ config_environment(previous_environment)
100
+ end
101
+ end
102
+
85
103
  private
86
104
 
105
+ def config_environment(env = nil)
106
+ if env
107
+ @config_environment = env
108
+ else
109
+ @config_environment ||= Sinatra::Application.environment.to_s
110
+ end
111
+ end
112
+
87
113
  def config
88
- ActiveRecord::Base.configurations[Sinatra::Application.environment.to_s]
114
+ ActiveRecord::Base.configurations[config_environment]
89
115
  end
90
116
 
91
117
  def migrations_dir
@@ -49,4 +49,24 @@ namespace :db do
49
49
  Sinatra::ActiveRecordTasks.load_schema()
50
50
  end
51
51
  end
52
+
53
+ namespace :test do
54
+ task :purge do
55
+ Sinatra::ActiveRecordTasks.with_config_environment 'test' do
56
+ Sinatra::ActiveRecordTasks.purge()
57
+ end
58
+ end
59
+
60
+ task :load => :purge do
61
+ ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test'])
62
+ Sinatra::ActiveRecordTasks.with_config_environment 'test' do
63
+ Sinatra::ActiveRecordTasks.load_schema()
64
+ end
65
+ end
66
+
67
+ desc 'Prepare test database from development schema'
68
+ task :prepare do
69
+ Rake::Task["db:test:load"].invoke
70
+ end
71
+ end
52
72
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Mizerany
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-07 00:00:00.000000000 Z
12
+ date: 2014-03-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra