bborn-acts_as_taggable_on_steroids 2.0.beta3 → 2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +157 -0
- data/{lib → app/helpers}/tags_helper.rb +0 -0
- data/{lib → app/models}/tag.rb +0 -0
- data/{lib → app/models}/tag_list.rb +0 -0
- data/{lib → app/models}/tagging.rb +0 -0
- data/lib/acts_as_taggable.rb +1 -245
- data/lib/acts_as_taggable/active_record_extension.rb +246 -0
- data/lib/acts_as_taggable/engine.rb +16 -0
- data/test/acts_as_taggable_test.rb +63 -74
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +9 -0
- data/test/dummy/app/assets/stylesheets/application.css +7 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/{fixtures → dummy/app/models}/magazine.rb +0 -0
- data/test/{fixtures → dummy/app/models}/photo.rb +0 -0
- data/test/{fixtures → dummy/app/models}/post.rb +0 -0
- data/test/{fixtures → dummy/app/models}/special_post.rb +0 -0
- data/test/{fixtures → dummy/app/models}/subscription.rb +0 -0
- data/test/{fixtures → dummy/app/models}/user.rb +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +45 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +30 -0
- data/test/dummy/config/environments/production.rb +60 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +10 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/{schema.rb → dummy/db/schema.rb} +0 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +440 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +26 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/support/query_counter.rb +29 -0
- data/test/tag_list_test.rb +1 -1
- data/test/tag_test.rb +63 -63
- data/test/tagging_test.rb +1 -1
- data/test/tags_helper_test.rb +1 -1
- data/test/test_helper.rb +61 -0
- metadata +117 -33
- data/CHANGELOG +0 -212
- data/README +0 -157
- data/acts_as_taggable_on_steroids.gemspec +0 -54
- data/init.rb +0 -1
- data/test/abstract_unit.rb +0 -106
data/CHANGELOG
DELETED
@@ -1,212 +0,0 @@
|
|
1
|
-
[11 Jun 09]
|
2
|
-
|
3
|
-
* Remove deprecated TagCountsExtension.
|
4
|
-
|
5
|
-
* Update tests to use foxy fixtures [Jonas Wagner]
|
6
|
-
|
7
|
-
* Allow hash conditions to be passed to Tag.counts [Jonas Wagner]
|
8
|
-
|
9
|
-
[3 Jun 09]
|
10
|
-
|
11
|
-
* Upgrade tests for Rails 2.3
|
12
|
-
|
13
|
-
[18 Mar 09]
|
14
|
-
|
15
|
-
* Change callbacks used to save tags.
|
16
|
-
|
17
|
-
[18 Feb 09]
|
18
|
-
|
19
|
-
* Greatly improve speed when using find_tagged_with and :match_all [notonthehighstreet.com].
|
20
|
-
|
21
|
-
[17 Sep 08]
|
22
|
-
|
23
|
-
* Sanitize scope conditions in find_options_for_tag_counts [Rémy-Christophe Schermesser]
|
24
|
-
|
25
|
-
[23 Aug 08]
|
26
|
-
|
27
|
-
* Fix tag_counts instance method when no tags are present.
|
28
|
-
|
29
|
-
* Make tag_counts instance_method merge any :conditions passed to it.
|
30
|
-
|
31
|
-
[30 Mar 08]
|
32
|
-
|
33
|
-
* Make TagList.from accept array arguments.
|
34
|
-
|
35
|
-
[29 Mar 08]
|
36
|
-
|
37
|
-
* Improve parsing of quotes inside tags [Arturas Slajus].
|
38
|
-
|
39
|
-
* Add Tag.counts method.
|
40
|
-
|
41
|
-
[28 Mar 08]
|
42
|
-
|
43
|
-
* Make Tag#taggings :dependent => :destroy.
|
44
|
-
|
45
|
-
[27 Mar 08]
|
46
|
-
|
47
|
-
* Fix documentation for tag_counts.
|
48
|
-
|
49
|
-
[18 Mar 08]
|
50
|
-
|
51
|
-
* Add TagList#toggle [Pete Yandell].
|
52
|
-
|
53
|
-
# Add find_related_tags method [Austin Foncaier].
|
54
|
-
|
55
|
-
[30 Jan 08]
|
56
|
-
|
57
|
-
* Fix Tag.destroy_unused on Rails 2.0.
|
58
|
-
|
59
|
-
[23 October 2007]
|
60
|
-
|
61
|
-
* Make find_options_for_tag_counts and find_options_for_tagged_with dup their options.
|
62
|
-
|
63
|
-
* Apply conditions properly in find_options_for_tag_counts.
|
64
|
-
|
65
|
-
* Fix tag_cloud when no tags are present.
|
66
|
-
|
67
|
-
[22 October 2007]
|
68
|
-
|
69
|
-
* Fix find_tagged_with using :match_all and :include.
|
70
|
-
|
71
|
-
* Use inner joins instead of left outer joins.
|
72
|
-
|
73
|
-
[15 October 2007]
|
74
|
-
|
75
|
-
* Make find_tagged_with correctly apply :conditions
|
76
|
-
|
77
|
-
* Add Tag.destroy_unused option.
|
78
|
-
|
79
|
-
[11 October 2007]
|
80
|
-
|
81
|
-
* Make tag_counts work correctly with STI.
|
82
|
-
|
83
|
-
[3 October 2007]
|
84
|
-
|
85
|
-
* Improve documentation.
|
86
|
-
|
87
|
-
* Fix TagsHelper and test.
|
88
|
-
|
89
|
-
[2 October 2007]
|
90
|
-
|
91
|
-
* Remove TagList.parse, use TagList.from instead.
|
92
|
-
|
93
|
-
* Add :parse option to TagList#new, TagList#add, and TagList#remove.
|
94
|
-
|
95
|
-
tag_list = TagList.new("One, Two", :parse => true) # ["One", "Two"]
|
96
|
-
|
97
|
-
tag_list # ["One", "Two"]
|
98
|
-
tag_list.add("Three, Four", :parse => true) # ["One", "Two", "Three", "Four"]
|
99
|
-
|
100
|
-
* Remove TagList#names.
|
101
|
-
|
102
|
-
[29 September 2007]
|
103
|
-
|
104
|
-
* Add TagsHelper to assist with generating tag clouds and provide a simple example.
|
105
|
-
|
106
|
-
[27 September 2007]
|
107
|
-
|
108
|
-
* Add #tag_counts method to get tag counts for a specific object's tags.
|
109
|
-
|
110
|
-
* BACKWARDS INCOMPATIBILITY: Rename #find_options_for_tagged_with to #find_options_for_find_tagged_with
|
111
|
-
|
112
|
-
[17 September 2007]
|
113
|
-
|
114
|
-
* Fix clearing of cached tag list when all tags removed.
|
115
|
-
|
116
|
-
[12 September 2007]
|
117
|
-
|
118
|
-
* Make the TagList class inherit from Array.
|
119
|
-
|
120
|
-
* Deprecate obsolete TagList#names.
|
121
|
-
|
122
|
-
[6 September 2007]
|
123
|
-
|
124
|
-
* Add TagList#include? and TagList#empty?
|
125
|
-
|
126
|
-
[26 August 2007]
|
127
|
-
|
128
|
-
* Remove deprecated Tag.delimiter. Use TagList.delimiter instead.
|
129
|
-
|
130
|
-
[25 August 2007]
|
131
|
-
|
132
|
-
* Make tag_counts work with has_many :through
|
133
|
-
|
134
|
-
[23 August 2007]
|
135
|
-
|
136
|
-
* Make search comparisons case-insensitive across different databases. [Moisés Machado]
|
137
|
-
|
138
|
-
* Improve compatiblity with STI. [Moisés Machado]
|
139
|
-
|
140
|
-
[25 July 2007]
|
141
|
-
|
142
|
-
* Respect custom table names for the Tag and Tagging classes.
|
143
|
-
|
144
|
-
* Fix the :exclude option for find_tagged_with
|
145
|
-
|
146
|
-
[17 July 2007]
|
147
|
-
|
148
|
-
* Make the migration work on edge rails
|
149
|
-
|
150
|
-
[8 July 2007]
|
151
|
-
|
152
|
-
* find_options_for_tagged_with should not alter its arguments
|
153
|
-
|
154
|
-
[1 July 2007]
|
155
|
-
|
156
|
-
* Fix incorrect tagging when the case of the tag list is changed.
|
157
|
-
|
158
|
-
* Fix deprecated Tag.delimiter accessor.
|
159
|
-
|
160
|
-
[23 June 2007]
|
161
|
-
|
162
|
-
* Add validation to Tag model.
|
163
|
-
|
164
|
-
* find_options_for_tagged_with should always return a hash.
|
165
|
-
|
166
|
-
* find_tagged_with passing in no tags should return an empty array.
|
167
|
-
|
168
|
-
* Improve compatibility with PostgreSQL.
|
169
|
-
|
170
|
-
[21 June 2007]
|
171
|
-
|
172
|
-
* Remove extra .rb from generated migration file name.
|
173
|
-
|
174
|
-
[15 June 2007]
|
175
|
-
|
176
|
-
* Introduce TagList class.
|
177
|
-
|
178
|
-
* Various cleanups and improvements.
|
179
|
-
|
180
|
-
* Use TagList.delimiter now, not Tag.delimiter. Tag.delimiter will be removed at some stage.
|
181
|
-
|
182
|
-
[11 June 2007]
|
183
|
-
|
184
|
-
* Restructure the creation of the options for find_tagged_with [Thijs Cadier]
|
185
|
-
|
186
|
-
* Add an example migration with a generator.
|
187
|
-
|
188
|
-
* Add caching.
|
189
|
-
|
190
|
-
* Fix compatibility with Ruby < 1.8.6
|
191
|
-
|
192
|
-
[23 April 2007]
|
193
|
-
|
194
|
-
* Make tag_list to respect Tag.delimiter
|
195
|
-
|
196
|
-
[31 March 2007]
|
197
|
-
|
198
|
-
* Add Tag.delimiter accessor to change how tags are parsed.
|
199
|
-
|
200
|
-
* Fix :include => :tags when used with find_tagged_with
|
201
|
-
|
202
|
-
[7 March 2007]
|
203
|
-
|
204
|
-
* Fix tag_counts for SQLServer [Brad Young]
|
205
|
-
|
206
|
-
[21 Feb 2007]
|
207
|
-
|
208
|
-
* Use scoping instead of TagCountsExtension [Michael Schuerig]
|
209
|
-
|
210
|
-
[7 Jan 2007]
|
211
|
-
|
212
|
-
* Add :match_all to find_tagged_with [Michael Sheakoski]
|
data/README
DELETED
@@ -1,157 +0,0 @@
|
|
1
|
-
= acts_as_taggable_on_steroids
|
2
|
-
|
3
|
-
If you find this plugin useful, please consider a donation to show your support!
|
4
|
-
|
5
|
-
http://www.paypal.com/cgi-bin/webscr?cmd=_send-money
|
6
|
-
|
7
|
-
Email address: jonathan.viney@gmail.com
|
8
|
-
|
9
|
-
== Instructions
|
10
|
-
|
11
|
-
This plugin is based on acts_as_taggable by DHH but includes extras
|
12
|
-
such as tests, smarter tag assignment, and tag cloud calculations.
|
13
|
-
|
14
|
-
== Installation
|
15
|
-
|
16
|
-
Rails 2.*
|
17
|
-
|
18
|
-
ruby script/plugin install git://github.com/jviney/acts_as_taggable_on_steroids.git
|
19
|
-
|
20
|
-
Rails 3:
|
21
|
-
|
22
|
-
rails plugin install git://github.com/jviney/acts_as_taggable_on_steroids.git
|
23
|
-
|
24
|
-
== Usage
|
25
|
-
|
26
|
-
=== Prepare database
|
27
|
-
|
28
|
-
Generate and apply the migration:
|
29
|
-
|
30
|
-
ruby script/generate acts_as_taggable_migration
|
31
|
-
rake db:migrate
|
32
|
-
|
33
|
-
=== Basic tagging
|
34
|
-
|
35
|
-
Let's suppose users have many posts and we want those posts to have tags.
|
36
|
-
The first step is to add +acts_as_taggable+ to the Post class:
|
37
|
-
|
38
|
-
class Post < ActiveRecord::Base
|
39
|
-
acts_as_taggable
|
40
|
-
|
41
|
-
belongs_to :user
|
42
|
-
end
|
43
|
-
|
44
|
-
We can now use the tagging methods provided by acts_as_taggable, <tt>#tag_list</tt> and <tt>#tag_list=</tt>. Both these
|
45
|
-
methods work like regular attribute accessors.
|
46
|
-
|
47
|
-
p = Post.find(:first)
|
48
|
-
p.tag_list # []
|
49
|
-
p.tag_list = "Funny, Silly"
|
50
|
-
p.save
|
51
|
-
p.tag_list # ["Funny", "Silly"]
|
52
|
-
|
53
|
-
You can also add or remove arrays of tags.
|
54
|
-
|
55
|
-
p.tag_list.add("Great", "Awful")
|
56
|
-
p.tag_list.remove("Funny")
|
57
|
-
|
58
|
-
In your views you should use something like the following:
|
59
|
-
|
60
|
-
<%= f.label :tag_list %>
|
61
|
-
<%= f.text_field :tag_list, :size => 80 %>
|
62
|
-
|
63
|
-
=== Finding tagged objects
|
64
|
-
|
65
|
-
To retrieve objects tagged with a certain tag, use find_tagged_with.
|
66
|
-
|
67
|
-
Post.find_tagged_with('Funny, Silly')
|
68
|
-
|
69
|
-
By default, find_tagged_with will find objects that have any of the given tags. To
|
70
|
-
find only objects that are tagged with all the given tags, use match_all.
|
71
|
-
|
72
|
-
Post.find_tagged_with('Funny, Silly', :match_all => true)
|
73
|
-
|
74
|
-
See <tt>ActiveRecord::Acts::Taggable::InstanceMethods</tt> for more methods and options.
|
75
|
-
|
76
|
-
=== Tag cloud calculations
|
77
|
-
|
78
|
-
To construct tag clouds, the frequency of each tag needs to be calculated.
|
79
|
-
Because we specified +acts_as_taggable+ on the <tt>Post</tt> class, we can
|
80
|
-
get a calculation of all the tag counts by using <tt>Post.tag_counts</tt>. But what if we wanted a tag count for
|
81
|
-
an single user's posts? To achieve this we call tag_counts on the association:
|
82
|
-
|
83
|
-
User.find(:first).posts.tag_counts
|
84
|
-
|
85
|
-
A helper is included to assist with generating tag clouds. Include it in your helper file:
|
86
|
-
|
87
|
-
module ApplicationHelper
|
88
|
-
include TagsHelper
|
89
|
-
end
|
90
|
-
|
91
|
-
You can also use the <tt>counts</tt> method on <tt>Tag</tt> to get the counts for all tags in the database.
|
92
|
-
|
93
|
-
Tag.counts
|
94
|
-
|
95
|
-
Here is an example that generates a tag cloud.
|
96
|
-
|
97
|
-
Controller:
|
98
|
-
|
99
|
-
class PostController < ApplicationController
|
100
|
-
def tag_cloud
|
101
|
-
@tags = Post.tag_counts
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
View:
|
106
|
-
<% tag_cloud @tags, %w(css1 css2 css3 css4) do |tag, css_class| %>
|
107
|
-
<%= link_to tag.name, { :action => :tag, :id => tag.name }, :class => css_class %>
|
108
|
-
<% end %>
|
109
|
-
|
110
|
-
CSS:
|
111
|
-
|
112
|
-
.css1 { font-size: 1.0em; }
|
113
|
-
.css2 { font-size: 1.2em; }
|
114
|
-
.css3 { font-size: 1.4em; }
|
115
|
-
.css4 { font-size: 1.6em; }
|
116
|
-
|
117
|
-
=== Caching
|
118
|
-
|
119
|
-
It is useful to cache the list of tags to reduce the number of queries executed. To do this,
|
120
|
-
add a column named <tt>cached_tag_list</tt> to the model which is being tagged. The column should be long enough to hold
|
121
|
-
the full tag list and must have a default value of null, not an empty string.
|
122
|
-
|
123
|
-
class CachePostTagList < ActiveRecord::Migration
|
124
|
-
def self.up
|
125
|
-
add_column :posts, :cached_tag_list, :string
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
class Post < ActiveRecord::Base
|
130
|
-
acts_as_taggable
|
131
|
-
|
132
|
-
# The caching column defaults to cached_tag_list, but can be changed:
|
133
|
-
#
|
134
|
-
# set_cached_tag_list_column_name "my_caching_column_name"
|
135
|
-
end
|
136
|
-
|
137
|
-
The details of the caching are handled for you. Just continue to use the tag_list accessor as you normally would.
|
138
|
-
Note that the cached tag list will not be updated if you directly create Tagging objects or manually append to the
|
139
|
-
<tt>tags</tt> or <tt>taggings</tt> associations. To update the cached tag list you should call <tt>save_cached_tag_list</tt> manually.
|
140
|
-
|
141
|
-
=== Delimiter
|
142
|
-
|
143
|
-
If you want to change the delimiter used to parse and present tags, set TagList.delimiter.
|
144
|
-
For example, to use spaces instead of commas, add the following to config/environment.rb:
|
145
|
-
|
146
|
-
TagList.delimiter = " "
|
147
|
-
|
148
|
-
=== Unused tags
|
149
|
-
|
150
|
-
Set Tag.destroy_unused to remove tags when they are no longer being
|
151
|
-
used to tag any objects. Defaults to false.
|
152
|
-
|
153
|
-
Tag.destroy_unused = true
|
154
|
-
|
155
|
-
=== Other
|
156
|
-
|
157
|
-
Problems, comments, and suggestions all welcome. jonathan.viney@gmail.com
|
@@ -1,54 +0,0 @@
|
|
1
|
-
Gem::Specification.new do |s|
|
2
|
-
s.name = "bborn-acts_as_taggable_on_steroids"
|
3
|
-
s.version = "2.0.beta3"
|
4
|
-
s.date = "2011-02-07"
|
5
|
-
s.summary = "Rails 3 plugin that is based on acts_as_taggable by jviney that is based on acts_as_taggable by DHH."
|
6
|
-
s.email = "ysbaddaden@gmail.com"
|
7
|
-
s.homepage = "http://github.com/ysbaddaden/acts_as_taggable_on_steroids"
|
8
|
-
s.description = "Rails plugin that is based on acts_as_taggable by jviney that is based on acts_as_taggable by DHH."
|
9
|
-
s.has_rdoc = true
|
10
|
-
s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
|
11
|
-
s.rubyforge_project = "acts_as_taggable_on_steroids"
|
12
|
-
s.authors = ["Jonathan Viney", "Julien Portalier"]
|
13
|
-
s.files = [
|
14
|
-
"acts_as_taggable_on_steroids.gemspec",
|
15
|
-
"CHANGELOG",
|
16
|
-
"init.rb",
|
17
|
-
"lib/acts_as_taggable.rb",
|
18
|
-
"lib/generators/acts_as_taggable_migration",
|
19
|
-
"lib/generators/acts_as_taggable_migration/acts_as_taggable_migration_generator.rb",
|
20
|
-
"lib/generators/acts_as_taggable_migration/templates",
|
21
|
-
"lib/generators/acts_as_taggable_migration/templates/migration.rb",
|
22
|
-
"lib/tag.rb",
|
23
|
-
"lib/tag_list.rb",
|
24
|
-
"lib/tagging.rb",
|
25
|
-
"lib/tags_helper.rb",
|
26
|
-
"MIT-LICENSE",
|
27
|
-
"Rakefile",
|
28
|
-
"README",
|
29
|
-
]
|
30
|
-
s.test_files = [
|
31
|
-
"test/abstract_unit.rb",
|
32
|
-
"test/acts_as_taggable_test.rb",
|
33
|
-
"test/database.yml",
|
34
|
-
"test/fixtures",
|
35
|
-
"test/fixtures/magazine.rb",
|
36
|
-
"test/fixtures/magazines.yml",
|
37
|
-
"test/fixtures/photo.rb",
|
38
|
-
"test/fixtures/photos.yml",
|
39
|
-
"test/fixtures/post.rb",
|
40
|
-
"test/fixtures/posts.yml",
|
41
|
-
"test/fixtures/special_post.rb",
|
42
|
-
"test/fixtures/subscription.rb",
|
43
|
-
"test/fixtures/subscriptions.yml",
|
44
|
-
"test/fixtures/taggings.yml",
|
45
|
-
"test/fixtures/tags.yml",
|
46
|
-
"test/fixtures/user.rb",
|
47
|
-
"test/fixtures/users.yml",
|
48
|
-
"test/schema.rb",
|
49
|
-
"test/tag_list_test.rb",
|
50
|
-
"test/tag_test.rb",
|
51
|
-
"test/tagging_test.rb",
|
52
|
-
"test/tags_helper_test.rb"
|
53
|
-
]
|
54
|
-
end
|
data/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/lib/acts_as_taggable'
|
data/test/abstract_unit.rb
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
|
3
|
-
begin
|
4
|
-
require File.dirname(__FILE__) + '/../../../../config/environment'
|
5
|
-
rescue LoadError
|
6
|
-
require 'rubygems'
|
7
|
-
gem 'activesupport'
|
8
|
-
gem 'activerecord'
|
9
|
-
gem 'actionpack'
|
10
|
-
require 'active_support/dependencies'
|
11
|
-
require 'active_record'
|
12
|
-
require 'action_controller'
|
13
|
-
end
|
14
|
-
|
15
|
-
# Search for fixtures first
|
16
|
-
fixture_path = File.dirname(__FILE__) + '/fixtures/'
|
17
|
-
ActiveSupport::Dependencies.autoload_paths.insert(0, fixture_path)
|
18
|
-
|
19
|
-
require "active_record/test_case"
|
20
|
-
require "active_record/fixtures"
|
21
|
-
|
22
|
-
require File.dirname(__FILE__) + '/../lib/acts_as_taggable'
|
23
|
-
require_dependency File.dirname(__FILE__) + '/../lib/tag_list'
|
24
|
-
require_dependency File.dirname(__FILE__) + '/../lib/tags_helper'
|
25
|
-
|
26
|
-
ENV['DB'] ||= 'sqlite3'
|
27
|
-
|
28
|
-
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + '/debug.log')
|
29
|
-
ActiveRecord::Base.configurations = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
|
30
|
-
ActiveRecord::Base.establish_connection(ENV['DB'])
|
31
|
-
|
32
|
-
load(File.dirname(__FILE__) + '/schema.rb')
|
33
|
-
|
34
|
-
class ActiveSupport::TestCase #:nodoc:
|
35
|
-
include ActiveRecord::TestFixtures
|
36
|
-
|
37
|
-
self.fixture_path = File.dirname(__FILE__) + "/fixtures/"
|
38
|
-
|
39
|
-
self.use_transactional_fixtures = true
|
40
|
-
self.use_instantiated_fixtures = false
|
41
|
-
|
42
|
-
fixtures :all
|
43
|
-
|
44
|
-
def assert_equivalent(expected, actual, message = nil)
|
45
|
-
if expected.first.is_a?(ActiveRecord::Base)
|
46
|
-
assert_equal expected.sort_by(&:id), actual.sort_by(&:id), message
|
47
|
-
else
|
48
|
-
assert_equal expected.sort, actual.sort, message
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def assert_tag_counts(tags, expected_values)
|
53
|
-
# Map the tag fixture names to real tag names
|
54
|
-
expected_values = expected_values.inject({}) do |hash, (tag, count)|
|
55
|
-
hash[tags(tag).name] = count
|
56
|
-
hash
|
57
|
-
end
|
58
|
-
|
59
|
-
tags.each do |tag|
|
60
|
-
value = expected_values.delete(tag.name)
|
61
|
-
|
62
|
-
assert_not_nil value, "Expected count for #{tag.name} was not provided"
|
63
|
-
assert_equal value, tag.count, "Expected value of #{value} for #{tag.name}, but was #{tag.count}"
|
64
|
-
end
|
65
|
-
|
66
|
-
unless expected_values.empty?
|
67
|
-
assert false, "The following tag counts were not present: #{expected_values.inspect}"
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def assert_queries(num = 1)
|
72
|
-
$query_count = 0
|
73
|
-
yield
|
74
|
-
ensure
|
75
|
-
assert_equal num, $query_count, "#{$query_count} instead of #{num} queries were executed."
|
76
|
-
end
|
77
|
-
|
78
|
-
def assert_no_queries(&block)
|
79
|
-
assert_queries(0, &block)
|
80
|
-
end
|
81
|
-
|
82
|
-
# From Rails trunk
|
83
|
-
def assert_difference(expressions, difference = 1, message = nil, &block)
|
84
|
-
expression_evaluations = [expressions].flatten.collect{|expression| lambda { eval(expression, block.binding) } }
|
85
|
-
|
86
|
-
original_values = expression_evaluations.inject([]) { |memo, expression| memo << expression.call }
|
87
|
-
yield
|
88
|
-
expression_evaluations.each_with_index do |expression, i|
|
89
|
-
assert_equal original_values[i] + difference, expression.call, message
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def assert_no_difference(expressions, message = nil, &block)
|
94
|
-
assert_difference expressions, 0, message, &block
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
ActiveRecord::Base.connection.class.class_eval do
|
99
|
-
def execute_with_counting(sql, name = nil, &block)
|
100
|
-
$query_count ||= 0
|
101
|
-
$query_count += 1
|
102
|
-
execute_without_counting(sql, name, &block)
|
103
|
-
end
|
104
|
-
|
105
|
-
alias_method_chain :execute, :counting
|
106
|
-
end
|