bootstripe-rails 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,7 @@
|
|
1
1
|
module ActiveRecord
|
2
2
|
class Base
|
3
|
+
DONT_TRUNCATE = [:schema_migrations]
|
4
|
+
|
3
5
|
# Options:
|
4
6
|
# :merge_lookup => true/false [defaults to true]
|
5
7
|
def self.upsert(lookup, params, options = {})
|
@@ -36,6 +38,24 @@ module ActiveRecord
|
|
36
38
|
order 'created_at ASC'
|
37
39
|
end
|
38
40
|
|
41
|
+
# Truncates all tables in the database
|
42
|
+
#
|
43
|
+
# options:
|
44
|
+
# @param {Array} :exclude tables to exclude from the truncation
|
45
|
+
def self.truncate_models!(options={})
|
46
|
+
if adapter = ActiveRecord::Base.connection.adapter_name
|
47
|
+
exclude = [*options[:exclude]].collect(&:to_sym) if options[:exclude]
|
48
|
+
exclude = ([exclude] + DONT_TRUNCATE).flatten.compact.uniq
|
49
|
+
|
50
|
+
ActiveRecord::Base.connection.tables.each do |table_name|
|
51
|
+
trunc_method = adapter.match(/sqlite/i) ? "DELETE FROM" : "TRUNCATE TABLE"
|
52
|
+
ActiveRecord::Base.connection.execute("#{trunc_method} #{table_name}") if !exclude.include?(table_name.to_sym)
|
53
|
+
end
|
54
|
+
else
|
55
|
+
raise 'No ActiveRecord adapter specified!'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
39
59
|
def clone!(params = {})
|
40
60
|
cl = self.class.new
|
41
61
|
time = Time.current
|
@@ -18,4 +18,12 @@ describe ActiveRecord::Base do
|
|
18
18
|
User.where(:name => 'Mike').first.email.should eq 'mikeypants@mike.com'
|
19
19
|
end
|
20
20
|
|
21
|
+
it 'should truncate' do
|
22
|
+
User.upsert({:name => 'Mike'}, {:email => 'mikeypants@mike.com'})
|
23
|
+
ActiveRecord::Base.truncate_models!(:exclude => :users)
|
24
|
+
User.count.should eq 2
|
25
|
+
ActiveRecord::Base.truncate_models!
|
26
|
+
User.count.should eq 0
|
27
|
+
end
|
28
|
+
|
21
29
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bootstripe-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2012-03-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
17
|
-
requirement: &
|
17
|
+
requirement: &70122628959960 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70122628959960
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: sqlite3
|
28
|
-
requirement: &
|
28
|
+
requirement: &70122628957060 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70122628957060
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rails
|
39
|
-
requirement: &
|
39
|
+
requirement: &70122628955680 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70122628955680
|
48
48
|
description: A handful of useful additions for Rails
|
49
49
|
email:
|
50
50
|
- mike@bytebin.com
|