acts_as_favorite 0.1
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/MIT-LICENSE +20 -0
- data/README +53 -0
- data/Rakefile +38 -0
- data/about.yml +8 -0
- data/generators/favorite_model/USAGE +20 -0
- data/generators/favorite_model/favorite_model_generator.rb +35 -0
- data/generators/favorite_model/templates/fixtures.yml +5 -0
- data/generators/favorite_model/templates/migration.rb +15 -0
- data/generators/favorite_model/templates/model.rb +5 -0
- data/generators/favorite_model/templates/unit_test.rb +10 -0
- data/init.rb +1 -0
- data/install.rb +1 -0
- data/lib/acts_as_favorite.rb +111 -0
- data/lib/identity.rb +28 -0
- data/tasks/acts_as_favorite_tasks.rake +4 -0
- data/test/acts_as_favorite_test.rb +79 -0
- data/test/database.yml +18 -0
- data/test/fixtures/books.yml +11 -0
- data/test/fixtures/drinks.yml +15 -0
- data/test/fixtures/favorites.yml +23 -0
- data/test/fixtures/users.yml +15 -0
- data/test/schema.rb +24 -0
- data/test/test_helper.rb +44 -0
- metadata +79 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2006 Josh B Martin
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
= ActsAsFavorite
|
2
|
+
|
3
|
+
http://svn.webwideconsulting.com/svn/acts_as_favorite
|
4
|
+
|
5
|
+
This plugin provides a simple way to track users favorites within the system using
|
6
|
+
ActiveRecord models.
|
7
|
+
|
8
|
+
|
9
|
+
== Requirements
|
10
|
+
As we are not generating anything and there is no config, it is assumed in this version
|
11
|
+
that your user class is named "User", and you dont have an existing "Favorite" class.
|
12
|
+
|
13
|
+
== Installation and Configuration
|
14
|
+
|
15
|
+
1) Install as a plugin using script/plugin.
|
16
|
+
2) Generate the Favorite model, migrations, and tests with
|
17
|
+
./script/generate favorite_model Favorite
|
18
|
+
3) rake migrate to create the required tables
|
19
|
+
4) add <tt>acts_as_favorite_user</tt> to your User model
|
20
|
+
5) add <tt>acts_as_favorite</tt> to any models which you want to provide to users for favorites.
|
21
|
+
|
22
|
+
== The Specifics
|
23
|
+
|
24
|
+
Below are some specifics of using the plugin...
|
25
|
+
|
26
|
+
=== Setting and Using favorites
|
27
|
+
|
28
|
+
To Set:
|
29
|
+
current_user.has_favorite(Blog.find(43))
|
30
|
+
|
31
|
+
To Test(returns true/false):
|
32
|
+
current_user.has_favorite?(Blog.find(99))
|
33
|
+
current_user.has_favorite_venues?
|
34
|
+
|
35
|
+
To Find:
|
36
|
+
current_user.all_favorites (all favorite referenced objects, blogs, etc)
|
37
|
+
current_user.favorite_blogs (metaprogramming references Blog entries only)
|
38
|
+
Blog.find(43).favoriting_users (returns users which have the specified blog set as a favorite)
|
39
|
+
|
40
|
+
=== Dynamic methods through the Identity mixin
|
41
|
+
|
42
|
+
The Identity mixin provides some dynamic methods for accessing favorite based information. You
|
43
|
+
can replace 'blahs' with any model class that acts_as_favorite.
|
44
|
+
|
45
|
+
user.has_favorite_blahs? --> returns true/false if the user has any favorites within the Blah class.
|
46
|
+
user.favorite_blahs --> returns an array of Blah's that are set as the users favorites.
|
47
|
+
|
48
|
+
== License
|
49
|
+
MIT License applies.
|
50
|
+
|
51
|
+
== Authors
|
52
|
+
Josh Martin
|
53
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the acts_as_favorite plugin.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.pattern = 'test/**/*_test.rb'
|
12
|
+
t.verbose = true
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Generate documentation for the acts_as_favorite plugin.'
|
16
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
17
|
+
rdoc.rdoc_dir = 'rdoc'
|
18
|
+
rdoc.title = 'ActsAsFavorite'
|
19
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
20
|
+
rdoc.rdoc_files.include('README')
|
21
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
22
|
+
end
|
23
|
+
|
24
|
+
begin
|
25
|
+
require 'jeweler'
|
26
|
+
Jeweler::Tasks.new do |gemspec|
|
27
|
+
gemspec.name = "acts_as_favorite"
|
28
|
+
gemspec.summary = "User fovorites for you web application"
|
29
|
+
gemspec.description = "This gem provides a simple way to track users favorites within the system using ActiveRecord models"
|
30
|
+
gemspec.email = "kossnocorp@gmail.com"
|
31
|
+
gemspec.homepage = "http://github.com/kossnocorp/acts_as_favorite"
|
32
|
+
gemspec.authors = ["Josh Martin"]
|
33
|
+
gemspec.version = "0.1"
|
34
|
+
end
|
35
|
+
Jeweler::GemcutterTasks.new
|
36
|
+
rescue LoadError
|
37
|
+
puts "Jeweler not available. Install it with: gem install jeweler"
|
38
|
+
end
|
data/about.yml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
author: Josh Martin
|
2
|
+
summary: Adds a flexible mechanism for tracking users favorites.
|
3
|
+
description: Adds a flexible mechanism for tracking user favorites.
|
4
|
+
homepage: http://localhost/
|
5
|
+
plugin: http://svn.webwideconsulting.com/svn/acts_as_favorite/
|
6
|
+
license: MIT
|
7
|
+
version: 1.0
|
8
|
+
rails_version: 1.0+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Description:
|
2
|
+
The favorite_model generator creates a Role model for use with the ActsAsFavorite plugin.
|
3
|
+
|
4
|
+
The generator takes a model name as its argument, which at this time must be 'Favorite'.
|
5
|
+
|
6
|
+
The generator creates a Role model class in app/models, a test suite in
|
7
|
+
test/unit, test fixtures in test/fixtures/singular_name.yml, and a migration
|
8
|
+
in db/migrate.
|
9
|
+
|
10
|
+
Example:
|
11
|
+
./script/generate favorite_model Favorite
|
12
|
+
|
13
|
+
This will create a Role model:
|
14
|
+
Model: app/models/favorite.rb
|
15
|
+
Test: test/unit/favorite_test.rb
|
16
|
+
Fixtures: test/fixtures/favorites.yml
|
17
|
+
Migration: db/migrate/XXX_add_favorites.rb
|
18
|
+
|
19
|
+
You should then run "rake migrate".
|
20
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# Shamelessly derived from Rick Olsen's acts_as_attachment
|
2
|
+
class FavoriteModelGenerator < Rails::Generator::NamedBase
|
3
|
+
default_options :skip_migration => false
|
4
|
+
|
5
|
+
def manifest
|
6
|
+
record do |m|
|
7
|
+
# Check for class naming collisions.
|
8
|
+
m.class_collisions class_path, class_name, "#{class_name}Test"
|
9
|
+
|
10
|
+
# Model, test, and fixture directories.
|
11
|
+
m.directory File.join('app/models', class_path)
|
12
|
+
m.directory File.join('test/unit', class_path)
|
13
|
+
m.directory File.join('test/fixtures', class_path)
|
14
|
+
|
15
|
+
# Model class, unit test, and fixtures.
|
16
|
+
m.template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
|
17
|
+
m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb")
|
18
|
+
m.template 'fixtures.yml', File.join('test/fixtures', class_path, "#{table_name}.yml")
|
19
|
+
|
20
|
+
unless options[:skip_migration]
|
21
|
+
m.migration_template 'migration.rb', 'db/migrate', :assigns => {
|
22
|
+
:migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
|
23
|
+
}, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
def add_options!(opt)
|
30
|
+
opt.separator ''
|
31
|
+
opt.separator 'Options:'
|
32
|
+
opt.on("--skip-migration",
|
33
|
+
"Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class <%= migration_name %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :<%= table_name %>, :force => true do |t|
|
4
|
+
t.column :user_id, :integer
|
5
|
+
t.column :favorable_type, :string, :limit => 30
|
6
|
+
t.column :favorable_id, :integer
|
7
|
+
t.column :created_at, :datetime
|
8
|
+
t.column :updated_at, :datetime
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.down
|
13
|
+
drop_table :<%= table_name %>
|
14
|
+
end
|
15
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/lib/acts_as_favorite'
|
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
puts IO.read(File.join(File.dirname(__FILE__), 'README'))
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/identity'
|
2
|
+
|
3
|
+
module ActsAsFavorite
|
4
|
+
|
5
|
+
module UserExtensions
|
6
|
+
def self.included( recipient )
|
7
|
+
recipient.extend( ClassMethods )
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def acts_as_favorite_user
|
12
|
+
has_many :favorites
|
13
|
+
has_many :favorables, :through => :favorites
|
14
|
+
include ActsAsFavorite::UserExtensions::InstanceMethods
|
15
|
+
include ActsAsFavorite::Identity::UserExtensions::InstanceMethods
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module InstanceMethods
|
20
|
+
|
21
|
+
# Returns a polymorphic array of all user favorites
|
22
|
+
def all_favorites
|
23
|
+
self.favorites.map{|f| f.favorable }
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns trur/false if the provided object is a favorite of the users
|
27
|
+
def has_favorite?( favorite_obj )
|
28
|
+
favorite = get_favorite( favorite_obj )
|
29
|
+
favorite ? self.favorites.exists?( favorite.id ) : false
|
30
|
+
end
|
31
|
+
|
32
|
+
# Sets the object as a favorite of the users
|
33
|
+
def has_favorite( favorite_obj )
|
34
|
+
favorite = get_favorite( favorite_obj )
|
35
|
+
if favorite.nil?
|
36
|
+
favorite = Favorite.create( :user_id => self.id,
|
37
|
+
:favorable_type => favorite_obj.class.to_s,
|
38
|
+
:favorable_id => favorite_obj.id )
|
39
|
+
end
|
40
|
+
favorite
|
41
|
+
end
|
42
|
+
|
43
|
+
# Removes an object from the users favorites
|
44
|
+
def has_no_favorite( favorite_obj )
|
45
|
+
favorite = get_favorite ( favorite_obj )
|
46
|
+
|
47
|
+
# ACA: The original plugin did not properly destroy the favorite.
|
48
|
+
# Instead, it just removed the element from the favorites list. If the
|
49
|
+
# favorites list was refetched from the DB, surprise! It came back!
|
50
|
+
|
51
|
+
if favorite
|
52
|
+
self.favorites.delete( favorite )
|
53
|
+
favorite_obj.favorites.delete( favorite )
|
54
|
+
favorite.destroy
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
# Returns a favorite
|
61
|
+
def get_favorite( favorite_obj )
|
62
|
+
# ACA: The original plugin did not incoorporate the user id. This
|
63
|
+
# meant that the has_many associations did not find favorites
|
64
|
+
# properly.
|
65
|
+
Favorite.find( :first,
|
66
|
+
:conditions => [ 'user_id = ? AND favorable_type = ? AND favorable_id = ?',
|
67
|
+
self.id, favorite_obj.class.to_s, favorite_obj.id ] )
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
module ModelExtensions
|
74
|
+
def self.included( recipient )
|
75
|
+
recipient.extend( ClassMethods )
|
76
|
+
end
|
77
|
+
|
78
|
+
module ClassMethods
|
79
|
+
def acts_as_favorite
|
80
|
+
has_many :favorites, :as => :favorable
|
81
|
+
has_many :favoriting_users, :through => :favorites, :source => :user
|
82
|
+
|
83
|
+
# ACA: The original plugin included unnecessary repetitions of the
|
84
|
+
# instance method definitions as well as the below include.
|
85
|
+
|
86
|
+
include ActsAsFavorite::ModelExtensions::InstanceMethods
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
module InstanceMethods
|
91
|
+
def accepts_favorite?( user_obj )
|
92
|
+
user_obj.has_favorite?( self )
|
93
|
+
end
|
94
|
+
|
95
|
+
def accepts_favorite( user_obj )
|
96
|
+
user_obj.has_favorite( self )
|
97
|
+
end
|
98
|
+
|
99
|
+
def accepts_no_favorite( user_obj )
|
100
|
+
user_obj.has_no_favorite( self )
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
ActiveRecord::Base.send( :include,
|
109
|
+
ActsAsFavorite::UserExtensions,
|
110
|
+
ActsAsFavorite::ModelExtensions
|
111
|
+
)
|
data/lib/identity.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module ActsAsFavorite
|
2
|
+
module Identity
|
3
|
+
|
4
|
+
module UserExtensions
|
5
|
+
module InstanceMethods
|
6
|
+
|
7
|
+
def method_missing( method_sym, *args )
|
8
|
+
if method_sym.to_s =~ Regexp.new("^favorite_(\\w+)")
|
9
|
+
favorite_class = ($1).singularize.classify.constantize
|
10
|
+
favorite_class.find(:all, :include => :favorites,
|
11
|
+
:conditions => ['favorites.user_id = ? AND favorites.favorable_type = ?',
|
12
|
+
id, favorite_class.to_s ] )
|
13
|
+
elsif method_sym.to_s =~ Regexp.new("^has_favorite_(\\w+)\\?")
|
14
|
+
favorite_class = ($1).singularize.classify.constantize
|
15
|
+
Favorite.count( :include => :user, :conditions => [ 'favorites.user_id = ? AND favorites.favorable_type = ?',
|
16
|
+
id, favorite_class.to_s ] ) != 0
|
17
|
+
else
|
18
|
+
super
|
19
|
+
end
|
20
|
+
rescue
|
21
|
+
super
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class User < ActiveRecord::Base
|
4
|
+
acts_as_favorite_user
|
5
|
+
end
|
6
|
+
|
7
|
+
class Favorite < ActiveRecord::Base
|
8
|
+
belongs_to :user
|
9
|
+
belongs_to :favorable, :polymorphic => true
|
10
|
+
end
|
11
|
+
|
12
|
+
class Book < ActiveRecord::Base
|
13
|
+
acts_as_favorite
|
14
|
+
end
|
15
|
+
|
16
|
+
class Drink < ActiveRecord::Base
|
17
|
+
acts_as_favorite
|
18
|
+
end
|
19
|
+
|
20
|
+
class ActsAsFavoriteTest < Test::Unit::TestCase
|
21
|
+
fixtures :users, :books, :drinks, :favorites
|
22
|
+
|
23
|
+
def test_user_should_have_favorites
|
24
|
+
assert users(:josh).has_favorites?
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_should_create_favorite
|
28
|
+
assert_difference users(:james).favorites, :count do
|
29
|
+
users(:james).has_favorite books(:agile)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_dynamic_counter_should_return_true
|
34
|
+
assert users(:josh).has_favorite_books?
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_should_return_false_with_no_favorite_books
|
38
|
+
assert_equal users(:george).has_favorite_books?, false
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_should_add_items_to_favorites
|
42
|
+
assert_difference Favorite, :count do
|
43
|
+
users(:james).has_favorite drinks(:wine)
|
44
|
+
assert users(:james).has_favorite?(drinks(:wine))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_should_remove_from_favorites
|
49
|
+
assert_difference users(:josh).favorites, :count, -1 do
|
50
|
+
users(:josh).has_no_favorite drinks(:beer)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_should_return_users_with_specified_favorite
|
55
|
+
assert books(:ruby).favorite_users.include?(users(:josh))
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_should_add_and_remove_favorites
|
59
|
+
|
60
|
+
assert users(:george).favorites.empty?
|
61
|
+
|
62
|
+
assert_difference users(:george).favorites, :count, 3 do
|
63
|
+
users(:george).has_favorite books(:agile)
|
64
|
+
users(:george).has_favorite books(:ruby)
|
65
|
+
users(:george).has_favorite books(:rails)
|
66
|
+
end
|
67
|
+
assert_equal users(:george).favorites.size, 3
|
68
|
+
assert users(:george).favorite_books.size, 3
|
69
|
+
|
70
|
+
assert_difference users(:george).favorites, :count, -2 do
|
71
|
+
users(:george).has_no_favorite books(:agile)
|
72
|
+
users(:george).has_no_favorite books(:ruby)
|
73
|
+
end
|
74
|
+
assert_equal users(:george).favorites.size, 1
|
75
|
+
assert users(:george).favorite_books.size, 1
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
data/test/database.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
sqlite:
|
2
|
+
:adapter: sqlite
|
3
|
+
:dbfile: acts_as_favorite_plugin.sqlite.db
|
4
|
+
sqlite3:
|
5
|
+
:adapter: sqlite3
|
6
|
+
:dbfile: acts_as_favorite_plugin.sqlite3.db
|
7
|
+
postgresql:
|
8
|
+
:adapter: postgresql
|
9
|
+
:username: postgres
|
10
|
+
:password: postgres
|
11
|
+
:database: acts_as_favorite_plugin_test
|
12
|
+
:min_messages: ERROR
|
13
|
+
mysql:
|
14
|
+
:adapter: mysql
|
15
|
+
:host: localhost
|
16
|
+
:username: rails
|
17
|
+
:password:
|
18
|
+
:database: acts_as_favorite_plugin_test
|
@@ -0,0 +1,23 @@
|
|
1
|
+
josh_ruby:
|
2
|
+
id: 1
|
3
|
+
user_id: 1
|
4
|
+
favorable_type: Book
|
5
|
+
favorable_id: 1
|
6
|
+
|
7
|
+
josh_agile:
|
8
|
+
id: 2
|
9
|
+
user_id: 1
|
10
|
+
favorable_type: Book
|
11
|
+
favorable_id: 2
|
12
|
+
|
13
|
+
josh_rails:
|
14
|
+
id: 3
|
15
|
+
user_id: 1
|
16
|
+
favorable_type: Book
|
17
|
+
favorable_id: 3
|
18
|
+
|
19
|
+
josh_beer:
|
20
|
+
id: 4
|
21
|
+
user_id : 1
|
22
|
+
favorable_type: Drink
|
23
|
+
favorable_id: 1
|
data/test/schema.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
ActiveRecord::Schema.define(:version => 1) do
|
2
|
+
|
3
|
+
create_table :users, :force => true do |t|
|
4
|
+
t.column :name, :string, :limit => 50
|
5
|
+
end
|
6
|
+
|
7
|
+
create_table :favorites, :force => true do |t|
|
8
|
+
t.column :user_id, :integer
|
9
|
+
t.column :favorable_id, :integer
|
10
|
+
t.column :favorable_type, :string, :limit => 30
|
11
|
+
t.column :created_at, :datetime
|
12
|
+
t.column :updated_at, :datetime
|
13
|
+
end
|
14
|
+
|
15
|
+
create_table :books, :force => true do |t|
|
16
|
+
t.column :title, :string, :limit => 30
|
17
|
+
end
|
18
|
+
|
19
|
+
create_table :drinks, :force => true do |t|
|
20
|
+
t.column :title, :string, :limit => 30
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../../../../config/environment.rb'))
|
5
|
+
require 'rubygems'
|
6
|
+
require 'active_support/breakpoint'
|
7
|
+
require 'active_record/fixtures'
|
8
|
+
|
9
|
+
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
|
10
|
+
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
|
11
|
+
ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite'])
|
12
|
+
|
13
|
+
load(File.dirname(__FILE__) + "/schema.rb")
|
14
|
+
|
15
|
+
Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures/"
|
16
|
+
$LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path)
|
17
|
+
|
18
|
+
class Test::Unit::TestCase #:nodoc:
|
19
|
+
def create_fixtures(*table_names)
|
20
|
+
if block_given?
|
21
|
+
Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) { yield }
|
22
|
+
else
|
23
|
+
Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Turn off transactional fixtures if you're working with MyISAM tables in MySQL
|
28
|
+
self.use_transactional_fixtures = true
|
29
|
+
|
30
|
+
# Instantiated fixtures are slow, but give you @david where you otherwise would need people(:david)
|
31
|
+
self.use_instantiated_fixtures = false
|
32
|
+
|
33
|
+
# Add more helper methods to be used by all tests here...
|
34
|
+
def assert_difference(object, method = nil, difference = 1)
|
35
|
+
initial_value = object.send(method)
|
36
|
+
yield
|
37
|
+
assert_equal initial_value + difference, object.send(method), "#{object}##{method}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def assert_no_difference(object, method, &block)
|
41
|
+
assert_difference object, method, 0, &block
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acts_as_favorite
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Josh Martin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-08 00:00:00 +06:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: This gem provides a simple way to track users favorites within the system using ActiveRecord models
|
17
|
+
email: kossnocorp@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
files:
|
25
|
+
- MIT-LICENSE
|
26
|
+
- README
|
27
|
+
- Rakefile
|
28
|
+
- about.yml
|
29
|
+
- generators/favorite_model/USAGE
|
30
|
+
- generators/favorite_model/favorite_model_generator.rb
|
31
|
+
- generators/favorite_model/templates/fixtures.yml
|
32
|
+
- generators/favorite_model/templates/migration.rb
|
33
|
+
- generators/favorite_model/templates/model.rb
|
34
|
+
- generators/favorite_model/templates/unit_test.rb
|
35
|
+
- init.rb
|
36
|
+
- install.rb
|
37
|
+
- lib/acts_as_favorite.rb
|
38
|
+
- lib/identity.rb
|
39
|
+
- tasks/acts_as_favorite_tasks.rake
|
40
|
+
- test/acts_as_favorite_test.rb
|
41
|
+
- test/database.yml
|
42
|
+
- test/fixtures/books.yml
|
43
|
+
- test/fixtures/drinks.yml
|
44
|
+
- test/fixtures/favorites.yml
|
45
|
+
- test/fixtures/users.yml
|
46
|
+
- test/schema.rb
|
47
|
+
- test/test_helper.rb
|
48
|
+
has_rdoc: true
|
49
|
+
homepage: http://github.com/kossnocorp/acts_as_favorite
|
50
|
+
licenses: []
|
51
|
+
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options:
|
54
|
+
- --charset=UTF-8
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
version:
|
69
|
+
requirements: []
|
70
|
+
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.3.5
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: User fovorites for you web application
|
76
|
+
test_files:
|
77
|
+
- test/acts_as_favorite_test.rb
|
78
|
+
- test/schema.rb
|
79
|
+
- test/test_helper.rb
|