lazy_comments 0.0.3 → 0.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e8f6c334b91ac1efc0fd73bc9f0f650abc8c15a7
4
- data.tar.gz: 73854a2bf83f2b9057be97fe3555edb4e568dc12
3
+ metadata.gz: b57224b58d14d49177fb6264d35bb976fa32676e
4
+ data.tar.gz: 4a50b45a8bc095b005243b2adaee2e8df4861fb4
5
5
  SHA512:
6
- metadata.gz: a31d5c4adeed4a59ef70dc376d727bdf21d7e6feb70201edc9c954bae47b84d9858f63c02ee24e571869981b20f5f03860e949dde49a4700ca886abfc45d32f0
7
- data.tar.gz: 4ca3b34ca01d648af7dbbd8c0f752632fbd524ae6931813d093bef562855cff82378b0054fa953a35a1b7c2e96b3e3040fe6be4424bfbf734b28a635824995be
6
+ metadata.gz: e207acfca9cff7f3d10b4cd119e19262ae004cac605c834ff10ee54b29269a09b24cc3d3f523e4c29a70b1c1609e54fc1355243b96287671db7e3970aa332b96
7
+ data.tar.gz: 5f0e8a8987a186ffbdf92ba818dadbe0e58d6113a9d5e4a1b833560597c4c6b9ec4a2693a4c24718d4befacb5976da99311585b8b2083fa3b0a21d0c76675b96
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ gemspec
2
+
3
+ group :development do
4
+ gem 'rails'
5
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,128 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ lazy_comments (0.0.3)
5
+ rails (>= 4)
6
+
7
+ GEM
8
+ specs:
9
+ actionmailer (4.0.0)
10
+ actionpack (= 4.0.0)
11
+ mail (~> 2.5.3)
12
+ actionpack (4.0.0)
13
+ activesupport (= 4.0.0)
14
+ builder (~> 3.1.0)
15
+ erubis (~> 2.7.0)
16
+ rack (~> 1.5.2)
17
+ rack-test (~> 0.6.2)
18
+ activemodel (4.0.0)
19
+ activesupport (= 4.0.0)
20
+ builder (~> 3.1.0)
21
+ activerecord (4.0.0)
22
+ activemodel (= 4.0.0)
23
+ activerecord-deprecated_finders (~> 1.0.2)
24
+ activesupport (= 4.0.0)
25
+ arel (~> 4.0.0)
26
+ activerecord-deprecated_finders (1.0.3)
27
+ activesupport (4.0.0)
28
+ i18n (~> 0.6, >= 0.6.4)
29
+ minitest (~> 4.2)
30
+ multi_json (~> 1.3)
31
+ thread_safe (~> 0.1)
32
+ tzinfo (~> 0.3.37)
33
+ arel (4.0.0)
34
+ atomic (1.1.13)
35
+ builder (3.1.4)
36
+ coderay (1.0.9)
37
+ diff-lcs (1.2.4)
38
+ erubis (2.7.0)
39
+ ffi (1.9.0)
40
+ formatador (0.2.4)
41
+ guard (1.8.2)
42
+ formatador (>= 0.2.4)
43
+ listen (>= 1.0.0)
44
+ lumberjack (>= 1.0.2)
45
+ pry (>= 0.9.10)
46
+ thor (>= 0.14.6)
47
+ guard-rspec (3.0.2)
48
+ guard (>= 1.8)
49
+ rspec (~> 2.13)
50
+ hike (1.2.3)
51
+ i18n (0.6.5)
52
+ listen (1.2.3)
53
+ rb-fsevent (>= 0.9.3)
54
+ rb-inotify (>= 0.9)
55
+ rb-kqueue (>= 0.2)
56
+ lumberjack (1.0.4)
57
+ mail (2.5.4)
58
+ mime-types (~> 1.16)
59
+ treetop (~> 1.4.8)
60
+ method_source (0.8.2)
61
+ mime-types (1.24)
62
+ minitest (4.7.5)
63
+ multi_json (1.7.9)
64
+ polyglot (0.3.3)
65
+ pry (0.9.12.2)
66
+ coderay (~> 1.0.5)
67
+ method_source (~> 0.8)
68
+ slop (~> 3.4)
69
+ rack (1.5.2)
70
+ rack-test (0.6.2)
71
+ rack (>= 1.0)
72
+ rails (4.0.0)
73
+ actionmailer (= 4.0.0)
74
+ actionpack (= 4.0.0)
75
+ activerecord (= 4.0.0)
76
+ activesupport (= 4.0.0)
77
+ bundler (>= 1.3.0, < 2.0)
78
+ railties (= 4.0.0)
79
+ sprockets-rails (~> 2.0.0)
80
+ railties (4.0.0)
81
+ actionpack (= 4.0.0)
82
+ activesupport (= 4.0.0)
83
+ rake (>= 0.8.7)
84
+ thor (>= 0.18.1, < 2.0)
85
+ rake (10.1.0)
86
+ rb-fsevent (0.9.3)
87
+ rb-inotify (0.9.1)
88
+ ffi (>= 0.5.0)
89
+ rb-kqueue (0.2.0)
90
+ ffi (>= 0.5.0)
91
+ rspec (2.14.1)
92
+ rspec-core (~> 2.14.0)
93
+ rspec-expectations (~> 2.14.0)
94
+ rspec-mocks (~> 2.14.0)
95
+ rspec-core (2.14.5)
96
+ rspec-expectations (2.14.1)
97
+ diff-lcs (>= 1.1.3, < 2.0)
98
+ rspec-mocks (2.14.3)
99
+ slop (3.4.6)
100
+ sprockets (2.10.0)
101
+ hike (~> 1.2)
102
+ multi_json (~> 1.0)
103
+ rack (~> 1.0)
104
+ tilt (~> 1.1, != 1.3.0)
105
+ sprockets-rails (2.0.0)
106
+ actionpack (>= 3.0)
107
+ activesupport (>= 3.0)
108
+ sprockets (~> 2.8)
109
+ sqlite3 (1.3.8)
110
+ thor (0.18.1)
111
+ thread_safe (0.1.2)
112
+ atomic
113
+ tilt (1.4.1)
114
+ treetop (1.4.15)
115
+ polyglot
116
+ polyglot (>= 0.3.1)
117
+ tzinfo (0.3.37)
118
+
119
+ PLATFORMS
120
+ ruby
121
+
122
+ DEPENDENCIES
123
+ guard
124
+ guard-rspec
125
+ lazy_comments!
126
+ rails
127
+ rspec (= 2.14.1)
128
+ sqlite3
data/Guardfile ADDED
@@ -0,0 +1,46 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara features specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
25
+
26
+ guard :rspec do
27
+ watch(%r{^spec/.+_spec\.rb$})
28
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
29
+ watch('spec/spec_helper.rb') { "spec" }
30
+
31
+ # Rails example
32
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
33
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
34
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
35
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
36
+ watch('config/routes.rb') { "spec/routing" }
37
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
38
+
39
+ # Capybara features specs
40
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
41
+
42
+ # Turnip features and steps
43
+ watch(%r{^spec/acceptance/(.+)\.feature$})
44
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
45
+ end
46
+
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ lazy_comments
2
+ =============
3
+
4
+ Simple commenting gem that gives you tag any AR model with `has_comments` and adding comments to it.
5
+
6
+ ### Requirements
7
+ - Rails 4
8
+ - ActiveRecord
9
+ - Haml (currently, generated views use HAML only)
10
+
11
+ ## Installation
12
+
13
+ gem 'lazy_comments'
14
+ rails g comments # Generates controllers, models, views and migrations
15
+
16
+ ## Usage
17
+
18
+ class Post < ActiveRecord::Base
19
+ has_comments
20
+ end
21
+
22
+ Add a comment to your model:
23
+
24
+ post = Post.new
25
+ post.comments.build(message: "hello")
26
+
27
+
28
+ Find Comments:
29
+
30
+ post = Post.find(13)
31
+ Comment.for_subject(post)
32
+ post.comments.where(user: current_user)
33
+
34
+ Comments belonging to a group:
35
+
36
+ # Essentially group is a string that can be anything
37
+ Comment.in_group("hello_world")
38
+
39
+
40
+ Helpers
41
+
42
+ Feature not committed yet, coming soon!
43
+
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'lazy_comments'
3
- s.version = '0.0.3'
3
+ s.version = '0.1.0'
4
4
  s.date = '2013-08-18'
5
5
  s.summary = "A Rails commenting gem that handles mentions"
6
6
  s.description = "Hello world version of a commenting gem"
@@ -10,4 +10,11 @@ Gem::Specification.new do |s|
10
10
  s.require_paths = ["lib"]
11
11
  s.homepage = 'http://github.com/daemonsy/lazy_comments'
12
12
  s.license = 'MIT'
13
+
14
+ s.add_runtime_dependency 'rails', ['>= 4']
15
+
16
+ s.add_development_dependency 'rspec', "2.14.1"
17
+ s.add_development_dependency 'sqlite3'
18
+ s.add_development_dependency 'guard'
19
+ s.add_development_dependency 'guard-rspec'
13
20
  end
data/lib/commentable.rb CHANGED
@@ -12,6 +12,13 @@ module Lazy
12
12
  where(commentable_type: subject.class.base_class, commentable_id: subject.id)
13
13
  end
14
14
 
15
+ def for_topic(topic)
16
+ where(topic: topic)
17
+ end
18
+
19
+ def in_group(group)
20
+ group.present? ? where(group: group) : self
21
+ end
15
22
  end
16
23
  end
17
24
  end
@@ -1,16 +1,19 @@
1
1
  class CreateComments < ActiveRecord::Migration
2
- def change
2
+ def up
3
3
  create_table :comments do |t|
4
- t.text :message
4
+ t.text :body
5
5
  t.references :user, index: true
6
6
  t.references :commentable, polymorphic: true
7
- t.string :groups
8
- t.string :mentions
7
+ t.string :group
8
+ t.string :topic
9
9
 
10
10
  t.timestamps
11
11
  end
12
12
  add_index :comments, :commentable_type
13
13
  add_index :comments, :commentable_id
14
- add_index :comments, :user_id
14
+ end
15
+
16
+ def down
17
+ drop_table :comments
15
18
  end
16
19
  end
@@ -0,0 +1,84 @@
1
+ require 'rspec'
2
+ require "support/active_record"
3
+ require "support/lazy_comments"
4
+
5
+
6
+
7
+ ActiveRecord::Migration.verbose = false
8
+ ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
9
+
10
+ ActiveRecord::Migrator.up "db/migrate"
11
+
12
+ def load_existing_schema
13
+ load "support/schema.rb"
14
+ end
15
+
16
+ def file_path(file)
17
+ File.expand_path(File.dirname(__FILE__) + "/../#{file}")
18
+ end
19
+
20
+ def setup_models
21
+ load "support/models.rb"
22
+ end
23
+
24
+ def install_gem
25
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/generators/comments/templates/comments_table.rb")
26
+ CreateComments.new.up
27
+ end
28
+
29
+ describe "Lazy Comment" do
30
+ load_existing_schema
31
+ install_gem
32
+ setup_models
33
+
34
+ describe "#has_comments" do
35
+ it "creates comments on the associated model" do
36
+ post = Post.create(title: "Disney Star Wars???", body: "WATTTTT")
37
+ comment = post.comments.build(body: "I sincerely hope they don't screw it up")
38
+
39
+ expect(comment.commentable_id).to eq post.id
40
+ expect(comment.commentable_type).to eq "Post"
41
+ end
42
+ end
43
+
44
+ describe "Lazy::Commentable" do
45
+ context "Finders" do
46
+ describe "#for_subject" do
47
+ it "finds comments for a given AR model" do
48
+ vader_dies = Post.create(title: "Darth Vader dies", body: "The rumor mill says he was electrocuted")
49
+ comment = vader_dies.comments.create(body: "Hopefully not by a old wrinkly man")
50
+
51
+ comments = Comment.for_subject(vader_dies)
52
+ expect(comments).to include(comment)
53
+ expect(comments.size).to eq 1
54
+ end
55
+ end
56
+
57
+ describe "#for_topic" do
58
+ it "filters by the topic" do
59
+ 2.times { |i| Comment.create(body: "Comment #{i}", topic: "Remote Working") }
60
+
61
+ comments = Comment.for_topic("Remote Working")
62
+ expect(comments.size).to eq 2
63
+ end
64
+ end
65
+
66
+ describe "#in_groups" do
67
+ before(:each) do
68
+ @dorian_gray = Post.create(title: "A picture of Dorian Gray", body: "The story goes...")
69
+ @dorian_gray.comments.create(body: "lovely story", group: "haters")
70
+ @dorian_gray.comments.create(body: "lovely story", group: :fans)
71
+ end
72
+
73
+ it "filters by group" do
74
+ haters_comments = @dorian_gray.comments.in_group(:haters)
75
+ expect(haters_comments.size).to eq 1
76
+
77
+ fan_comments = @dorian_gray.comments.in_group(:fans)
78
+ expect(fan_comments.size).to eq 1
79
+ end
80
+
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,10 @@
1
+ require 'active_record'
2
+
3
+ RSpec.configure do |config|
4
+ config.around do |test|
5
+ ActiveRecord::Base.transaction do
6
+ test.run
7
+ raise ActiveRecord::Rollback
8
+ end
9
+ end
10
+ end
@@ -0,0 +1 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../lib/lazy_comments.rb")
@@ -0,0 +1,12 @@
1
+ class User < ActiveRecord::Base
2
+ end
3
+
4
+
5
+ class Post < ActiveRecord::Base
6
+ has_comments
7
+ end
8
+
9
+
10
+ class Comment < ActiveRecord::Base
11
+ include Lazy::Commentable
12
+ end
@@ -0,0 +1,10 @@
1
+ ActiveRecord::Schema.define(:version => 0) do
2
+ create_table :users do |u|
3
+ u.string :name
4
+ end
5
+
6
+ create_table :posts do |p|
7
+ p.string :title
8
+ p.text :body
9
+ end
10
+ end
File without changes
@@ -0,0 +1 @@
1
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lazy_comments
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damon Aw
@@ -9,13 +9,88 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2013-08-18 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 2.14.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 2.14.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
13
83
  description: Hello world version of a commenting gem
14
84
  email: daemonsy@gmail.com
15
85
  executables: []
16
86
  extensions: []
17
87
  extra_rdoc_files: []
18
88
  files:
89
+ - .rspec
90
+ - Gemfile
91
+ - Gemfile.lock
92
+ - Guardfile
93
+ - README.md
19
94
  - lazy_comments.gemspec
20
95
  - lib/commentable.rb
21
96
  - lib/comments.rb
@@ -28,6 +103,13 @@ files:
28
103
  - lib/generators/comments/templates/views/comments/_form.html.haml
29
104
  - lib/generators/comments/templates/views/comments/_list_and_form.html.haml
30
105
  - lib/lazy_comments.rb
106
+ - spec/lazy_comments_spec.rb
107
+ - spec/support/active_record.rb
108
+ - spec/support/lazy_comments.rb
109
+ - spec/support/models.rb
110
+ - spec/support/schema.rb
111
+ - spec/support/setup_helper.rb
112
+ - tmp/rspec_guard_result
31
113
  homepage: http://github.com/daemonsy/lazy_comments
32
114
  licenses:
33
115
  - MIT
@@ -48,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
130
  version: '0'
49
131
  requirements: []
50
132
  rubyforge_project:
51
- rubygems_version: 2.0.2
133
+ rubygems_version: 2.0.3
52
134
  signing_key:
53
135
  specification_version: 4
54
136
  summary: A Rails commenting gem that handles mentions