shoulda_create 0.0.2 → 0.0.3
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/README.rdoc +14 -1
- data/lib/shoulda_create/shoulda_create.rb +11 -4
- metadata +17 -7
data/README.rdoc
CHANGED
@@ -8,11 +8,24 @@ Shoulda did, but doesn't any more. With this, it can again.
|
|
8
8
|
|
9
9
|
Some ideological dispute, I guess. I complained to one of the thoughtbot guys, and he said "that's the joy of open source, you can build your own". Well, here it is.
|
10
10
|
|
11
|
-
==
|
11
|
+
== Examples
|
12
12
|
|
13
13
|
context 'POST to :create' do
|
14
14
|
setup { post :create, :email => 'bob@example.com', :name => 'Bob Dobbs' }
|
15
|
+
# simple usage
|
15
16
|
should_create :user
|
17
|
+
|
18
|
+
# asserting records are neither created nor destroyed
|
19
|
+
should_not_change_record_count_of :blog_posts
|
20
|
+
|
21
|
+
# asserting a change in some state other than simple row count
|
22
|
+
should_change("number of Bobs", :by => 1){ User.where("name ILIKE '%bob%'").count }
|
23
|
+
|
24
|
+
# the subject can be a class rather than a symbol:
|
25
|
+
should_create Audited::Adapters::ActiveRecord::Audit
|
26
|
+
|
27
|
+
# ... or it can be a table name: (remember to pluralize)
|
28
|
+
should_create 'audits'
|
16
29
|
end
|
17
30
|
|
18
31
|
== License
|
@@ -1,9 +1,16 @@
|
|
1
1
|
module ShouldaCreate
|
2
2
|
def should_change_record_count_of(class_name, amount, action) # :nodoc:
|
3
|
-
klass = class_name.to_s.camelize.constantize
|
4
|
-
var_name = "@_before_change_record_count_#{class_name}"
|
3
|
+
klass = class_name.is_a?(Symbol) ? class_name.to_s.camelize.constantize : class_name
|
4
|
+
var_name = "@_before_change_record_count_#{class_name.to_s.gsub(/:+/, '_')}"
|
5
|
+
counter = lambda do
|
6
|
+
if class_name.is_a?(String)
|
7
|
+
ActiveRecord::Base.connection.select_one("SELECT count(*) FROM #{class_name}")["count"].to_i
|
8
|
+
else
|
9
|
+
klass.count
|
10
|
+
end
|
11
|
+
end
|
5
12
|
before = lambda do
|
6
|
-
instance_variable_set var_name,
|
13
|
+
instance_variable_set var_name, counter.call
|
7
14
|
end
|
8
15
|
human_name = class_name.to_s.humanize.downcase
|
9
16
|
count = 'a'
|
@@ -13,7 +20,7 @@ module ShouldaCreate
|
|
13
20
|
end
|
14
21
|
should "#{action} #{count} #{human_name}", :before => before do
|
15
22
|
assert_equal instance_variable_get(var_name) + amount,
|
16
|
-
|
23
|
+
counter.call,
|
17
24
|
"Expected to #{action} a #{human_name}"
|
18
25
|
end
|
19
26
|
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shoulda_create
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 25
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Bill Kirtley
|
@@ -9,8 +15,7 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date: 2012-
|
13
|
-
default_executable:
|
18
|
+
date: 2012-11-13 00:00:00 Z
|
14
19
|
dependencies: []
|
15
20
|
|
16
21
|
description: I like using should_create and friends to make assertions about records coming and going in the database. Shoulda did, but doesn't any more. With this, it can again.
|
@@ -26,7 +31,6 @@ files:
|
|
26
31
|
- lib/shoulda_create/test_unit.rb
|
27
32
|
- lib/shoulda_create.rb
|
28
33
|
- README.rdoc
|
29
|
-
has_rdoc: true
|
30
34
|
homepage: http://github.com/cluesque/shoulda_create
|
31
35
|
licenses: []
|
32
36
|
|
@@ -36,21 +40,27 @@ rdoc_options: []
|
|
36
40
|
require_paths:
|
37
41
|
- lib
|
38
42
|
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
39
44
|
requirements:
|
40
45
|
- - ">="
|
41
46
|
- !ruby/object:Gem::Version
|
47
|
+
hash: 3
|
48
|
+
segments:
|
49
|
+
- 0
|
42
50
|
version: "0"
|
43
|
-
version:
|
44
51
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
45
53
|
requirements:
|
46
54
|
- - ">="
|
47
55
|
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
48
59
|
version: "0"
|
49
|
-
version:
|
50
60
|
requirements: []
|
51
61
|
|
52
62
|
rubyforge_project:
|
53
|
-
rubygems_version: 1.
|
63
|
+
rubygems_version: 1.8.24
|
54
64
|
signing_key:
|
55
65
|
specification_version: 3
|
56
66
|
summary: Restores should_create functionality to shoulda.
|