minitest-ar-assertions 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +2 -0
- data/README.rdoc +22 -10
- data/VERSION +1 -1
- data/minitest-ar-assertions.gemspec +1 -1
- data/test/helper.rb +5 -4
- data/test/test_minitest_activerecord_assertions.rb +73 -3
- metadata +9 -9
data/Gemfile
CHANGED
@@ -6,6 +6,7 @@ source "http://rubygems.org"
|
|
6
6
|
# Add dependencies to develop your gem here.
|
7
7
|
# Include everything needed to run rake, tests, features, etc.
|
8
8
|
group :development do
|
9
|
+
gem 'minitest', "~>2.6.0", :require => "minitest/autorun"
|
9
10
|
# gem "shoulda", ">= 0"
|
10
11
|
gem "rdoc", "~> 3.12"
|
11
12
|
gem "bundler", "~> 1.0.0"
|
data/Gemfile.lock
CHANGED
data/README.rdoc
CHANGED
@@ -2,16 +2,28 @@
|
|
2
2
|
|
3
3
|
A (small) collection of assertions for testing ActiveRecord associations and validations with MiniTest.
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
5
|
+
== Install:
|
6
|
+
In your Gemfile:
|
7
|
+
gem 'minitest-ar-assertions', :require => 'minitest_activerecord_assertions'
|
8
|
+
|
9
|
+
then in test_helper.rb (or test_config.rb if like me, you love Padrino)
|
10
|
+
include MiniTest::Assertions::ActiveRecord
|
11
|
+
|
12
|
+
Now you are ready to do your thing...
|
13
|
+
|
14
|
+
== Associations:
|
15
|
+
assert_association Comment, :has_many, :likes, :as => :likeable
|
16
|
+
|
17
|
+
assert_association Post, :has_many, :likes => :as => :likeable
|
18
|
+
|
19
|
+
assert_association Like :belongs_to, :likeable
|
20
|
+
|
21
|
+
|
22
|
+
== Validations:
|
23
|
+
assert_validates_presence_of User, :email
|
24
|
+
|
25
|
+
assert_validates_uniqueness_of User, :username, :email
|
26
|
+
|
15
27
|
|
16
28
|
== Contributing to minitest-ar-assertions
|
17
29
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/test/helper.rb
CHANGED
@@ -7,12 +7,13 @@ rescue Bundler::BundlerError => e
|
|
7
7
|
$stderr.puts "Run `bundle install` to install missing gems"
|
8
8
|
exit e.status_code
|
9
9
|
end
|
10
|
-
require 'test/unit'
|
11
|
-
require 'shoulda'
|
12
10
|
|
13
11
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
12
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
-
require
|
13
|
+
require "minitest/autorun"
|
14
|
+
require 'minitest_activerecord_assertions'
|
15
|
+
require "active_record"
|
16
16
|
|
17
|
-
class
|
17
|
+
class MiniTest::Unit::TestCase
|
18
|
+
include MiniTest::Assertions::ActiveRecord
|
18
19
|
end
|
@@ -1,7 +1,77 @@
|
|
1
1
|
require 'helper'
|
2
|
+
require 'active_support/core_ext/module/delegation'
|
2
3
|
|
3
|
-
class
|
4
|
-
|
5
|
-
|
4
|
+
class UnvalidatedThing
|
5
|
+
include ActiveRecord::Reflection
|
6
|
+
include ActiveRecord::Validations
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
class UnassociatedThing
|
11
|
+
include ActiveRecord::Reflection
|
12
|
+
include ActiveRecord::Validations
|
13
|
+
end
|
14
|
+
|
15
|
+
class User < ActiveRecord::Base
|
16
|
+
include ActiveRecord::Reflection
|
17
|
+
include ActiveRecord::Validations
|
18
|
+
|
19
|
+
has_many :likes, :as => :likeable
|
20
|
+
validates_presence_of :email
|
21
|
+
validates_uniqueness_of :username, :email
|
22
|
+
end
|
23
|
+
|
24
|
+
class Like < ActiveRecord::Base
|
25
|
+
include ActiveRecord::Reflection
|
26
|
+
include ActiveRecord::Validations
|
27
|
+
|
28
|
+
belongs_to :likeable, :polymorphic => true
|
29
|
+
belongs_to :user
|
30
|
+
validates_presence_of :email
|
31
|
+
validates_uniqueness_of :username, :email
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "assert_association assertion" do
|
35
|
+
it "should fail for models with no associations" do
|
36
|
+
assert_raises MiniTest::Assertion do
|
37
|
+
assert_association UnvalidatedThing, :belongs_to, :user
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should pass for models with has_many associations" do
|
42
|
+
assert assert_association(User, :has_many, :likes)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should pass for models with belongs_to associations" do
|
46
|
+
assert assert_association(Like, :belongs_to, :user)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should pass for models with polymorphic belongs_to associations" do
|
50
|
+
assert assert_association(Like, :belongs_to, :likeable, :polymorphic => true)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "assert_validates_presence_of assertion" do
|
55
|
+
it "should fail for models with no validations" do
|
56
|
+
assert_raises MiniTest::Assertion do
|
57
|
+
assert_validates_presence_of UnvalidatedThing, :email
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should pass for models with validates_presence_of validations" do
|
62
|
+
assert assert_validates_presence_of(User, :email)
|
6
63
|
end
|
7
64
|
end
|
65
|
+
|
66
|
+
describe "assert_validates_uniqueness_of assertion" do
|
67
|
+
it "should fail for models with no validations" do
|
68
|
+
assert_raises MiniTest::Assertion do
|
69
|
+
assert_validates_uniqueness_of UnvalidatedThing, :username, :email
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should pass for models with validates_uniqueness_of validations" do
|
74
|
+
assert assert_validates_uniqueness_of(User, :username, :email)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest-ar-assertions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-05-28 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdoc
|
16
|
-
requirement: &
|
16
|
+
requirement: &78785000 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.12'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *78785000
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &78784400 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.0.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *78784400
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: jeweler
|
38
|
-
requirement: &
|
38
|
+
requirement: &78783860 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.8.3
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *78783860
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: activerecord
|
49
|
-
requirement: &
|
49
|
+
requirement: &78783060 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *78783060
|
58
58
|
description: A collection of assertions for use with minitest and activerecord. Simplifies
|
59
59
|
testing associations and validations by introspecting associations and validations
|
60
60
|
for you models.
|