Empact-sexy_pg_constraints 0.2.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.
@@ -0,0 +1,28 @@
1
+ module AssertProhibitsAllows
2
+ def assert_prohibits(model, column, constraint, constraint_type = 'check', exception_type = ActiveRecord::StatementInvalid)
3
+ column = column.join('_') if column.respond_to?(:join)
4
+
5
+ book = model.new
6
+ yield(book)
7
+ assert book.valid?
8
+ error = assert_raise exception_type do
9
+ book.save
10
+ end
11
+ assert_match /PGError/, error.message
12
+ assert_match /violates #{constraint_type} constraint/, error.message
13
+ assert_match /"#{model.table_name}_#{column}_(#{Array(constraint).map {|c| c.to_s }.join('|')})"/, error.message if constraint_type == 'check'
14
+ end
15
+
16
+ def assert_allows(model)
17
+ first_count = model.count
18
+ book = model.new
19
+ yield(book)
20
+ assert book.valid?
21
+ assert_nothing_raised do
22
+ book.save
23
+ end
24
+ assert_equal first_count + 1, model.count
25
+ end
26
+ end
27
+
28
+ Test::Unit::TestCase.send(:include, AssertProhibitsAllows)
@@ -0,0 +1,6 @@
1
+ adapter: postgresql
2
+ host: localhost
3
+ port: 5432
4
+ username: postgres
5
+ database: spc_test
6
+ encoding: utf8
@@ -0,0 +1,36 @@
1
+ # Setting up sample migrations
2
+ class CreateBooks < ActiveRecord::Migration
3
+ def self.up
4
+ create_table :books do |t|
5
+ t.string :title
6
+ t.string :author
7
+ t.integer :author_id
8
+ t.integer :quantity
9
+ t.integer :from
10
+ t.string :isbn
11
+ t.string :as
12
+ t.integer :xor_col_1
13
+ t.integer :xor_col_2
14
+ end
15
+ end
16
+
17
+ def self.down
18
+ drop_table :books
19
+ end
20
+ end
21
+
22
+ class CreateAuthors < ActiveRecord::Migration
23
+ def self.up
24
+ create_table :authors do |t|
25
+ t.string :name
26
+ t.string :bio
27
+ end
28
+ end
29
+
30
+ def self.down
31
+ drop_table :authors
32
+ end
33
+ end
34
+
35
+ class Book < ActiveRecord::Base; end
36
+ class Author < ActiveRecord::Base; end
@@ -0,0 +1,27 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'active_support/core_ext/class/attribute_accessors'
11
+ require 'active_support/core_ext/module/delegation'
12
+ require 'active_record'
13
+ require 'test/unit'
14
+ require 'shoulda'
15
+
16
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
17
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
18
+ require "sexy_pg_constraints"
19
+ require 'support/models'
20
+ require 'support/assert_prohibits_allows'
21
+
22
+ db_config_path = File.join(File.dirname(__FILE__), 'support', 'database.yml')
23
+ ActiveRecord::Base.establish_connection(YAML::load(open(db_config_path)))
24
+ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send(:include, SexyPgConstraints)
25
+
26
+ class Test::Unit::TestCase
27
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Empact-sexy_pg_constraints
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.2.0
6
+ platform: ruby
7
+ authors:
8
+ - Maxim Chernyak
9
+ - Ben Woosley
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2011-04-21 00:00:00 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: activerecord
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 3.0.0
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: pg
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: shoulda
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: bundler
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: 1.0.0
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: jeweler
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: 1.5.2
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: rcov
73
+ requirement: &id006 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: *id006
82
+ description: Use migrations and simple syntax to manage constraints in PostgreSQL DB.
83
+ email: ben.woosley@gmail.com
84
+ executables: []
85
+
86
+ extensions: []
87
+
88
+ extra_rdoc_files:
89
+ - LICENSE.txt
90
+ - README.rdoc
91
+ files:
92
+ - CHANGELOG.rdoc
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE.txt
96
+ - README.rdoc
97
+ - Rakefile
98
+ - VERSION
99
+ - init.rb
100
+ - lib/sexy_pg_constraints.rb
101
+ - lib/sexy_pg_constraints/constrainer.rb
102
+ - lib/sexy_pg_constraints/constraints.rb
103
+ - lib/sexy_pg_constraints/deconstrainer.rb
104
+ - lib/sexy_pg_constraints/helpers.rb
105
+ - lib/sexy_pg_constraints/initializer.rb
106
+ - sexy_pg_constraints.gemspec
107
+ - test/sexy_pg_constraints_test.rb
108
+ - test/support/assert_prohibits_allows.rb
109
+ - test/support/database.yml.example
110
+ - test/support/models.rb
111
+ - test/test_helper.rb
112
+ homepage: http://github.com/maxim/sexy_pg_constraints
113
+ licenses: []
114
+
115
+ post_install_message:
116
+ rdoc_options: []
117
+
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ hash: -665410626784681910
126
+ segments:
127
+ - 0
128
+ version: "0"
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: "0"
135
+ requirements: []
136
+
137
+ rubyforge_project:
138
+ rubygems_version: 1.7.2
139
+ signing_key:
140
+ specification_version: 3
141
+ summary: ""
142
+ test_files:
143
+ - test/sexy_pg_constraints_test.rb
144
+ - test/support/assert_prohibits_allows.rb
145
+ - test/support/models.rb
146
+ - test/test_helper.rb