tag_snotmonkey 0.0.1 → 0.0.2

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.
@@ -0,0 +1,2 @@
1
+ Gemfile.lock
2
+ spec/internal/db/*.sqlite
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,6 @@
1
+ class TagSnotmonkey::Tag < ActiveRecord::Base
2
+ has_many :taggings, :class_name => 'TagSnotmonkey::Tagging',
3
+ :dependent => :destroy
4
+
5
+ validates :name, :presence => true, :uniqueness => true
6
+ end
@@ -0,0 +1,7 @@
1
+ class TagSnotmonkey::Tagging < ActiveRecord::Base
2
+ belongs_to :taggable, :polymorphic => true
3
+ belongs_to :tag, :class_name => 'TagSnotmonkey::Tag'
4
+
5
+ validates :taggable, :presence => true
6
+ validates :tag, :presence => true
7
+ end
@@ -0,0 +1,27 @@
1
+ class TagTables < ActiveRecord::Migration
2
+ def up
3
+ create_table :taggings do |t|
4
+ t.integer :tag_id, :null => false
5
+ t.integer :taggable_id, :null => false
6
+ t.string :taggable_type, :null => false
7
+ t.timestamps
8
+ end
9
+
10
+ add_index :taggings, :tag_id
11
+ add_index :taggings, [:taggable_type, :taggable_id]
12
+ add_index :taggings, [:taggable_type, :taggable_id, :tag_id],
13
+ :unique => true, :name => 'unique_taggings'
14
+
15
+ create_table :tags do |t|
16
+ t.string :name, :null => false
17
+ t.timestamps
18
+ end
19
+
20
+ add_index :tags, :name, :unique => true
21
+ end
22
+
23
+ def down
24
+ drop_table :tags
25
+ drop_table :taggings
26
+ end
27
+ end
@@ -0,0 +1,8 @@
1
+ # Declare our top level module
2
+ module TagSnotmonkey
3
+ #
4
+ end
5
+
6
+ # Require the rest of the gem's files
7
+ require 'tag_snotmonkey/active_record'
8
+ require 'tag_snotmonkey/engine'
@@ -0,0 +1,16 @@
1
+ module TagSnotmonkey::ActiveRecord
2
+ def self.included(base)
3
+ # include our class methods
4
+ base.extend TagSnotmonkey::ActiveRecord::ClassMethods
5
+ end
6
+
7
+ module ClassMethods
8
+ # Set up the underlying tag associations in the model
9
+ def has_many_tags
10
+ has_many :taggings, :class_name => 'TagSnotmonkey::Tagging',
11
+ :as => :taggable, :dependent => :destroy
12
+ has_many :tags, :class_name => 'TagSnotmonkey::Tag',
13
+ :through => :taggings
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ require 'rails/engine'
2
+
3
+ class TagSnotmonkey::Engine < Rails::Engine
4
+ # set our engine name
5
+ engine_name :tag_snotmonkey
6
+
7
+ ActiveSupport.on_load :active_record do
8
+ # this is run when Rails loads ActiveRecord, and is
9
+ # within the context of ActiveRecord::Base.
10
+ include TagSnotmonkey::ActiveRecord
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Adding and removing tags' do
4
+ let(:article) { Article.create }
5
+ let(:pancakes) { TagSnotmonkey::Tag.create :name => 'pancakes' }
6
+
7
+ it "stores new tags" do
8
+ article.tags << pancakes
9
+
10
+ article.tags.reload.should == [pancakes]
11
+ end
12
+
13
+ it "removes existing tags" do
14
+ article.tags << pancakes
15
+
16
+ article.tags.delete pancakes
17
+
18
+ article.tags.reload.should == []
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ class Article < ActiveRecord::Base
2
+ has_many_tags
3
+ end
@@ -0,0 +1,3 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: db/combustion_test.sqlite
@@ -0,0 +1,3 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: db/combustion_test.sqlite
@@ -0,0 +1,6 @@
1
+ ActiveRecord::Schema.define do
2
+ create_table :articles, :force => true do |t|
3
+ t.string :title
4
+ t.timestamps
5
+ end
6
+ end
@@ -0,0 +1 @@
1
+ *.log
@@ -0,0 +1,11 @@
1
+ require 'bundler'
2
+
3
+ Bundler.require :default, :development
4
+
5
+ Combustion.initialize! :active_record
6
+
7
+ require 'rspec/rails'
8
+
9
+ RSpec.configure do |config|
10
+ config.use_transactional_fixtures = true
11
+ end
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = 'tag_snotmonkey'
4
- s.version = '0.0.1'
4
+ s.version = '0.0.2'
5
5
  s.authors = ['Alan Owens']
6
6
  s.email = ['alan.owens1975@gmail.com']
7
7
  s.homepage = 'https://github.com/aowens/tag_snotmonkey'
@@ -11,4 +11,9 @@ Gem::Specification.new do |s|
11
11
  s.files = `git ls-files`.split("\n")
12
12
  s.test_files = `git ls-files -- {spec}/*`.split("\n")
13
13
  s.require_paths = ['lib']
14
+
15
+ s.add_runtime_dependency 'activerecord', '>= 3.2.0'
16
+ s.add_development_dependency 'combustion', '~> 0.4.0'
17
+ s.add_development_dependency 'rspec-rails', '~> 2.13'
18
+ s.add_development_dependency 'sqlite3', '~> 1.3.7'
14
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tag_snotmonkey
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,71 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
  date: 2013-05-01 00:00:00.000000000 Z
13
- dependencies: []
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activerecord
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: combustion
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.4.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.4.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec-rails
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '2.13'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.13'
62
+ - !ruby/object:Gem::Dependency
63
+ name: sqlite3
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.3.7
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 1.3.7
14
78
  description: This friendly snotmonkey gives you tags in your Rails app.
15
79
  email:
16
80
  - alan.owens1975@gmail.com
@@ -18,7 +82,21 @@ executables: []
18
82
  extensions: []
19
83
  extra_rdoc_files: []
20
84
  files:
85
+ - .gitignore
86
+ - Gemfile
87
+ - app/models/tag_snotmonkey/tag.rb
88
+ - app/models/tag_snotmonkey/tagging.rb
89
+ - db/migrate/1_tag_tables.rb
21
90
  - lib/tag_snotmonkey.rb
91
+ - lib/tag_snotmonkey/active_record.rb
92
+ - lib/tag_snotmonkey/engine.rb
93
+ - spec/acceptance/tags_spec.rb
94
+ - spec/internal/app/models/article.rb
95
+ - spec/internal/config/database.yml
96
+ - spec/internal/database.yml
97
+ - spec/internal/db/schema.rb
98
+ - spec/internal/log/.gitignore
99
+ - spec/spec_helper.rb
22
100
  - tag_snotmonkey.gemspec
23
101
  homepage: https://github.com/aowens/tag_snotmonkey
24
102
  licenses: []