scoped-tags 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,5 @@
1
1
  ---
2
- :patch: 1
2
+ :patch: 0
3
3
  :major: 0
4
- :minor: 3
4
+ :minor: 4
5
+ :build:
@@ -1,4 +1,4 @@
1
- class ScopedTagsGenerator < Rails::Generator::Base
1
+ class ScopedTagsMigrationGenerator < Rails::Generator::Base
2
2
  def manifest
3
3
  record do |m|
4
4
  m.migration_template 'migration.rb', 'db/migrate', :migration_file_name => "scoped_tags_migration"
@@ -1,64 +1,64 @@
1
1
  module ScopedTags
2
-
2
+
3
3
  module ActiveRecordAdditions
4
-
4
+
5
5
  def self.included(base)
6
6
  base.class_eval do
7
7
  def self.scoped_tags(contexts, options = nil)
8
8
  self.class.instance_eval{ attr_accessor :tag_contexts }
9
-
9
+
10
10
  raise ScopedTagsError, 'context is required for scoped-tags setup' if contexts.blank?
11
-
11
+
12
12
  self.tag_contexts = [contexts].flatten
13
-
14
- has_many :taggings, :as => :taggable, :class_name => 'Tagging', :dependent => :delete_all
15
- has_many :tags, :through => :taggings, :class_name => 'Tag', :readonly => true
16
-
13
+
14
+ has_many :taggings, :as => :taggable, :class_name => 'Tagging', :dependent => :delete_all
15
+ has_many :base_tags, :through => :taggings, :class_name => 'Tag', :source => :tag, :readonly => true
16
+
17
17
  self.tag_contexts.each do |context|
18
18
  has_many context, :through => :taggings, :class_name => 'Tag',
19
19
  :source => :tag,
20
- :conditions => ['context = ?', context.to_s.downcase]
21
-
20
+ :conditions => { :context => context.to_s.downcase }
21
+
22
22
  c = context.to_s.singularize
23
23
  define_method("#{c}_list") { get_tag_list(context) }
24
24
  define_method("#{c}_list=") { |new_list| set_tag_list(context, new_list) }
25
25
  self.class.instance_eval do
26
26
  define_method("tagged_with_#{context}") { |*args| find_tagged_with(args.first, context.to_s, args.extract_options!) }
27
27
  end
28
- end
29
-
28
+ end
29
+
30
30
  self.send :extend, ClassMethods
31
31
  self.send :include, InstanceMethods
32
32
  end
33
33
  end
34
34
  end
35
-
36
-
35
+
36
+
37
37
  module ClassMethods
38
38
  def find_tagged_with(tag_names, context, options = {})
39
39
  tag_names = tag_names.is_a?(Array) ? tag_names : tag_names.split(TagListCollection.delimiter)
40
40
  tag_names = tag_names.collect(&:strip).reject(&:blank?)
41
-
42
- required_options = { :include => [:taggings, :tags],
41
+
42
+ required_options = { :include => [:taggings, :base_tags],
43
43
  :conditions => ['tags.name IN (?) AND tags.context = ?', tag_names, context] }
44
-
44
+
45
45
  self.all(options.merge(required_options))
46
46
  end
47
47
  end
48
48
 
49
-
49
+
50
50
  module InstanceMethods
51
51
  protected
52
52
  def get_tag_list(context)
53
53
  @tag_list_collections = { } if not @tag_list_collections
54
54
  @tag_list_collections[context] ||= TagListCollection.new(self, context.to_s.downcase)
55
55
  end
56
-
56
+
57
57
  def set_tag_list(context, new_tags)
58
58
  get_tag_list(context).replace(new_tags)
59
- end
59
+ end
60
60
  end
61
-
61
+
62
62
  end
63
-
63
+
64
64
  end
@@ -2,7 +2,7 @@ class Tagging < ActiveRecord::Base
2
2
  belongs_to :tag
3
3
  belongs_to :taggable, :polymorphic => true
4
4
 
5
- validates_uniqueness_of :taggable_id, :scope => :tag_id
5
+ validates_uniqueness_of :taggable_id, :scope => [:tag_id, :taggable_type]
6
6
 
7
7
  attr_accessible :taggable_type, :taggable_id, :tag_id
8
8
  end
data/readme.md CHANGED
@@ -26,12 +26,31 @@ Key Features
26
26
  - tags are available for use in the validations as they are always kept in sync
27
27
 
28
28
 
29
+ Installation
30
+ ------------
31
+
32
+ ./script/plugin install git://github.com/joshk/scoped-tags.git
33
+
34
+ or
35
+
36
+ gem install scoped-tags --source http://gemcutter.org
37
+
38
+ although it is highly recommended that you install the gemcutter gem and set gemcutter as your default gem repository.
39
+
40
+ If you are using rails you can also use:
41
+
42
+ config.gem 'scoped-tags', :source => 'http://gemcutter.org' # source not needed if gemcutter is installed
43
+
44
+ To generate the migration file use:
45
+
46
+ ./script/generate scoped_tags_migration
47
+
29
48
 
30
49
  How can I use it?
31
50
  -----------------
32
51
 
33
52
  class Person
34
- scoped_tags :genres
53
+ scoped_tags :interests
35
54
  end
36
55
 
37
56
  me = Person.new(:name => 'Josh')
@@ -1 +1,256 @@
1
1
  # Logfile created on Sat Oct 17 19:04:03 +0200 2009 by logger.rb/22285
2
+ SQL (0.5ms) select sqlite_version(*)
3
+ SQL (0.3ms)  SELECT name
4
+ FROM sqlite_master
5
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
6
+ 
7
+ SQL (0.6ms) CREATE TABLE "scoped_tagged_models" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
8
+ SQL (0.1ms)  SELECT name
9
+ FROM sqlite_master
10
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
11
+ 
12
+ SQL (0.1ms) CREATE TABLE "tags" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "context" varchar(255)) 
13
+ SQL (0.1ms)  SELECT name
14
+ FROM sqlite_master
15
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
16
+ 
17
+ SQL (0.1ms) CREATE TABLE "taggings" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "tag_id" integer, "taggable_id" integer, "taggable_type" varchar(255)) 
18
+ SQL (0.2ms) CREATE INDEX "index_tags_on_context_and_name" ON "tags" ("context", "name")
19
+ SQL (0.1ms) CREATE INDEX "index_taggings_on_taggable_id_and_taggable_type" ON "taggings" ("taggable_id", "taggable_type")
20
+ SQL (0.3ms)  SELECT name
21
+ FROM sqlite_master
22
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
23
+ 
24
+ SQL (0.3ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
25
+ SQL (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
26
+ SQL (0.2ms)  SELECT name
27
+ FROM sqlite_master
28
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
29
+ 
30
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
31
+ SQL (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
32
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'pop' and context = 'genres') LIMIT 1
33
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'blues' and context = 'genres') LIMIT 1
34
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'blues' and context = 'genres') LIMIT 1
35
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'rock' and context = 'genres') LIMIT 1
36
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'country' and context = 'genres') LIMIT 1
37
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'blues' and context = 'genres') LIMIT 1
38
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'blues' and context = 'genres') LIMIT 1
39
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'pop' and context = 'genres') LIMIT 1
40
+ Tag Load (0.2ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'rock' AND "tags".context = 'genres') LIMIT 1
41
+ Tag Load (0.1ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'pop' AND "tags".context = 'genres') LIMIT 1
42
+ ScopedTaggedModel Create (0.1ms) INSERT INTO "scoped_tagged_models" ("name") VALUES(NULL)
43
+ Tag Load (0.1ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'rock' AND "tags".context = 'genres') LIMIT 1
44
+ Tag Create (0.1ms) INSERT INTO "tags" ("name", "context") VALUES('rock', 'genres')
45
+ Tagging Load (0.1ms) SELECT "taggings".id FROM "taggings" WHERE ("taggings"."taggable_id" = 1 AND "taggings".tag_id = 1 AND "taggings".taggable_type = 'ScopedTaggedModel') LIMIT 1
46
+ Tagging Create (0.1ms) INSERT INTO "taggings" ("tag_id", "taggable_id", "taggable_type") VALUES(1, 1, 'ScopedTaggedModel')
47
+ Tag Load (0.1ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'pop' AND "tags".context = 'genres') LIMIT 1
48
+ Tag Create (0.1ms) INSERT INTO "tags" ("name", "context") VALUES('pop', 'genres')
49
+ Tagging Load (0.1ms) SELECT "taggings".id FROM "taggings" WHERE ("taggings"."taggable_id" = 1 AND "taggings".tag_id = 2 AND "taggings".taggable_type = 'ScopedTaggedModel') LIMIT 1
50
+ Tagging Create (0.1ms) INSERT INTO "taggings" ("tag_id", "taggable_id", "taggable_type") VALUES(2, 1, 'ScopedTaggedModel')
51
+ ScopedTaggedModel Load Including Associations (0.5ms) SELECT "scoped_tagged_models"."id" AS t0_r0, "scoped_tagged_models"."name" AS t0_r1, "taggings"."id" AS t1_r0, "taggings"."tag_id" AS t1_r1, "taggings"."taggable_id" AS t1_r2, "taggings"."taggable_type" AS t1_r3, "tags"."id" AS t2_r0, "tags"."name" AS t2_r1, "tags"."context" AS t2_r2 FROM "scoped_tagged_models" LEFT OUTER JOIN "taggings" ON "taggings".taggable_id = "scoped_tagged_models".id AND "taggings".taggable_type = 'ScopedTaggedModel' LEFT OUTER JOIN "taggings" base_tags_scoped_tagged_models_join ON ("scoped_tagged_models"."id" = "base_tags_scoped_tagged_models_join"."taggable_id" AND "base_tags_scoped_tagged_models_join"."taggable_type" = 'ScopedTaggedModel') LEFT OUTER JOIN "tags" ON ("tags"."id" = "base_tags_scoped_tagged_models_join"."tag_id") WHERE (tags.name IN ('pop') AND tags.context = 'genres') 
52
+ ScopedTaggedModel Load Including Associations (0.5ms) SELECT "scoped_tagged_models"."id" AS t0_r0, "scoped_tagged_models"."name" AS t0_r1, "taggings"."id" AS t1_r0, "taggings"."tag_id" AS t1_r1, "taggings"."taggable_id" AS t1_r2, "taggings"."taggable_type" AS t1_r3, "tags"."id" AS t2_r0, "tags"."name" AS t2_r1, "tags"."context" AS t2_r2 FROM "scoped_tagged_models" LEFT OUTER JOIN "taggings" ON "taggings".taggable_id = "scoped_tagged_models".id AND "taggings".taggable_type = 'ScopedTaggedModel' LEFT OUTER JOIN "taggings" base_tags_scoped_tagged_models_join ON ("scoped_tagged_models"."id" = "base_tags_scoped_tagged_models_join"."taggable_id" AND "base_tags_scoped_tagged_models_join"."taggable_type" = 'ScopedTaggedModel') LEFT OUTER JOIN "tags" ON ("tags"."id" = "base_tags_scoped_tagged_models_join"."tag_id") WHERE (tags.name IN ('pop') AND tags.context = 'genres') 
53
+ ScopedTaggedModel Delete all (0.1ms) DELETE FROM "scoped_tagged_models" WHERE 1=1
54
+ Tag Load (0.2ms) SELECT * FROM "tags" WHERE (name = 'pop' and context = 'genres') LIMIT 1
55
+ Tag Load (0.1ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'pop' AND "tags".context = 'genres' AND "tags".id <> 2) LIMIT 1
56
+ ScopedTaggedModel Create (0.1ms) INSERT INTO "scoped_tagged_models" ("name") VALUES(NULL)
57
+ Tagging Load (0.1ms) SELECT "taggings".id FROM "taggings" WHERE ("taggings"."taggable_id" = 2 AND "taggings".tag_id = 2 AND "taggings".taggable_type = 'ScopedTaggedModel') LIMIT 1
58
+ Tagging Create (0.1ms) INSERT INTO "taggings" ("tag_id", "taggable_id", "taggable_type") VALUES(2, 2, 'ScopedTaggedModel')
59
+ Tag Load (0.2ms) SELECT * FROM "tags" WHERE (name = 'pop' and context = 'genres') LIMIT 1
60
+ Tag Load (0.1ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'pop' AND "tags".context = 'genres' AND "tags".id <> 2) LIMIT 1
61
+ ScopedTaggedModel Create (0.1ms) INSERT INTO "scoped_tagged_models" ("name") VALUES(NULL)
62
+ Tagging Load (0.1ms) SELECT "taggings".id FROM "taggings" WHERE ("taggings"."taggable_id" = 3 AND "taggings".tag_id = 2 AND "taggings".taggable_type = 'ScopedTaggedModel') LIMIT 1
63
+ Tagging Create (0.1ms) INSERT INTO "taggings" ("tag_id", "taggable_id", "taggable_type") VALUES(2, 3, 'ScopedTaggedModel')
64
+ ScopedTaggedModel Load IDs For Limited Eager Loading (0.2ms) SELECT DISTINCT "scoped_tagged_models".id FROM "scoped_tagged_models" LEFT OUTER JOIN "taggings" base_tags_scoped_tagged_models_join ON ("scoped_tagged_models"."id" = "base_tags_scoped_tagged_models_join"."taggable_id" AND "base_tags_scoped_tagged_models_join"."taggable_type" = 'ScopedTaggedModel') LEFT OUTER JOIN "tags" ON ("tags"."id" = "base_tags_scoped_tagged_models_join"."tag_id") WHERE (tags.name IN ('pop') AND tags.context = 'genres') LIMIT 1
65
+ ScopedTaggedModel Load Including Associations (0.3ms) SELECT "scoped_tagged_models"."id" AS t0_r0, "scoped_tagged_models"."name" AS t0_r1, "taggings"."id" AS t1_r0, "taggings"."tag_id" AS t1_r1, "taggings"."taggable_id" AS t1_r2, "taggings"."taggable_type" AS t1_r3, "tags"."id" AS t2_r0, "tags"."name" AS t2_r1, "tags"."context" AS t2_r2 FROM "scoped_tagged_models" LEFT OUTER JOIN "taggings" ON "taggings".taggable_id = "scoped_tagged_models".id AND "taggings".taggable_type = 'ScopedTaggedModel' LEFT OUTER JOIN "taggings" base_tags_scoped_tagged_models_join ON ("scoped_tagged_models"."id" = "base_tags_scoped_tagged_models_join"."taggable_id" AND "base_tags_scoped_tagged_models_join"."taggable_type" = 'ScopedTaggedModel') LEFT OUTER JOIN "tags" ON ("tags"."id" = "base_tags_scoped_tagged_models_join"."tag_id") WHERE (tags.name IN ('pop') AND tags.context = 'genres') AND "scoped_tagged_models".id IN (2) 
66
+ ScopedTaggedModel Delete all (0.1ms) DELETE FROM "scoped_tagged_models" WHERE 1=1
67
+ Tag Load (0.2ms) SELECT * FROM "tags" WHERE (name = 'pop' and context = 'genres') LIMIT 1
68
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'techno' and context = 'genres') LIMIT 1
69
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'dance' and context = 'genres') LIMIT 1
70
+ Tag Load (0.2ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'pop' AND "tags".context = 'genres' AND "tags".id <> 2) LIMIT 1
71
+ Tag Load (0.1ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'techno' AND "tags".context = 'genres') LIMIT 1
72
+ Tag Load (0.1ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'dance' AND "tags".context = 'genres') LIMIT 1
73
+ ScopedTaggedModel Create (0.1ms) INSERT INTO "scoped_tagged_models" ("name") VALUES(NULL)
74
+ Tagging Load (0.1ms) SELECT "taggings".id FROM "taggings" WHERE ("taggings"."taggable_id" = 4 AND "taggings".tag_id = 2 AND "taggings".taggable_type = 'ScopedTaggedModel') LIMIT 1
75
+ Tagging Create (0.1ms) INSERT INTO "taggings" ("tag_id", "taggable_id", "taggable_type") VALUES(2, 4, 'ScopedTaggedModel')
76
+ Tag Load (0.1ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'techno' AND "tags".context = 'genres') LIMIT 1
77
+ Tag Create (0.1ms) INSERT INTO "tags" ("name", "context") VALUES('techno', 'genres')
78
+ Tagging Load (0.1ms) SELECT "taggings".id FROM "taggings" WHERE ("taggings"."taggable_id" = 4 AND "taggings".tag_id = 3 AND "taggings".taggable_type = 'ScopedTaggedModel') LIMIT 1
79
+ Tagging Create (0.1ms) INSERT INTO "taggings" ("tag_id", "taggable_id", "taggable_type") VALUES(3, 4, 'ScopedTaggedModel')
80
+ Tag Load (0.1ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'dance' AND "tags".context = 'genres') LIMIT 1
81
+ Tag Create (0.1ms) INSERT INTO "tags" ("name", "context") VALUES('dance', 'genres')
82
+ Tagging Load (0.1ms) SELECT "taggings".id FROM "taggings" WHERE ("taggings"."taggable_id" = 4 AND "taggings".tag_id = 4 AND "taggings".taggable_type = 'ScopedTaggedModel') LIMIT 1
83
+ Tagging Create (0.1ms) INSERT INTO "taggings" ("tag_id", "taggable_id", "taggable_type") VALUES(4, 4, 'ScopedTaggedModel')
84
+ Tag Load (0.2ms) SELECT * FROM "tags" WHERE (name = 'pop' and context = 'genres') LIMIT 1
85
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'techno' and context = 'genres') LIMIT 1
86
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'dance' and context = 'genres') LIMIT 1
87
+ Tag Load (0.2ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'pop' AND "tags".context = 'genres' AND "tags".id <> 2) LIMIT 1
88
+ Tag Load (0.1ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'techno' AND "tags".context = 'genres' AND "tags".id <> 3) LIMIT 1
89
+ Tag Load (0.1ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'dance' AND "tags".context = 'genres' AND "tags".id <> 4) LIMIT 1
90
+ ScopedTaggedModel Create (0.1ms) INSERT INTO "scoped_tagged_models" ("name") VALUES(NULL)
91
+ Tagging Load (0.1ms) SELECT "taggings".id FROM "taggings" WHERE ("taggings"."taggable_id" = 5 AND "taggings".tag_id = 2 AND "taggings".taggable_type = 'ScopedTaggedModel') LIMIT 1
92
+ Tagging Create (0.1ms) INSERT INTO "taggings" ("tag_id", "taggable_id", "taggable_type") VALUES(2, 5, 'ScopedTaggedModel')
93
+ Tagging Load (0.1ms) SELECT "taggings".id FROM "taggings" WHERE ("taggings"."taggable_id" = 5 AND "taggings".tag_id = 3 AND "taggings".taggable_type = 'ScopedTaggedModel') LIMIT 1
94
+ Tagging Create (0.1ms) INSERT INTO "taggings" ("tag_id", "taggable_id", "taggable_type") VALUES(3, 5, 'ScopedTaggedModel')
95
+ Tagging Load (0.1ms) SELECT "taggings".id FROM "taggings" WHERE ("taggings"."taggable_id" = 5 AND "taggings".tag_id = 4 AND "taggings".taggable_type = 'ScopedTaggedModel') LIMIT 1
96
+ Tagging Create (0.1ms) INSERT INTO "taggings" ("tag_id", "taggable_id", "taggable_type") VALUES(4, 5, 'ScopedTaggedModel')
97
+ ScopedTaggedModel Load IDs For Limited Eager Loading (0.3ms) SELECT DISTINCT "scoped_tagged_models".id FROM "scoped_tagged_models" LEFT OUTER JOIN "taggings" base_tags_scoped_tagged_models_join ON ("scoped_tagged_models"."id" = "base_tags_scoped_tagged_models_join"."taggable_id" AND "base_tags_scoped_tagged_models_join"."taggable_type" = 'ScopedTaggedModel') LEFT OUTER JOIN "tags" ON ("tags"."id" = "base_tags_scoped_tagged_models_join"."tag_id") WHERE (tags.name IN ('pop','techno','dance') AND tags.context = 'genres') LIMIT 1
98
+ ScopedTaggedModel Load Including Associations (1.0ms) SELECT "scoped_tagged_models"."id" AS t0_r0, "scoped_tagged_models"."name" AS t0_r1, "taggings"."id" AS t1_r0, "taggings"."tag_id" AS t1_r1, "taggings"."taggable_id" AS t1_r2, "taggings"."taggable_type" AS t1_r3, "tags"."id" AS t2_r0, "tags"."name" AS t2_r1, "tags"."context" AS t2_r2 FROM "scoped_tagged_models" LEFT OUTER JOIN "taggings" ON "taggings".taggable_id = "scoped_tagged_models".id AND "taggings".taggable_type = 'ScopedTaggedModel' LEFT OUTER JOIN "taggings" base_tags_scoped_tagged_models_join ON ("scoped_tagged_models"."id" = "base_tags_scoped_tagged_models_join"."taggable_id" AND "base_tags_scoped_tagged_models_join"."taggable_type" = 'ScopedTaggedModel') LEFT OUTER JOIN "tags" ON ("tags"."id" = "base_tags_scoped_tagged_models_join"."tag_id") WHERE (tags.name IN ('pop','techno','dance') AND tags.context = 'genres') AND "scoped_tagged_models".id IN (4) 
99
+ ScopedTaggedModel Delete all (0.1ms) DELETE FROM "scoped_tagged_models" WHERE 1=1
100
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'pop' and context = 'genres') LIMIT 1
101
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'techno' and context = 'genres') LIMIT 1
102
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'dance' and context = 'genres') LIMIT 1
103
+ Tag Load (0.1ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'pop' AND "tags".context = 'genres' AND "tags".id <> 2) LIMIT 1
104
+ Tag Load (0.1ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'techno' AND "tags".context = 'genres' AND "tags".id <> 3) LIMIT 1
105
+ Tag Load (0.1ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'dance' AND "tags".context = 'genres' AND "tags".id <> 4) LIMIT 1
106
+ ScopedTaggedModel Create (0.1ms) INSERT INTO "scoped_tagged_models" ("name") VALUES(NULL)
107
+ Tagging Load (0.1ms) SELECT "taggings".id FROM "taggings" WHERE ("taggings"."taggable_id" = 6 AND "taggings".tag_id = 2 AND "taggings".taggable_type = 'ScopedTaggedModel') LIMIT 1
108
+ Tagging Create (0.1ms) INSERT INTO "taggings" ("tag_id", "taggable_id", "taggable_type") VALUES(2, 6, 'ScopedTaggedModel')
109
+ Tagging Load (0.1ms) SELECT "taggings".id FROM "taggings" WHERE ("taggings"."taggable_id" = 6 AND "taggings".tag_id = 3 AND "taggings".taggable_type = 'ScopedTaggedModel') LIMIT 1
110
+ Tagging Create (0.1ms) INSERT INTO "taggings" ("tag_id", "taggable_id", "taggable_type") VALUES(3, 6, 'ScopedTaggedModel')
111
+ Tagging Load (0.1ms) SELECT "taggings".id FROM "taggings" WHERE ("taggings"."taggable_id" = 6 AND "taggings".tag_id = 4 AND "taggings".taggable_type = 'ScopedTaggedModel') LIMIT 1
112
+ Tagging Create (0.1ms) INSERT INTO "taggings" ("tag_id", "taggable_id", "taggable_type") VALUES(4, 6, 'ScopedTaggedModel')
113
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'pop' and context = 'genres') LIMIT 1
114
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'techno' and context = 'genres') LIMIT 1
115
+ Tag Load (0.2ms) SELECT * FROM "tags" WHERE (name = 'dance' and context = 'genres') LIMIT 1
116
+ Tag Load (0.1ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'pop' AND "tags".context = 'genres' AND "tags".id <> 2) LIMIT 1
117
+ Tag Load (0.1ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'techno' AND "tags".context = 'genres' AND "tags".id <> 3) LIMIT 1
118
+ Tag Load (0.1ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'dance' AND "tags".context = 'genres' AND "tags".id <> 4) LIMIT 1
119
+ ScopedTaggedModel Create (0.1ms) INSERT INTO "scoped_tagged_models" ("name") VALUES(NULL)
120
+ Tagging Load (0.1ms) SELECT "taggings".id FROM "taggings" WHERE ("taggings"."taggable_id" = 7 AND "taggings".tag_id = 2 AND "taggings".taggable_type = 'ScopedTaggedModel') LIMIT 1
121
+ Tagging Create (0.1ms) INSERT INTO "taggings" ("tag_id", "taggable_id", "taggable_type") VALUES(2, 7, 'ScopedTaggedModel')
122
+ Tagging Load (0.1ms) SELECT "taggings".id FROM "taggings" WHERE ("taggings"."taggable_id" = 7 AND "taggings".tag_id = 3 AND "taggings".taggable_type = 'ScopedTaggedModel') LIMIT 1
123
+ Tagging Create (0.1ms) INSERT INTO "taggings" ("tag_id", "taggable_id", "taggable_type") VALUES(3, 7, 'ScopedTaggedModel')
124
+ Tagging Load (0.3ms) SELECT "taggings".id FROM "taggings" WHERE ("taggings"."taggable_id" = 7 AND "taggings".tag_id = 4 AND "taggings".taggable_type = 'ScopedTaggedModel') LIMIT 1
125
+ Tagging Create (0.1ms) INSERT INTO "taggings" ("tag_id", "taggable_id", "taggable_type") VALUES(4, 7, 'ScopedTaggedModel')
126
+ ScopedTaggedModel Load IDs For Limited Eager Loading (0.2ms) SELECT DISTINCT "scoped_tagged_models".id FROM "scoped_tagged_models" LEFT OUTER JOIN "taggings" base_tags_scoped_tagged_models_join ON ("scoped_tagged_models"."id" = "base_tags_scoped_tagged_models_join"."taggable_id" AND "base_tags_scoped_tagged_models_join"."taggable_type" = 'ScopedTaggedModel') LEFT OUTER JOIN "tags" ON ("tags"."id" = "base_tags_scoped_tagged_models_join"."tag_id") WHERE (tags.name IN ('pop','techno','dance') AND tags.context = 'genres') LIMIT 1
127
+ ScopedTaggedModel Load Including Associations (0.9ms) SELECT "scoped_tagged_models"."id" AS t0_r0, "scoped_tagged_models"."name" AS t0_r1, "taggings"."id" AS t1_r0, "taggings"."tag_id" AS t1_r1, "taggings"."taggable_id" AS t1_r2, "taggings"."taggable_type" AS t1_r3, "tags"."id" AS t2_r0, "tags"."name" AS t2_r1, "tags"."context" AS t2_r2 FROM "scoped_tagged_models" LEFT OUTER JOIN "taggings" ON "taggings".taggable_id = "scoped_tagged_models".id AND "taggings".taggable_type = 'ScopedTaggedModel' LEFT OUTER JOIN "taggings" base_tags_scoped_tagged_models_join ON ("scoped_tagged_models"."id" = "base_tags_scoped_tagged_models_join"."taggable_id" AND "base_tags_scoped_tagged_models_join"."taggable_type" = 'ScopedTaggedModel') LEFT OUTER JOIN "tags" ON ("tags"."id" = "base_tags_scoped_tagged_models_join"."tag_id") WHERE (tags.name IN ('pop','techno','dance') AND tags.context = 'genres') AND "scoped_tagged_models".id IN (6) 
128
+ SQL (0.2ms)  SELECT name
129
+ FROM sqlite_master
130
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
131
+ 
132
+ SQL (0.1ms) DROP TABLE "scoped_tagged_models"
133
+ SQL (0.1ms) CREATE TABLE "scoped_tagged_models" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
134
+ SQL (0.2ms)  SELECT name
135
+ FROM sqlite_master
136
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
137
+ 
138
+ SQL (0.1ms) DROP TABLE "tags"
139
+ SQL (0.1ms) CREATE TABLE "tags" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "context" varchar(255)) 
140
+ SQL (0.2ms)  SELECT name
141
+ FROM sqlite_master
142
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
143
+ 
144
+ SQL (0.1ms) DROP TABLE "taggings"
145
+ SQL (0.1ms) CREATE TABLE "taggings" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "tag_id" integer, "taggable_id" integer, "taggable_type" varchar(255)) 
146
+ SQL (0.1ms) CREATE INDEX "index_tags_on_context_and_name" ON "tags" ("context", "name")
147
+ SQL (0.1ms) CREATE INDEX "index_taggings_on_taggable_id_and_taggable_type" ON "taggings" ("taggable_id", "taggable_type")
148
+ SQL (0.2ms)  SELECT name
149
+ FROM sqlite_master
150
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
151
+ 
152
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
153
+ Tagging Load (0.1ms) SELECT "taggings".id FROM "taggings" WHERE ("taggings"."taggable_id" = 1 AND "taggings".tag_id = 1 AND "taggings".taggable_type = 'Context1') LIMIT 1
154
+ Tagging Create (0.1ms) INSERT INTO "taggings" ("tag_id", "taggable_id", "taggable_type") VALUES(1, 1, 'Context1')
155
+ Tagging Load (0.2ms) SELECT * FROM "taggings" LIMIT 1
156
+ Tagging Load (0.2ms) SELECT "taggings".id FROM "taggings" WHERE ("taggings"."taggable_id" = 1 AND "taggings".tag_id = 1 AND "taggings".taggable_type = 'Context1') LIMIT 1
157
+ Tagging Load (0.1ms) SELECT "taggings".id FROM "taggings" WHERE ("taggings"."taggable_id" = 1 AND "taggings".tag_id = 2 AND "taggings".taggable_type = 'Context1') LIMIT 1
158
+ Tagging Load (0.1ms) SELECT "taggings".id FROM "taggings" WHERE ("taggings"."taggable_id" = 1 AND "taggings".tag_id = 2 AND "taggings".taggable_type = 'Context2') LIMIT 1
159
+ SQL (0.1ms) PRAGMA index_list("taggings")
160
+ SQL (0.1ms) PRAGMA index_info('index_taggings_on_taggable_id_and_taggable_type')
161
+ Tagging Load (0.1ms) SELECT "taggings".id FROM "taggings" WHERE ("taggings"."taggable_id" = 1 AND "taggings".tag_id = 1 AND "taggings".taggable_type = 'Context2') LIMIT 1
162
+ Tagging Create (0.1ms) INSERT INTO "taggings" ("tag_id", "taggable_id", "taggable_type") VALUES(1, 1, 'Context2')
163
+ Tag Delete all (0.1ms) DELETE FROM "tags" WHERE 1=1
164
+ Tag Load (0.1ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'rock' AND "tags".context = 'genres') LIMIT 1
165
+ Tag Create (0.1ms) INSERT INTO "tags" ("name", "context") VALUES('rock', 'genres')
166
+ Tag Load (0.2ms) SELECT * FROM "tags" LIMIT 1
167
+ Tag Load (0.2ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'rock' AND "tags".context = 'genres') LIMIT 1
168
+ Tag Load (0.1ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'rock' AND "tags".context = 'genret') LIMIT 1
169
+ Tag Load (0.1ms) SELECT "tags".id FROM "tags" WHERE ("tags"."name" IS NULL AND "tags".context IS NULL) LIMIT 1
170
+ SQL (0.1ms) PRAGMA index_list("tags")
171
+ SQL (0.2ms) PRAGMA index_info('index_tags_on_context_and_name')
172
+ Tag Load (0.1ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'rock and roll' AND "tags".context = 'genres') LIMIT 1
173
+ Tag Load (0.1ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'pop' AND "tags".context = 'genres') LIMIT 1
174
+ SQL (0.2ms)  SELECT name
175
+ FROM sqlite_master
176
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
177
+ 
178
+ SQL (0.1ms) DROP TABLE "scoped_tagged_models"
179
+ SQL (0.2ms) CREATE TABLE "scoped_tagged_models" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
180
+ SQL (0.4ms)  SELECT name
181
+ FROM sqlite_master
182
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
183
+ 
184
+ SQL (0.1ms) DROP TABLE "tags"
185
+ SQL (0.1ms) CREATE TABLE "tags" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "context" varchar(255)) 
186
+ SQL (0.4ms)  SELECT name
187
+ FROM sqlite_master
188
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
189
+ 
190
+ SQL (0.2ms) DROP TABLE "taggings"
191
+ SQL (2.2ms) CREATE TABLE "taggings" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "tag_id" integer, "taggable_id" integer, "taggable_type" varchar(255)) 
192
+ SQL (0.2ms) CREATE INDEX "index_tags_on_context_and_name" ON "tags" ("context", "name")
193
+ SQL (0.2ms) CREATE INDEX "index_taggings_on_taggable_id_and_taggable_type" ON "taggings" ("taggable_id", "taggable_type")
194
+ SQL (0.2ms)  SELECT name
195
+ FROM sqlite_master
196
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
197
+ 
198
+ SQL (0.2ms) SELECT version FROM "schema_migrations"
199
+ Tag Load (0.1ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'pop' AND "tags".context = 'genres') LIMIT 1
200
+ Tag Create (0.1ms) INSERT INTO "tags" ("name", "context") VALUES('pop', 'genres')
201
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'pop' and context = 'genres') LIMIT 1
202
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'disco' and context = 'genres') LIMIT 1
203
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'disco' and context = 'genres') LIMIT 1
204
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'techno' and context = 'genres') LIMIT 1
205
+ Tag Load (0.2ms) SELECT * FROM "tags" WHERE (name = 'dance' and context = 'genres') LIMIT 1
206
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'techno' and context = 'genres') LIMIT 1
207
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'house' and context = 'genres') LIMIT 1
208
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'rock' and context = 'genres') LIMIT 1
209
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'rock' and context = 'genres') LIMIT 1
210
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'pop' and context = 'genres') LIMIT 1
211
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'disco' and context = 'genres') LIMIT 1
212
+ Tag Load (0.1ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'rock' AND "tags".context = 'genres') LIMIT 1
213
+ Tag Load (0.1ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'pop' AND "tags".context = 'genres' AND "tags".id <> 1) LIMIT 1
214
+ Tag Load (0.1ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'disco' AND "tags".context = 'genres') LIMIT 1
215
+ ScopedTaggedModel Create (0.1ms) INSERT INTO "scoped_tagged_models" ("name") VALUES(NULL)
216
+ Tag Load (0.1ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'rock' AND "tags".context = 'genres') LIMIT 1
217
+ Tag Create (0.1ms) INSERT INTO "tags" ("name", "context") VALUES('rock', 'genres')
218
+ Tagging Load (0.1ms) SELECT "taggings".id FROM "taggings" WHERE ("taggings"."taggable_id" = 1 AND "taggings".tag_id = 2 AND "taggings".taggable_type = 'ScopedTaggedModel') LIMIT 1
219
+ Tagging Create (0.1ms) INSERT INTO "taggings" ("tag_id", "taggable_id", "taggable_type") VALUES(2, 1, 'ScopedTaggedModel')
220
+ Tagging Load (0.2ms) SELECT "taggings".id FROM "taggings" WHERE ("taggings"."taggable_id" = 1 AND "taggings".tag_id = 1 AND "taggings".taggable_type = 'ScopedTaggedModel') LIMIT 1
221
+ Tagging Create (0.1ms) INSERT INTO "taggings" ("tag_id", "taggable_id", "taggable_type") VALUES(1, 1, 'ScopedTaggedModel')
222
+ Tag Load (0.1ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'disco' AND "tags".context = 'genres') LIMIT 1
223
+ Tag Create (0.1ms) INSERT INTO "tags" ("name", "context") VALUES('disco', 'genres')
224
+ Tagging Load (0.1ms) SELECT "taggings".id FROM "taggings" WHERE ("taggings"."taggable_id" = 1 AND "taggings".tag_id = 3 AND "taggings".taggable_type = 'ScopedTaggedModel') LIMIT 1
225
+ Tagging Create (0.2ms) INSERT INTO "taggings" ("tag_id", "taggable_id", "taggable_type") VALUES(3, 1, 'ScopedTaggedModel')
226
+ Tagging Delete all (0.1ms) DELETE FROM "taggings" WHERE ("taggings"."tag_id" = 2 AND "taggings"."taggable_id" = 1 AND "taggings"."taggable_type" = 'ScopedTaggedModel') 
227
+ ScopedTaggedModel Load (0.2ms) SELECT * FROM "scoped_tagged_models" WHERE ("scoped_tagged_models"."id" = 1) 
228
+ SQL (0.2ms) SELECT count(*) AS count_all FROM "tags" INNER JOIN "taggings" ON "tags".id = "taggings".tag_id WHERE (("taggings".taggable_id = 1) AND ("taggings".taggable_type = 'ScopedTaggedModel') AND (("tags"."context" = 'genres'))) 
229
+ Tag Load (0.3ms) SELECT * FROM "tags" WHERE (name = 'rock' and context = 'genres') LIMIT 1
230
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'pop' and context = 'genres') LIMIT 1
231
+ Tag Load (0.2ms) SELECT * FROM "tags" WHERE (name = 'disco' and context = 'genres') LIMIT 1
232
+ Tagging Delete all (0.1ms) DELETE FROM "taggings" WHERE ("taggings"."tag_id" = 3 AND "taggings"."taggable_id" IS NULL AND "taggings"."taggable_type" = 'ScopedTaggedModel') 
233
+ Tag Load (0.1ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'rock' AND "tags".context = 'genres' AND "tags".id <> 2) LIMIT 1
234
+ Tag Load (0.1ms) SELECT "tags".id FROM "tags" WHERE (LOWER("tags"."name") = 'pop' AND "tags".context = 'genres' AND "tags".id <> 1) LIMIT 1
235
+ ScopedTaggedModel Create (0.1ms) INSERT INTO "scoped_tagged_models" ("name") VALUES(NULL)
236
+ Tagging Load (0.2ms) SELECT "taggings".id FROM "taggings" WHERE ("taggings"."taggable_id" = 2 AND "taggings".tag_id = 2 AND "taggings".taggable_type = 'ScopedTaggedModel') LIMIT 1
237
+ Tagging Create (0.1ms) INSERT INTO "taggings" ("tag_id", "taggable_id", "taggable_type") VALUES(2, 2, 'ScopedTaggedModel')
238
+ Tagging Load (0.1ms) SELECT "taggings".id FROM "taggings" WHERE ("taggings"."taggable_id" = 2 AND "taggings".tag_id = 1 AND "taggings".taggable_type = 'ScopedTaggedModel') LIMIT 1
239
+ Tagging Create (0.2ms) INSERT INTO "taggings" ("tag_id", "taggable_id", "taggable_type") VALUES(1, 2, 'ScopedTaggedModel')
240
+ ScopedTaggedModel Load (0.2ms) SELECT * FROM "scoped_tagged_models" WHERE ("scoped_tagged_models"."id" = 2) 
241
+ SQL (0.2ms) SELECT count(*) AS count_all FROM "tags" INNER JOIN "taggings" ON "tags".id = "taggings".tag_id WHERE (("taggings".taggable_id = 2) AND ("taggings".taggable_type = 'ScopedTaggedModel') AND (("tags"."context" = 'genres'))) 
242
+ Tag Load (0.2ms) SELECT * FROM "tags" WHERE (name = 'rock' and context = 'genres') LIMIT 1
243
+ Tag Load (0.2ms) SELECT * FROM "tags" WHERE (name = 'pop' and context = 'genres') LIMIT 1
244
+ Tag Load (0.2ms) SELECT * FROM "tags" WHERE (name = 'rock' and context = 'genres') LIMIT 1
245
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'pop' and context = 'genres') LIMIT 1
246
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'disco' and context = 'genres') LIMIT 1
247
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'rock' and context = 'genres') LIMIT 1
248
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'pop' and context = 'genres') LIMIT 1
249
+ Tag Load (0.2ms) SELECT * FROM "tags" WHERE (name = 'disco' and context = 'genres') LIMIT 1
250
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'funk' and context = 'genres') LIMIT 1
251
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'house' and context = 'genres') LIMIT 1
252
+ Tagging Delete all (0.1ms) DELETE FROM "taggings" WHERE ("taggings"."tag_id" = 2 AND "taggings"."taggable_id" IS NULL AND "taggings"."taggable_type" = 'ScopedTaggedModel') 
253
+ Tagging Delete all (0.1ms) DELETE FROM "taggings" WHERE ("taggings"."tag_id" = 1 AND "taggings"."taggable_id" IS NULL AND "taggings"."taggable_type" = 'ScopedTaggedModel') 
254
+ Tagging Delete all (0.1ms) DELETE FROM "taggings" WHERE ("taggings"."tag_id" = 3 AND "taggings"."taggable_id" IS NULL AND "taggings"."taggable_type" = 'ScopedTaggedModel') 
255
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'funk' and context = 'genres') LIMIT 1
256
+ Tag Load (0.1ms) SELECT * FROM "tags" WHERE (name = 'house' and context = 'genres') LIMIT 1
@@ -12,7 +12,7 @@ describe "ScopedTaggedModel" do
12
12
  end
13
13
 
14
14
  it "should include a tags method" do
15
- @scoped_model.should respond_to(:tags)
15
+ @scoped_model.should respond_to(:base_tags)
16
16
  end
17
17
 
18
18
  it "should include the genres method" do
@@ -81,7 +81,7 @@ describe "ScopedTaggedModel" do
81
81
  @scoped_model.genre_list << tag
82
82
  @scoped_model.save!
83
83
 
84
- ar_check = ScopedTaggedModel.all(:conditions => ['tags.name IN (?) AND tags.context = ?', tag, 'genres'], :include => [:taggings, :tags])
84
+ ar_check = ScopedTaggedModel.all(:conditions => ['tags.name IN (?) AND tags.context = ?', tag, 'genres'], :include => [:taggings, :base_tags])
85
85
  ar_check.size.should == 1
86
86
 
87
87
  ScopedTaggedModel.methods.should include('tagged_with_genres')
@@ -2,60 +2,76 @@ require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
 
4
4
  describe Tagging do
5
- before(:all) { Tagging.create!(:tag_id => 1, :taggable_id => 1) }
6
-
5
+
6
+ before(:all) do
7
+ reload_database
8
+ Tagging.create!(:tag_id => 1, :taggable_id => 1, :taggable_type => "Context1")
9
+ end
10
+
7
11
  it { should belong_to(:tag) }
8
12
  it { should belong_to(:taggable) }
9
- it { should validate_uniqueness_of(:taggable_id).scoped_to(:tag_id) }
10
-
13
+ it { should validate_uniqueness_of(:taggable_id).scoped_to(:tag_id, :taggable_type) }
14
+
11
15
  it { should allow_mass_assignment_of(:taggable_id)
12
16
  should allow_mass_assignment_of(:taggable_type)
13
17
  should allow_mass_assignment_of(:tag_id) }
14
-
18
+
15
19
  it { should_not allow_mass_assignment_of(:created_at)
16
20
  should_not allow_mass_assignment_of(:updated_at) }
17
-
21
+
18
22
  it { should have_db_index([:taggable_id, :taggable_type]) }
23
+
24
+ it "should validate uniqueness of taggable_id scoped to tag_id and taggable type" do
25
+ proc {
26
+ Tagging.create!(:tag_id => 1, :taggable_id => 1, :taggable_type => "Context2")
27
+ }.should_not raise_error
28
+ end
29
+
19
30
  end
20
31
 
21
32
 
22
33
  describe Tag do
23
- before(:all) { Tag.create!(:name => 'rock', :context => 'genres') }
24
-
34
+ before(:all) do
35
+ Tag.delete_all
36
+ Tag.create!(:name => 'rock', :context => 'genres')
37
+ end
38
+
25
39
  it { should have_many(:taggings).dependent(:delete_all) }
26
-
40
+
27
41
  it { should validate_uniqueness_of(:name).scoped_to(:context).case_insensitive }
28
42
  it { should validate_presence_of(:context) }
29
-
43
+
30
44
  it { should allow_mass_assignment_of(:name)
31
45
  should allow_mass_assignment_of(:context) }
32
-
46
+
33
47
  it { should_not allow_mass_assignment_of(:created_at)
34
48
  should_not allow_mass_assignment_of(:updated_at) }
35
-
49
+
36
50
  it { should have_db_index([:context, :name]) }
37
-
51
+
38
52
  it "should trim and squeeze spaces from name and context before validation" do
39
53
  t = Tag.new(:name => ' rock and roll', :context => ' genres ')
40
54
  t.valid?
41
55
  t.name.should == 'rock and roll'
42
- t.context.should == 'genres'
56
+ t.context.should == 'genres'
43
57
  end
44
-
58
+
45
59
  it "should lowercase the name and context before validation" do
46
60
  t = Tag.new(:name => 'POP', :context => 'GENRES')
47
61
  t.valid?
48
62
  t.name.should == 'pop'
49
63
  t.context.should == 'genres'
50
64
  end
51
-
65
+
52
66
  it "should recognize that it is equal to another tag with the same name and context" do
53
67
  t = Tag.new(:name => 'pop', :context => 'genres')
54
68
  s = Tag.new(:name => 'pop', :context => 'genres')
55
69
  t.should == s
56
70
  end
57
-
71
+
58
72
  it "#find_or_new_by_name_ane_context" do
73
+ reload_database # or we will have duplication
74
+
59
75
  Tag.create!(:name => 'pop', :context => 'genres')
60
76
  s = Tag.find_or_new_by_name_and_context('pop', 'genres')
61
77
  s.new_record?.should be_false
@@ -1,25 +1,29 @@
1
+ require 'rubygems'
2
+
1
3
  require 'spec'
2
4
  require 'shoulda'
3
5
 
6
+ require 'sqlite3' # So we don't get Encoding errors which we get with plain sqlite3
7
+
4
8
  require 'active_support'
5
9
  require 'active_record'
6
10
 
7
11
  require 'scoped-tags'
8
12
 
9
- Spec::Runner.configure do |config|
10
- config.include(Shoulda::ActiveRecord::Matchers, :type => :model)
11
- end
12
13
 
13
- TEST_DATABASE_FILE = 'spec/test.sqlite3'
14
+ def reload_database
15
+ load(File.expand_path('../schema.rb', __FILE__))
16
+ end
14
17
 
15
- File.unlink(TEST_DATABASE_FILE) if File.exist?(TEST_DATABASE_FILE)
16
- ActiveRecord::Base.establish_connection(
17
- "adapter" => "sqlite3", "database" => TEST_DATABASE_FILE
18
- )
19
-
20
- load('schema.rb')
18
+ Spec::Runner.configure do |config|
19
+ config.include(Shoulda::ActiveRecord::Matchers, :type => :model)
21
20
 
22
- RAILS_DEFAULT_LOGGER = Logger.new("spec/debug.log")
21
+ config.before(:suite) do
22
+ ActiveRecord::Base.logger = Logger.new(File.expand_path("../debug.log", __FILE__))
23
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
24
+ reload_database
25
+ end
26
+ end
23
27
 
24
28
  class ScopedTaggedModel < ActiveRecord::Base
25
29
  scoped_tags :genres
Binary file
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scoped-tags
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 4
8
+ - 0
9
+ version: 0.4.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Josh Kalderimis
@@ -9,19 +14,23 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-10-18 00:00:00 +02:00
17
+ date: 2010-03-31 00:00:00 +02:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: activerecord
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 3
30
+ - 3
23
31
  version: 2.3.3
24
- version:
32
+ type: :runtime
33
+ version_requirements: *id001
25
34
  description:
26
35
  email: josh.kalderimis@gmail.com
27
36
  executables: []
@@ -33,9 +42,8 @@ extra_rdoc_files: []
33
42
  files:
34
43
  - MIT-LICENSE
35
44
  - VERSION.yml
36
- - generators/scoped_tags_migration/scoped_tags_generator.rb
45
+ - generators/scoped_tags_migration/scoped_tags_migration_generator.rb
37
46
  - generators/scoped_tags_migration/templates/migration.rb
38
- - install.rb
39
47
  - lib/scoped-tags.rb
40
48
  - lib/scoped_tags/active_record_additions.rb
41
49
  - lib/scoped_tags/tag.rb
@@ -43,7 +51,6 @@ files:
43
51
  - lib/scoped_tags/tag_list_proxy.rb
44
52
  - lib/scoped_tags/tagging.rb
45
53
  - readme.md
46
- - uninstall.rb
47
54
  has_rdoc: true
48
55
  homepage: http://github.com/joshk/scoped-tags
49
56
  licenses: []
@@ -57,18 +64,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
57
64
  requirements:
58
65
  - - ">="
59
66
  - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
60
69
  version: "0"
61
- version:
62
70
  required_rubygems_version: !ruby/object:Gem::Requirement
63
71
  requirements:
64
72
  - - ">="
65
73
  - !ruby/object:Gem::Version
74
+ segments:
75
+ - 0
66
76
  version: "0"
67
- version:
68
77
  requirements: []
69
78
 
70
79
  rubyforge_project:
71
- rubygems_version: 1.3.5
80
+ rubygems_version: 1.3.6
72
81
  signing_key:
73
82
  specification_version: 3
74
83
  summary: Scoped tagging plugin for your rails models which keeps your associations in sync with your tag arrays
data/install.rb DELETED
@@ -1 +0,0 @@
1
- # Install hook code here
@@ -1 +0,0 @@
1
- # Uninstall hook code here