rein 0.8.1 → 0.8.2
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.
- data/.gitignore +4 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/Rakefile +6 -0
- data/lib/rein.rb +9 -8
- data/lib/rein/constraint/foreign_key.rb +4 -3
- data/lib/rein/version.rb +1 -1
- data/rein.gemspec +28 -0
- data/spec/rein/constraint/foreign_key_spec.rb +107 -0
- data/spec/rein/constraint/inclusion_spec.rb +23 -0
- data/spec/rein/constraint/numericality_spec.rb +48 -0
- data/spec/rein/constraint/presence_spec.rb +18 -0
- data/spec/rein/constraint/primary_key_spec.rb +18 -0
- data/spec/rein/view_spec.rb +23 -0
- data/spec/spec_helper.rb +17 -0
- metadata +77 -51
- data/lib/rein/alone.rb +0 -14
- data/lib/verify_rcov.rb +0 -56
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/Gemfile
ADDED
data/Rakefile
ADDED
data/lib/rein.rb
CHANGED
@@ -5,15 +5,16 @@ end
|
|
5
5
|
|
6
6
|
RC = Rein::Constraint
|
7
7
|
|
8
|
-
require
|
9
|
-
require
|
8
|
+
require "active_record"
|
9
|
+
require "active_support/core_ext/hash"
|
10
|
+
require "active_support/inflector"
|
10
11
|
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
12
|
+
require "rein/constraint/primary_key"
|
13
|
+
require "rein/constraint/foreign_key"
|
14
|
+
require "rein/constraint/inclusion"
|
15
|
+
require "rein/constraint/numericality"
|
16
|
+
require "rein/constraint/presence"
|
17
|
+
require "rein/view"
|
17
18
|
|
18
19
|
module ActiveRecord::ConnectionAdapters
|
19
20
|
class MysqlAdapter < AbstractAdapter
|
@@ -10,8 +10,8 @@ module RC
|
|
10
10
|
sql << " ADD CONSTRAINT #{name}"
|
11
11
|
sql << " FOREIGN KEY (#{referencing_attribute})"
|
12
12
|
sql << " REFERENCES #{referenced_table} (#{referenced_attribute})"
|
13
|
-
sql << " ON DELETE #{referential_action(options[:on_delete]
|
14
|
-
sql << " ON UPDATE #{referential_action(options[:on_update]
|
13
|
+
sql << " ON DELETE #{referential_action(options[:on_delete])}" if options[:on_delete].present?
|
14
|
+
sql << " ON UPDATE #{referential_action(options[:on_update])}" if options[:on_update].present?
|
15
15
|
end
|
16
16
|
|
17
17
|
execute(sql)
|
@@ -23,7 +23,6 @@ module RC
|
|
23
23
|
|
24
24
|
def remove_foreign_key_constraint(referencing_table, referenced_table, options = {})
|
25
25
|
referencing_attribute = options[:referencing] || "#{referenced_table.to_s.singularize}_id".to_sym
|
26
|
-
referenced_attribute = "id".to_sym
|
27
26
|
|
28
27
|
name = options[:name] || "#{referencing_attribute}_fk".to_sym
|
29
28
|
|
@@ -41,6 +40,8 @@ module RC
|
|
41
40
|
private
|
42
41
|
def referential_action(action)
|
43
42
|
case action.to_sym
|
43
|
+
when :no_action
|
44
|
+
"NO ACTION"
|
44
45
|
when :cascade
|
45
46
|
"CASCADE"
|
46
47
|
when :restrict
|
data/lib/rein/version.rb
CHANGED
data/rein.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
$:.push File.expand_path("../lib", __FILE__)
|
4
|
+
|
5
|
+
require "rein/version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "rein"
|
9
|
+
s.version = Rein::VERSION
|
10
|
+
s.author = "Josh Bassett"
|
11
|
+
s.email = "josh.bassett@gmail.com"
|
12
|
+
s.homepage = "http://github.com/nullobject/rein"
|
13
|
+
s.summary = "Database constraints made easy for ActiveRecord."
|
14
|
+
s.description = "Rein adds bunch of methods to your ActiveRecord migrations so you can easily tame your database."
|
15
|
+
|
16
|
+
s.rubyforge_project = "rein"
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map {|f| File.basename(f) }
|
21
|
+
|
22
|
+
s.add_development_dependency "rake"
|
23
|
+
s.add_development_dependency "rspec"
|
24
|
+
s.add_development_dependency "rr"
|
25
|
+
s.add_development_dependency "simplecov"
|
26
|
+
|
27
|
+
s.add_runtime_dependency "activerecord"
|
28
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RC::ForeignKey do
|
4
|
+
let(:adapter) do
|
5
|
+
Class.new do
|
6
|
+
include RC::ForeignKey
|
7
|
+
end.new
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#add_foreign_key_constraint" do
|
11
|
+
subject { adapter }
|
12
|
+
|
13
|
+
before do
|
14
|
+
stub(adapter).execute
|
15
|
+
stub(adapter).add_index
|
16
|
+
end
|
17
|
+
|
18
|
+
context "with no options" do
|
19
|
+
before { adapter.add_foreign_key_constraint(:books, :people) }
|
20
|
+
it { should have_received.execute("ALTER TABLE books ADD CONSTRAINT person_id_fk FOREIGN KEY (person_id) REFERENCES people (id)") }
|
21
|
+
end
|
22
|
+
|
23
|
+
context "with a given referencing attribute" do
|
24
|
+
before { adapter.add_foreign_key_constraint(:books, :people, :referencing => :author_id) }
|
25
|
+
it { should have_received.execute("ALTER TABLE books ADD CONSTRAINT author_id_fk FOREIGN KEY (author_id) REFERENCES people (id)") }
|
26
|
+
end
|
27
|
+
|
28
|
+
context "with a given referenced attribute" do
|
29
|
+
before { adapter.add_foreign_key_constraint(:books, :people, :referenced => :person_id) }
|
30
|
+
it { should have_received.execute("ALTER TABLE books ADD CONSTRAINT person_id_fk FOREIGN KEY (person_id) REFERENCES people (person_id)") }
|
31
|
+
end
|
32
|
+
|
33
|
+
context "with a given referencing attribute and referenced attribute" do
|
34
|
+
before { adapter.add_foreign_key_constraint(:books, :people, :referencing => :author_id, :referenced => :person_id) }
|
35
|
+
it { should have_received.execute("ALTER TABLE books ADD CONSTRAINT author_id_fk FOREIGN KEY (author_id) REFERENCES people (person_id)") }
|
36
|
+
end
|
37
|
+
|
38
|
+
context "with a given name" do
|
39
|
+
before { adapter.add_foreign_key_constraint(:books, :people, :name => :foo) }
|
40
|
+
it { should have_received.execute("ALTER TABLE books ADD CONSTRAINT foo FOREIGN KEY (person_id) REFERENCES people (id)") }
|
41
|
+
end
|
42
|
+
|
43
|
+
context "with a given on delete referential action" do
|
44
|
+
before { adapter.add_foreign_key_constraint(:books, :people, :on_delete => :cascade) }
|
45
|
+
it { should have_received.execute("ALTER TABLE books ADD CONSTRAINT person_id_fk FOREIGN KEY (person_id) REFERENCES people (id) ON DELETE CASCADE") }
|
46
|
+
end
|
47
|
+
|
48
|
+
context "with a given on update referential action" do
|
49
|
+
before { adapter.add_foreign_key_constraint(:books, :people, :on_update => :cascade) }
|
50
|
+
it { should have_received.execute("ALTER TABLE books ADD CONSTRAINT person_id_fk FOREIGN KEY (person_id) REFERENCES people (id) ON UPDATE CASCADE") }
|
51
|
+
end
|
52
|
+
|
53
|
+
context "with a 'cascade' on delete and update referential action" do
|
54
|
+
before { adapter.add_foreign_key_constraint(:books, :people, :on_delete => :cascade, :on_update => :cascade) }
|
55
|
+
it { should have_received.execute("ALTER TABLE books ADD CONSTRAINT person_id_fk FOREIGN KEY (person_id) REFERENCES people (id) ON DELETE CASCADE ON UPDATE CASCADE") }
|
56
|
+
end
|
57
|
+
|
58
|
+
context "with a 'no action' on delete and update referential action" do
|
59
|
+
before { adapter.add_foreign_key_constraint(:books, :people, :on_delete => :no_action, :on_update => :no_action) }
|
60
|
+
it { should have_received.execute("ALTER TABLE books ADD CONSTRAINT person_id_fk FOREIGN KEY (person_id) REFERENCES people (id) ON DELETE NO ACTION ON UPDATE NO ACTION") }
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "with a given add_index option" do
|
64
|
+
before { adapter.add_foreign_key_constraint(:books, :people, :add_index => true) }
|
65
|
+
it { should have_received.add_index(:books, :person_id) }
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "with a referencing attribute and a add_index option" do
|
69
|
+
before { adapter.add_foreign_key_constraint(:books, :people, :referencing => :author_id, :add_index => true) }
|
70
|
+
it { should have_received.add_index(:books, :author_id) }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "#remove_foreign_key_constraint" do
|
75
|
+
subject { adapter }
|
76
|
+
|
77
|
+
before do
|
78
|
+
stub(adapter).execute
|
79
|
+
stub(adapter).remove_index
|
80
|
+
end
|
81
|
+
|
82
|
+
context "with no options" do
|
83
|
+
before { adapter.remove_foreign_key_constraint(:books, :people) }
|
84
|
+
it { should have_received.execute("ALTER TABLE books DROP CONSTRAINT person_id_fk") }
|
85
|
+
end
|
86
|
+
|
87
|
+
context "with a given referencing attribute" do
|
88
|
+
before { adapter.remove_foreign_key_constraint(:books, :people, :referencing => :author_id) }
|
89
|
+
it { should have_received.execute("ALTER TABLE books DROP CONSTRAINT author_id_fk") }
|
90
|
+
end
|
91
|
+
|
92
|
+
context "with a given name" do
|
93
|
+
before { adapter.remove_foreign_key_constraint(:books, :people, :name => :foo) }
|
94
|
+
it { should have_received.execute("ALTER TABLE books DROP CONSTRAINT foo") }
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "with a given remove_index option" do
|
98
|
+
before { adapter.remove_foreign_key_constraint(:books, :people, :remove_index => true) }
|
99
|
+
it { should have_received.remove_index(:books, :person_id) }
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "with a referencing attribute and a remove_index option" do
|
103
|
+
before { adapter.remove_foreign_key_constraint(:books, :people, :referencing => :author_id, :remove_index => true) }
|
104
|
+
it { should have_received.remove_index(:books, :author_id) }
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RC::Inclusion, "#add_inclusion_constraint" do
|
4
|
+
let(:adapter) do
|
5
|
+
Class.new do
|
6
|
+
include RC::Inclusion
|
7
|
+
end.new
|
8
|
+
end
|
9
|
+
|
10
|
+
subject { adapter }
|
11
|
+
|
12
|
+
before { stub(adapter).execute }
|
13
|
+
|
14
|
+
context "given an array of string values" do
|
15
|
+
before { adapter.add_inclusion_constraint(:books, :state, :in => %w(available on_loan)) }
|
16
|
+
it { should have_received.execute("ALTER TABLE books ADD CONSTRAINT books_state CHECK (state IN ('available', 'on_loan'))") }
|
17
|
+
end
|
18
|
+
|
19
|
+
context "given an array of numeric values" do
|
20
|
+
before { adapter.add_inclusion_constraint(:books, :state, :in => [1, 2, 3]) }
|
21
|
+
it { should have_received.execute("ALTER TABLE books ADD CONSTRAINT books_state CHECK (state IN (1, 2, 3))") }
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RC::Numericality, "#add_numericality_constraint" do
|
4
|
+
let(:adapter) do
|
5
|
+
Class.new do
|
6
|
+
include RC::Numericality
|
7
|
+
end.new
|
8
|
+
end
|
9
|
+
|
10
|
+
subject { adapter }
|
11
|
+
|
12
|
+
before { stub(adapter).execute }
|
13
|
+
|
14
|
+
context "greater_than" do
|
15
|
+
before { adapter.add_numericality_constraint(:books, :published_month, :greater_than => 1) }
|
16
|
+
it { should have_received.execute("ALTER TABLE books ADD CONSTRAINT books_published_month CHECK (published_month > 1)") }
|
17
|
+
end
|
18
|
+
|
19
|
+
context "greater_than_or_equal_to" do
|
20
|
+
before { adapter.add_numericality_constraint(:books, :published_month, :greater_than_or_equal_to => 2) }
|
21
|
+
it { should have_received.execute("ALTER TABLE books ADD CONSTRAINT books_published_month CHECK (published_month >= 2)") }
|
22
|
+
end
|
23
|
+
|
24
|
+
context "equal_to" do
|
25
|
+
before { adapter.add_numericality_constraint(:books, :published_month, :equal_to => 3) }
|
26
|
+
it { should have_received.execute("ALTER TABLE books ADD CONSTRAINT books_published_month CHECK (published_month = 3)") }
|
27
|
+
end
|
28
|
+
|
29
|
+
context "not_equal_to" do
|
30
|
+
before { adapter.add_numericality_constraint(:books, :published_month, :not_equal_to => 0) }
|
31
|
+
it { should have_received.execute("ALTER TABLE books ADD CONSTRAINT books_published_month CHECK (published_month != 0)") }
|
32
|
+
end
|
33
|
+
|
34
|
+
context "less_than" do
|
35
|
+
before { adapter.add_numericality_constraint(:books, :published_month, :less_than => 4) }
|
36
|
+
it { should have_received.execute("ALTER TABLE books ADD CONSTRAINT books_published_month CHECK (published_month < 4)") }
|
37
|
+
end
|
38
|
+
|
39
|
+
context "less_than_or_equal_to" do
|
40
|
+
before { adapter.add_numericality_constraint(:books, :published_month, :less_than_or_equal_to => 5) }
|
41
|
+
it { should have_received.execute("ALTER TABLE books ADD CONSTRAINT books_published_month CHECK (published_month <= 5)") }
|
42
|
+
end
|
43
|
+
|
44
|
+
context "greater_than_or_equal_to and less_than_or_equal_to" do
|
45
|
+
before { adapter.add_numericality_constraint(:books, :published_month, :greater_than_or_equal_to => 5, :less_than_or_equal_to => 6) }
|
46
|
+
it { should have_received.execute("ALTER TABLE books ADD CONSTRAINT books_published_month CHECK (published_month >= 5 AND published_month <= 6)") }
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RC::Presence, "#add_presence_constraint" do
|
4
|
+
let(:adapter) do
|
5
|
+
Class.new do
|
6
|
+
include RC::Presence
|
7
|
+
end.new
|
8
|
+
end
|
9
|
+
|
10
|
+
subject { adapter }
|
11
|
+
|
12
|
+
before { stub(adapter).execute }
|
13
|
+
|
14
|
+
context "given a table and attribute" do
|
15
|
+
before { adapter.add_presence_constraint(:books, :state) }
|
16
|
+
it { should have_received.execute("ALTER TABLE books ADD CONSTRAINT books_state CHECK (state !~ '^\s*$')") }
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RC::PrimaryKey, "#add_primary_key" do
|
4
|
+
let(:adapter) do
|
5
|
+
Class.new do
|
6
|
+
include RC::PrimaryKey
|
7
|
+
end.new
|
8
|
+
end
|
9
|
+
|
10
|
+
subject { adapter }
|
11
|
+
|
12
|
+
before { stub(adapter).execute }
|
13
|
+
|
14
|
+
context "with no options" do
|
15
|
+
before { adapter.add_primary_key(:books) }
|
16
|
+
it { should have_received.execute("ALTER TABLE books ADD PRIMARY KEY (id)") }
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rein::View do
|
4
|
+
let(:adapter) do
|
5
|
+
Class.new do
|
6
|
+
include Rein::View
|
7
|
+
end.new
|
8
|
+
end
|
9
|
+
|
10
|
+
subject { adapter }
|
11
|
+
|
12
|
+
before { stub(adapter).execute }
|
13
|
+
|
14
|
+
describe "#create_view" do
|
15
|
+
before { adapter.create_view(:foo, "SELECT * FROM bar") }
|
16
|
+
it { should have_received.execute("CREATE VIEW foo AS SELECT * FROM bar") }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#drop_view" do
|
20
|
+
before { adapter.drop_view(:foo) }
|
21
|
+
it { should have_received.execute("DROP VIEW foo") }
|
22
|
+
end
|
23
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "rr"
|
2
|
+
require "rr/adapters/rspec"
|
3
|
+
require "rspec"
|
4
|
+
require "simplecov"
|
5
|
+
|
6
|
+
SimpleCov.start
|
7
|
+
|
8
|
+
require "rein"
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.mock_with :rr
|
12
|
+
end
|
13
|
+
|
14
|
+
# FIXME: This is a workaround to get RSpec 2 to play nicely with RR.
|
15
|
+
def have_received(method = nil)
|
16
|
+
RR::Adapters::Rspec::InvocationMatcher.new(method)
|
17
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rein
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,85 +9,88 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-12-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement:
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '0'
|
22
|
-
type: :
|
22
|
+
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: hirb
|
27
|
-
requirement: &70131003190020 !ruby/object:Gem::Requirement
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
25
|
none: false
|
29
26
|
requirements:
|
30
|
-
- -
|
27
|
+
- - ! '>='
|
31
28
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0
|
33
|
-
type: :development
|
34
|
-
prerelease: false
|
35
|
-
version_requirements: *70131003190020
|
29
|
+
version: '0'
|
36
30
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
38
|
-
requirement:
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
39
33
|
none: false
|
40
34
|
requirements:
|
41
|
-
- -
|
35
|
+
- - ! '>='
|
42
36
|
- !ruby/object:Gem::Version
|
43
|
-
version: 0
|
37
|
+
version: '0'
|
44
38
|
type: :development
|
45
39
|
prerelease: false
|
46
|
-
version_requirements:
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: rcov
|
49
|
-
requirement: &70131003189000 !ruby/object:Gem::Requirement
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
41
|
none: false
|
51
42
|
requirements:
|
52
|
-
- -
|
43
|
+
- - ! '>='
|
53
44
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0
|
55
|
-
type: :development
|
56
|
-
prerelease: false
|
57
|
-
version_requirements: *70131003189000
|
45
|
+
version: '0'
|
58
46
|
- !ruby/object:Gem::Dependency
|
59
|
-
name:
|
60
|
-
requirement:
|
47
|
+
name: rr
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
61
49
|
none: false
|
62
50
|
requirements:
|
63
|
-
- -
|
51
|
+
- - ! '>='
|
64
52
|
- !ruby/object:Gem::Version
|
65
|
-
version:
|
53
|
+
version: '0'
|
66
54
|
type: :development
|
67
55
|
prerelease: false
|
68
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
69
62
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
71
|
-
requirement:
|
63
|
+
name: simplecov
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
72
65
|
none: false
|
73
66
|
requirements:
|
74
|
-
- -
|
67
|
+
- - ! '>='
|
75
68
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
69
|
+
version: '0'
|
77
70
|
type: :development
|
78
71
|
prerelease: false
|
79
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
80
78
|
- !ruby/object:Gem::Dependency
|
81
|
-
name:
|
82
|
-
requirement:
|
79
|
+
name: activerecord
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
83
81
|
none: false
|
84
82
|
requirements:
|
85
|
-
- -
|
83
|
+
- - ! '>='
|
86
84
|
- !ruby/object:Gem::Version
|
87
|
-
version: 0
|
88
|
-
type: :
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
89
87
|
prerelease: false
|
90
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
91
94
|
description: Rein adds bunch of methods to your ActiveRecord migrations so you can
|
92
95
|
easily tame your database.
|
93
96
|
email: josh.bassett@gmail.com
|
@@ -95,7 +98,13 @@ executables: []
|
|
95
98
|
extensions: []
|
96
99
|
extra_rdoc_files: []
|
97
100
|
files:
|
98
|
-
-
|
101
|
+
- .gitignore
|
102
|
+
- .rspec
|
103
|
+
- Gemfile
|
104
|
+
- LICENSE
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- lib/rein.rb
|
99
108
|
- lib/rein/constraint/foreign_key.rb
|
100
109
|
- lib/rein/constraint/inclusion.rb
|
101
110
|
- lib/rein/constraint/numericality.rb
|
@@ -103,10 +112,14 @@ files:
|
|
103
112
|
- lib/rein/constraint/primary_key.rb
|
104
113
|
- lib/rein/version.rb
|
105
114
|
- lib/rein/view.rb
|
106
|
-
-
|
107
|
-
-
|
108
|
-
-
|
109
|
-
-
|
115
|
+
- rein.gemspec
|
116
|
+
- spec/rein/constraint/foreign_key_spec.rb
|
117
|
+
- spec/rein/constraint/inclusion_spec.rb
|
118
|
+
- spec/rein/constraint/numericality_spec.rb
|
119
|
+
- spec/rein/constraint/presence_spec.rb
|
120
|
+
- spec/rein/constraint/primary_key_spec.rb
|
121
|
+
- spec/rein/view_spec.rb
|
122
|
+
- spec/spec_helper.rb
|
110
123
|
homepage: http://github.com/nullobject/rein
|
111
124
|
licenses: []
|
112
125
|
post_install_message:
|
@@ -119,16 +132,29 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
119
132
|
- - ! '>='
|
120
133
|
- !ruby/object:Gem::Version
|
121
134
|
version: '0'
|
135
|
+
segments:
|
136
|
+
- 0
|
137
|
+
hash: 2852352367581315615
|
122
138
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
139
|
none: false
|
124
140
|
requirements:
|
125
141
|
- - ! '>='
|
126
142
|
- !ruby/object:Gem::Version
|
127
|
-
version:
|
143
|
+
version: '0'
|
144
|
+
segments:
|
145
|
+
- 0
|
146
|
+
hash: 2852352367581315615
|
128
147
|
requirements: []
|
129
148
|
rubyforge_project: rein
|
130
|
-
rubygems_version: 1.8.
|
149
|
+
rubygems_version: 1.8.23
|
131
150
|
signing_key:
|
132
151
|
specification_version: 3
|
133
152
|
summary: Database constraints made easy for ActiveRecord.
|
134
|
-
test_files:
|
153
|
+
test_files:
|
154
|
+
- spec/rein/constraint/foreign_key_spec.rb
|
155
|
+
- spec/rein/constraint/inclusion_spec.rb
|
156
|
+
- spec/rein/constraint/numericality_spec.rb
|
157
|
+
- spec/rein/constraint/presence_spec.rb
|
158
|
+
- spec/rein/constraint/primary_key_spec.rb
|
159
|
+
- spec/rein/view_spec.rb
|
160
|
+
- spec/spec_helper.rb
|
data/lib/rein/alone.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
rc = "#{ENV['HOME']}/.rubyrc"
|
2
|
-
load(rc) if File.exist?(rc)
|
3
|
-
|
4
|
-
require 'rubygems'
|
5
|
-
require 'bundler'
|
6
|
-
|
7
|
-
envs = [:default]
|
8
|
-
envs << ENV["REIN_ENV"].downcase.to_sym if ENV["REIN_ENV"]
|
9
|
-
Bundler.setup(*envs)
|
10
|
-
|
11
|
-
path = File.join(File.expand_path(File.dirname(__FILE__)), '..')
|
12
|
-
$LOAD_PATH.unshift(path)
|
13
|
-
|
14
|
-
require 'rein'
|
data/lib/verify_rcov.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
module RCov
|
2
|
-
# A task that can verify that the RCov coverage doesn't
|
3
|
-
# drop below a certain threshold. It should be run after
|
4
|
-
# running Spec::Rake::SpecTask.
|
5
|
-
class VerifyTask < Rake::TaskLib
|
6
|
-
# Name of the task. Defaults to :verify_rcov
|
7
|
-
attr_accessor :name
|
8
|
-
|
9
|
-
# Path to the index.html file generated by RCov, which
|
10
|
-
# is the file containing the total coverage.
|
11
|
-
# Defaults to 'coverage/index.html'
|
12
|
-
attr_accessor :index_html
|
13
|
-
|
14
|
-
# Whether or not to output details. Defaults to true.
|
15
|
-
attr_accessor :verbose
|
16
|
-
|
17
|
-
# The threshold value (in percent) for coverage. If the
|
18
|
-
# actual coverage is not equal to this value, the task will raise an
|
19
|
-
# exception.
|
20
|
-
attr_accessor :threshold
|
21
|
-
|
22
|
-
# Require the threshold value be met exactly. This is the default.
|
23
|
-
attr_accessor :require_exact_threshold
|
24
|
-
|
25
|
-
def initialize(name=:verify_rcov)
|
26
|
-
@name = name
|
27
|
-
@index_html = 'coverage/index.html'
|
28
|
-
@verbose = true
|
29
|
-
@require_exact_threshold = true
|
30
|
-
yield self if block_given?
|
31
|
-
raise "Threshold must be set" if @threshold.nil?
|
32
|
-
define
|
33
|
-
end
|
34
|
-
|
35
|
-
def define
|
36
|
-
desc "Verify that rcov coverage is at least #{threshold}%"
|
37
|
-
task @name do
|
38
|
-
total_coverage = 0
|
39
|
-
|
40
|
-
File.open(index_html).each_line do |line|
|
41
|
-
if line =~ /<tt class='coverage_total'>\s*(\d+\.\d+)%\s*<\/tt>/
|
42
|
-
total_coverage = $1.to_f
|
43
|
-
break
|
44
|
-
end
|
45
|
-
end
|
46
|
-
output_coverage(total_coverage)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def output_coverage(total_coverage)
|
51
|
-
puts "Coverage: #{total_coverage}% (threshold: #{threshold}%)" if verbose
|
52
|
-
raise "Coverage must be at least #{threshold}% but was #{total_coverage}%" if total_coverage < threshold
|
53
|
-
raise "Coverage has increased above the threshold of #{threshold}% to #{total_coverage}%. You should update your threshold value." if (total_coverage > threshold) and require_exact_threshold
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|