rein 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/rein.rb CHANGED
@@ -12,11 +12,13 @@ require 'rein/constraint/foreign_key'
12
12
  require 'rein/constraint/primary_key'
13
13
  require 'rein/constraint/inclusion'
14
14
  require 'rein/constraint/numericality'
15
+ require 'rein/view'
15
16
 
16
17
  module ActiveRecord::ConnectionAdapters
17
18
  class MysqlAdapter < AbstractAdapter
18
19
  include RC::PrimaryKey
19
20
  include RC::ForeignKey
21
+ include Rein::View
20
22
  end
21
23
 
22
24
  class PostgreSQLAdapter < AbstractAdapter
@@ -24,5 +26,6 @@ module ActiveRecord::ConnectionAdapters
24
26
  include RC::ForeignKey
25
27
  include RC::Inclusion
26
28
  include RC::Numericality
29
+ include Rein::View
27
30
  end
28
31
  end
data/lib/rein/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rein
2
- VERSION = "0.5.2" unless defined?(Rein::VERSION)
2
+ VERSION = "0.6.0" unless defined?(Rein::VERSION)
3
3
  end
data/lib/rein/view.rb ADDED
@@ -0,0 +1,13 @@
1
+ module Rein
2
+ module View
3
+ def create_view(view_name, sql)
4
+ sql = "CREATE VIEW #{view_name} AS #{sql}"
5
+ execute(sql)
6
+ end
7
+
8
+ def drop_view(view_name)
9
+ sql = "DROP VIEW #{view_name}"
10
+ execute(sql)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,56 @@
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
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 5
8
- - 2
9
- version: 0.5.2
7
+ - 6
8
+ - 0
9
+ version: 0.6.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Josh Bassett
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-30 00:00:00 +10:00
17
+ date: 2010-10-19 00:00:00 +11:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -99,10 +99,10 @@ dependencies:
99
99
  - - ~>
100
100
  - !ruby/object:Gem::Version
101
101
  segments:
102
- - 1
103
- - 3
102
+ - 2
103
+ - 0
104
104
  - 0
105
- version: 1.3.0
105
+ version: 2.0.0
106
106
  type: :development
107
107
  version_requirements: *id006
108
108
  - !ruby/object:Gem::Dependency
@@ -150,7 +150,9 @@ files:
150
150
  - lib/rein/constraint/numericality.rb
151
151
  - lib/rein/constraint/primary_key.rb
152
152
  - lib/rein/version.rb
153
+ - lib/rein/view.rb
153
154
  - lib/rein.rb
155
+ - lib/verify_rcov.rb
154
156
  - LICENSE
155
157
  - README.md
156
158
  has_rdoc: true