acts_as_commentable_more 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/acts_as_commentable_more.rb +5 -2
- data/lib/{comment_methods.rb → acts_as_commentable_more/comment_methods.rb} +0 -0
- data/lib/acts_as_commentable_more/commentable_methods.rb +64 -0
- data/lib/acts_as_commentable_more/helpers/comment/callbacks_helper.rb +59 -0
- data/lib/acts_as_commentable_more/helpers/comment/methods_helper.rb +44 -0
- data/lib/acts_as_commentable_more/helpers/post/associations_helper.rb +30 -0
- data/lib/acts_as_commentable_more/helpers/post/methods_helper.rb +18 -0
- data/lib/acts_as_commentable_more/helpers/post/scopes_helper.rb +19 -0
- data/lib/acts_as_commentable_more/version.rb +1 -1
- data/lib/generators/commentable/templates/comment.rb +1 -1
- data/test/dummy/spec/models/letter_spec.rb +2 -1
- data/test/dummy/spec/models/main_model_spec.rb +5 -0
- data/test/dummy/spec/models/note_custom_asso_name_spec.rb +2 -1
- data/test/dummy/spec/models/note_spec.rb +2 -1
- data/test/dummy/spec/models/post_custom_asso_name_spec.rb +1 -1
- data/test/dummy/spec/models/post_disable_cache_spec.rb +5 -0
- data/test/dummy/spec/models/post_spec.rb +2 -1
- data/test/dummy/spec/models/topic_spec.rb +1 -1
- metadata +13 -165
- data/.coveralls.yml +0 -1
- data/.gitignore +0 -48
- data/.travis.yml +0 -22
- data/CHANGELOG.md +0 -12
- data/Gemfile +0 -40
- data/Gemfile.lock +0 -212
- data/LICENSE +0 -22
- data/README.md +0 -125
- data/acts_as_commentable_more.gemspec +0 -36
- data/lib/commentable_methods.rb +0 -118
- data/test/acts_as_commentable_more_test.rb +0 -7
- data/test/dummy/README.rdoc +0 -28
- data/test/dummy/Rakefile +0 -17
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +0 -13
- data/test/dummy/app/assets/stylesheets/application.css +0 -15
- data/test/dummy/app/controllers/application_controller.rb +0 -5
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/mailers/.keep +0 -0
- data/test/dummy/app/models/.keep +0 -0
- data/test/dummy/app/models/admin.rb +0 -2
- data/test/dummy/app/models/comment.rb +0 -17
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/models/custom_comment.rb +0 -17
- data/test/dummy/app/models/letter.rb +0 -3
- data/test/dummy/app/models/note.rb +0 -3
- data/test/dummy/app/models/note_custom_asso_name.rb +0 -3
- data/test/dummy/app/models/post.rb +0 -4
- data/test/dummy/app/models/post_custom_asso_name.rb +0 -5
- data/test/dummy/app/models/topic.rb +0 -3
- data/test/dummy/app/models/user.rb +0 -2
- data/test/dummy/app/views/layouts/application.html.erb +0 -14
- data/test/dummy/bin/bundle +0 -3
- data/test/dummy/bin/rails +0 -4
- data/test/dummy/bin/rake +0 -4
- data/test/dummy/config.ru +0 -4
- data/test/dummy/config/application.rb +0 -35
- data/test/dummy/config/boot.rb +0 -5
- data/test/dummy/config/database.travis.yml +0 -18
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -37
- data/test/dummy/config/environments/production.rb +0 -78
- data/test/dummy/config/environments/test.rb +0 -39
- data/test/dummy/config/initializers/assets.rb +0 -8
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/cookies_serializer.rb +0 -3
- data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/test/dummy/config/initializers/inflections.rb +0 -16
- data/test/dummy/config/initializers/mime_types.rb +0 -4
- data/test/dummy/config/initializers/session_store.rb +0 -3
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/test/dummy/config/locales/en.yml +0 -23
- data/test/dummy/config/routes.rb +0 -56
- data/test/dummy/config/secrets.yml +0 -22
- data/test/dummy/db/migrate/20150113045806_create_posts.rb +0 -9
- data/test/dummy/db/migrate/20150113045817_create_admins.rb +0 -9
- data/test/dummy/db/migrate/20150113045831_create_users.rb +0 -9
- data/test/dummy/db/migrate/20150113065948_create_notes.rb +0 -9
- data/test/dummy/db/migrate/20150113074249_create_topics.rb +0 -9
- data/test/dummy/db/migrate/20150114052120_create_letters.rb +0 -9
- data/test/dummy/db/migrate/20150114100411_create_comments.rb +0 -18
- data/test/dummy/db/migrate/20150114100422_create_custom_comments.rb +0 -18
- data/test/dummy/db/migrate/20150115094241_create_post_custom_asso_names.rb +0 -9
- data/test/dummy/db/migrate/20150115100013_create_note_custom_asso_names.rb +0 -9
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/public/404.html +0 -67
- data/test/dummy/public/422.html +0 -67
- data/test/dummy/public/500.html +0 -66
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/spec/acts_as_commentable_more_spec.rb +0 -275
- data/test/dummy/spec/factories/admins.rb +0 -7
- data/test/dummy/spec/factories/comments.rb +0 -7
- data/test/dummy/spec/factories/custom_comments.rb +0 -7
- data/test/dummy/spec/factories/letters.rb +0 -7
- data/test/dummy/spec/factories/note_custom_asso_names.rb +0 -7
- data/test/dummy/spec/factories/notes.rb +0 -7
- data/test/dummy/spec/factories/post_custom_asso_names.rb +0 -7
- data/test/dummy/spec/factories/posts.rb +0 -7
- data/test/dummy/spec/factories/topics.rb +0 -7
- data/test/dummy/spec/factories/users.rb +0 -7
- data/test/dummy/spec/rails_helper.rb +0 -61
- data/test/dummy/spec/spec_helper.rb +0 -85
- data/test/test_helper.rb +0 -16
data/test/dummy/lib/assets/.keep
DELETED
File without changes
|
data/test/dummy/log/.keep
DELETED
File without changes
|
data/test/dummy/public/404.html
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
-
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
-
<style>
|
7
|
-
body {
|
8
|
-
background-color: #EFEFEF;
|
9
|
-
color: #2E2F30;
|
10
|
-
text-align: center;
|
11
|
-
font-family: arial, sans-serif;
|
12
|
-
margin: 0;
|
13
|
-
}
|
14
|
-
|
15
|
-
div.dialog {
|
16
|
-
width: 95%;
|
17
|
-
max-width: 33em;
|
18
|
-
margin: 4em auto 0;
|
19
|
-
}
|
20
|
-
|
21
|
-
div.dialog > div {
|
22
|
-
border: 1px solid #CCC;
|
23
|
-
border-right-color: #999;
|
24
|
-
border-left-color: #999;
|
25
|
-
border-bottom-color: #BBB;
|
26
|
-
border-top: #B00100 solid 4px;
|
27
|
-
border-top-left-radius: 9px;
|
28
|
-
border-top-right-radius: 9px;
|
29
|
-
background-color: white;
|
30
|
-
padding: 7px 12% 0;
|
31
|
-
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
-
}
|
33
|
-
|
34
|
-
h1 {
|
35
|
-
font-size: 100%;
|
36
|
-
color: #730E15;
|
37
|
-
line-height: 1.5em;
|
38
|
-
}
|
39
|
-
|
40
|
-
div.dialog > p {
|
41
|
-
margin: 0 0 1em;
|
42
|
-
padding: 1em;
|
43
|
-
background-color: #F7F7F7;
|
44
|
-
border: 1px solid #CCC;
|
45
|
-
border-right-color: #999;
|
46
|
-
border-left-color: #999;
|
47
|
-
border-bottom-color: #999;
|
48
|
-
border-bottom-left-radius: 4px;
|
49
|
-
border-bottom-right-radius: 4px;
|
50
|
-
border-top-color: #DADADA;
|
51
|
-
color: #666;
|
52
|
-
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
-
}
|
54
|
-
</style>
|
55
|
-
</head>
|
56
|
-
|
57
|
-
<body>
|
58
|
-
<!-- This file lives in public/404.html -->
|
59
|
-
<div class="dialog">
|
60
|
-
<div>
|
61
|
-
<h1>The page you were looking for doesn't exist.</h1>
|
62
|
-
<p>You may have mistyped the address or the page may have moved.</p>
|
63
|
-
</div>
|
64
|
-
<p>If you are the application owner check the logs for more information.</p>
|
65
|
-
</div>
|
66
|
-
</body>
|
67
|
-
</html>
|
data/test/dummy/public/422.html
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>The change you wanted was rejected (422)</title>
|
5
|
-
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
-
<style>
|
7
|
-
body {
|
8
|
-
background-color: #EFEFEF;
|
9
|
-
color: #2E2F30;
|
10
|
-
text-align: center;
|
11
|
-
font-family: arial, sans-serif;
|
12
|
-
margin: 0;
|
13
|
-
}
|
14
|
-
|
15
|
-
div.dialog {
|
16
|
-
width: 95%;
|
17
|
-
max-width: 33em;
|
18
|
-
margin: 4em auto 0;
|
19
|
-
}
|
20
|
-
|
21
|
-
div.dialog > div {
|
22
|
-
border: 1px solid #CCC;
|
23
|
-
border-right-color: #999;
|
24
|
-
border-left-color: #999;
|
25
|
-
border-bottom-color: #BBB;
|
26
|
-
border-top: #B00100 solid 4px;
|
27
|
-
border-top-left-radius: 9px;
|
28
|
-
border-top-right-radius: 9px;
|
29
|
-
background-color: white;
|
30
|
-
padding: 7px 12% 0;
|
31
|
-
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
-
}
|
33
|
-
|
34
|
-
h1 {
|
35
|
-
font-size: 100%;
|
36
|
-
color: #730E15;
|
37
|
-
line-height: 1.5em;
|
38
|
-
}
|
39
|
-
|
40
|
-
div.dialog > p {
|
41
|
-
margin: 0 0 1em;
|
42
|
-
padding: 1em;
|
43
|
-
background-color: #F7F7F7;
|
44
|
-
border: 1px solid #CCC;
|
45
|
-
border-right-color: #999;
|
46
|
-
border-left-color: #999;
|
47
|
-
border-bottom-color: #999;
|
48
|
-
border-bottom-left-radius: 4px;
|
49
|
-
border-bottom-right-radius: 4px;
|
50
|
-
border-top-color: #DADADA;
|
51
|
-
color: #666;
|
52
|
-
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
-
}
|
54
|
-
</style>
|
55
|
-
</head>
|
56
|
-
|
57
|
-
<body>
|
58
|
-
<!-- This file lives in public/422.html -->
|
59
|
-
<div class="dialog">
|
60
|
-
<div>
|
61
|
-
<h1>The change you wanted was rejected.</h1>
|
62
|
-
<p>Maybe you tried to change something you didn't have access to.</p>
|
63
|
-
</div>
|
64
|
-
<p>If you are the application owner check the logs for more information.</p>
|
65
|
-
</div>
|
66
|
-
</body>
|
67
|
-
</html>
|
data/test/dummy/public/500.html
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>We're sorry, but something went wrong (500)</title>
|
5
|
-
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
-
<style>
|
7
|
-
body {
|
8
|
-
background-color: #EFEFEF;
|
9
|
-
color: #2E2F30;
|
10
|
-
text-align: center;
|
11
|
-
font-family: arial, sans-serif;
|
12
|
-
margin: 0;
|
13
|
-
}
|
14
|
-
|
15
|
-
div.dialog {
|
16
|
-
width: 95%;
|
17
|
-
max-width: 33em;
|
18
|
-
margin: 4em auto 0;
|
19
|
-
}
|
20
|
-
|
21
|
-
div.dialog > div {
|
22
|
-
border: 1px solid #CCC;
|
23
|
-
border-right-color: #999;
|
24
|
-
border-left-color: #999;
|
25
|
-
border-bottom-color: #BBB;
|
26
|
-
border-top: #B00100 solid 4px;
|
27
|
-
border-top-left-radius: 9px;
|
28
|
-
border-top-right-radius: 9px;
|
29
|
-
background-color: white;
|
30
|
-
padding: 7px 12% 0;
|
31
|
-
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
-
}
|
33
|
-
|
34
|
-
h1 {
|
35
|
-
font-size: 100%;
|
36
|
-
color: #730E15;
|
37
|
-
line-height: 1.5em;
|
38
|
-
}
|
39
|
-
|
40
|
-
div.dialog > p {
|
41
|
-
margin: 0 0 1em;
|
42
|
-
padding: 1em;
|
43
|
-
background-color: #F7F7F7;
|
44
|
-
border: 1px solid #CCC;
|
45
|
-
border-right-color: #999;
|
46
|
-
border-left-color: #999;
|
47
|
-
border-bottom-color: #999;
|
48
|
-
border-bottom-left-radius: 4px;
|
49
|
-
border-bottom-right-radius: 4px;
|
50
|
-
border-top-color: #DADADA;
|
51
|
-
color: #666;
|
52
|
-
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
-
}
|
54
|
-
</style>
|
55
|
-
</head>
|
56
|
-
|
57
|
-
<body>
|
58
|
-
<!-- This file lives in public/500.html -->
|
59
|
-
<div class="dialog">
|
60
|
-
<div>
|
61
|
-
<h1>We're sorry, but something went wrong.</h1>
|
62
|
-
</div>
|
63
|
-
<p>If you are the application owner check the logs for more information.</p>
|
64
|
-
</div>
|
65
|
-
</body>
|
66
|
-
</html>
|
File without changes
|
@@ -1,275 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
RSpec.describe ActsAsCommentableMore do
|
4
|
-
|
5
|
-
describe "managed basic comment" do
|
6
|
-
it "add a comment" do
|
7
|
-
post = create(:post)
|
8
|
-
expect{post.comments.create(message: 'my message')}.to change(Comment, :count).by(1)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "gets all comment" do
|
12
|
-
posts = create_list(:post, 2)
|
13
|
-
posts.each do |post|
|
14
|
-
5.times { |i| post.comments.create(message: "message #{i}") }
|
15
|
-
expect(post.comments.count).to eq 5
|
16
|
-
end
|
17
|
-
expect(Comment.count).to eq 10
|
18
|
-
end
|
19
|
-
|
20
|
-
it "any role of user" do
|
21
|
-
post = create(:post)
|
22
|
-
admin = create(:admin)
|
23
|
-
user = create(:user)
|
24
|
-
user_comment = post.comments.create(message: 'my message', user: user)
|
25
|
-
admin_comment = post.comments.create(message: 'my message', user: admin)
|
26
|
-
expect(user_comment.user).to eq user
|
27
|
-
expect(admin_comment.user).to eq admin
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "class helper" do
|
31
|
-
context "self.find_comments_by_user(user, role: nil)" do
|
32
|
-
before do
|
33
|
-
post_1 = create(:post)
|
34
|
-
post_2 = create(:post)
|
35
|
-
@admin = create(:admin)
|
36
|
-
@user = create(:user)
|
37
|
-
user_comment_post_1 = post_1.comments.create(message: 'my message', user: @user)
|
38
|
-
admin_comment_post_1 = post_1.comments.create(message: 'my message', user: @admin)
|
39
|
-
user_comment_post_2 = post_2.comments.create(message: 'my message', user: @user)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "findby user and role=nil" do
|
43
|
-
Comment.find_comments_by_user(@user).each do |comment|
|
44
|
-
expect(comment.user).to eq @user
|
45
|
-
expect(comment.role).to eq 'comment'
|
46
|
-
end
|
47
|
-
Comment.find_comments_by_user(@admin).each do |comment|
|
48
|
-
expect(comment.user).to eq @admin
|
49
|
-
expect(comment.role).to eq 'comment'
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
it "find by user and role can find" do
|
54
|
-
Comment.find_comments_by_user(@user, :comment).each do |comment|
|
55
|
-
expect(comment.user).to eq @user
|
56
|
-
expect(comment.role).to eq 'comment'
|
57
|
-
end
|
58
|
-
Comment.find_comments_by_user(@admin, :comment).each do |comment|
|
59
|
-
expect(comment.user).to eq @admin
|
60
|
-
expect(comment.role).to eq 'comment'
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
it "find by user and role doesn't have" do
|
65
|
-
expect(Comment.find_comments_by_user(@user, :any_role).count).to eq 0
|
66
|
-
expect(Comment.find_comments_by_user(@admin, :any_role).count).to eq 0
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
describe "managed comments with association options(:class_name and :as)" do
|
75
|
-
it "add a comment" do
|
76
|
-
topic = create(:topic)
|
77
|
-
comment = topic.comments.build(message: 'my message')
|
78
|
-
expect{comment.save}.to change(CustomComment, :count).by(1)
|
79
|
-
expect(comment.role).to eq 'comment'
|
80
|
-
end
|
81
|
-
it "gets all comment" do
|
82
|
-
topics = create_list(:topic, 2)
|
83
|
-
topics.each do |topic|
|
84
|
-
5.times { |i| topic.comments.create(message: "message #{i}") }
|
85
|
-
expect(topic.comments.count).to eq 5
|
86
|
-
end
|
87
|
-
expect(CustomComment.count).to eq 10
|
88
|
-
end
|
89
|
-
it "any type of user" do
|
90
|
-
topic = create(:topic)
|
91
|
-
admin = create(:admin)
|
92
|
-
user = create(:user)
|
93
|
-
user_comment = topic.comments.create(message: 'my message', user: user)
|
94
|
-
admin_comment = topic.comments.create(message: 'my message', user: admin)
|
95
|
-
expect(user_comment.user).to eq user
|
96
|
-
expect(admin_comment.user).to eq admin
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
describe "managed comment that specific type" do
|
101
|
-
describe "socpe all_comments" do
|
102
|
-
|
103
|
-
it "default association options" do
|
104
|
-
note = create(:note)
|
105
|
-
5.times { |i| note.private_comments.create(message: 'private message') }
|
106
|
-
3.times { |i| note.public_comments.create(message: 'public message') }
|
107
|
-
|
108
|
-
other_note = create(:note)
|
109
|
-
5.times { |i| other_note.private_comments.create(message: 'private message') }
|
110
|
-
|
111
|
-
expect(note.all_comments.count).to eq 8
|
112
|
-
end
|
113
|
-
|
114
|
-
it "custom association options" do
|
115
|
-
letter = create(:letter)
|
116
|
-
5.times { |i| letter.hide_comments.create(message: 'hide message') }
|
117
|
-
8.times { |i| letter.show_comments.create(message: 'show message') }
|
118
|
-
|
119
|
-
other_letter = create(:letter)
|
120
|
-
5.times { |i| other_letter.show_comments.create(message: 'show message') }
|
121
|
-
|
122
|
-
expect(letter.all_comments.count).to eq 13
|
123
|
-
end
|
124
|
-
|
125
|
-
end
|
126
|
-
|
127
|
-
it "doesn't have comments association to get all comment" do
|
128
|
-
note = create(:note)
|
129
|
-
expect{ note.comments }.to raise_error(NoMethodError)
|
130
|
-
end
|
131
|
-
|
132
|
-
it "gets comment specific role by {role}_comments method" do
|
133
|
-
note = create(:note)
|
134
|
-
5.times { |i| note.private_comments.create(message: 'private message') }
|
135
|
-
3.times { |i| note.public_comments.create(message: 'public message') }
|
136
|
-
expect(note.private_comments.count).to eq 5
|
137
|
-
expect(note.public_comments.count).to eq 3
|
138
|
-
end
|
139
|
-
|
140
|
-
it "add comment specific role" do
|
141
|
-
note = create(:note)
|
142
|
-
|
143
|
-
private_note = note.private_comments.build(message: 'private message')
|
144
|
-
expect{private_note.save}.to change(Comment, :count).by(1)
|
145
|
-
expect(private_note.role).to eq 'private'
|
146
|
-
|
147
|
-
public_note = note.public_comments.build(message: 'public message')
|
148
|
-
expect{public_note.save}.to change(Comment, :count).by(1)
|
149
|
-
expect(public_note.role).to eq 'public'
|
150
|
-
end
|
151
|
-
|
152
|
-
describe "creates_{role}_{as}s method for adding comment of role" do
|
153
|
-
it "creates_private_comments" do
|
154
|
-
note = create(:note)
|
155
|
-
expect{note.creates_private_comments(message: 'new comment')}.to change(Comment, :count).by(1)
|
156
|
-
end
|
157
|
-
it "creates_public_comments" do
|
158
|
-
note = create(:note)
|
159
|
-
expect{note.creates_public_comments(message: 'new comment')}.to change(Comment, :count).by(1)
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
it "#to_role to change only" do
|
164
|
-
note = create(:note)
|
165
|
-
private_comment = note.private_comments.create(message: 'private message')
|
166
|
-
private_comment.to_public
|
167
|
-
expect(private_comment.role).to eq 'public'
|
168
|
-
private_comment.reload
|
169
|
-
expect(private_comment.role).to eq 'private'
|
170
|
-
end
|
171
|
-
it "#to_role! to change and update" do
|
172
|
-
note = create(:note)
|
173
|
-
private_comment = note.private_comments.create(message: 'private message')
|
174
|
-
private_comment.to_public!
|
175
|
-
expect(private_comment.role).to eq 'public'
|
176
|
-
private_comment.reload
|
177
|
-
expect(private_comment.role).to eq 'public'
|
178
|
-
end
|
179
|
-
|
180
|
-
it "#is_role? to check role value" do
|
181
|
-
note = create(:note)
|
182
|
-
private_comment = note.private_comments.create(message: 'private message')
|
183
|
-
expect(private_comment.is_private?).to eq true
|
184
|
-
expect(private_comment.is_public?).to eq false
|
185
|
-
end
|
186
|
-
|
187
|
-
|
188
|
-
describe "class helper" do
|
189
|
-
context "self.find_comments_by_user(user, role: nil)" do
|
190
|
-
before do
|
191
|
-
note_1 = create(:note)
|
192
|
-
note_2 = create(:note)
|
193
|
-
@admin = create(:admin)
|
194
|
-
@user = create(:user)
|
195
|
-
user_private_comment_note_1 = note_1.private_comments.create(message: 'private message user', user: @user)
|
196
|
-
user_public_comment_note_2 = note_2.public_comments.create(message: 'public message user', user: @user)
|
197
|
-
admin_comment_note_1 = note_1.public_comments.create(message: 'public message admin', user: @admin)
|
198
|
-
end
|
199
|
-
|
200
|
-
it "findby user and role=nil" do
|
201
|
-
Comment.find_comments_by_user(@user).each do |comment|
|
202
|
-
expect(comment.user).to eq @user
|
203
|
-
expect(comment.role).to eq('private').or eq('public')
|
204
|
-
end
|
205
|
-
Comment.find_comments_by_user(@admin).each do |comment|
|
206
|
-
expect(comment.user).to eq @admin
|
207
|
-
expect(comment.role).to eq('private').or eq('public')
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
it "find by user and role can find" do
|
212
|
-
Comment.find_comments_by_user(@user, :private).each do |comment|
|
213
|
-
expect(comment.user).to eq @user
|
214
|
-
expect(comment.role).to eq 'private'
|
215
|
-
end
|
216
|
-
Comment.find_comments_by_user(@admin, :public).each do |comment|
|
217
|
-
expect(comment.user).to eq @admin
|
218
|
-
expect(comment.role).to eq 'public'
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
it "find by user and role doesn't have" do
|
223
|
-
expect(Comment.find_comments_by_user(@user, :any_role).count).to eq 0
|
224
|
-
expect(Comment.find_comments_by_user(@admin, :any_role).count).to eq 0
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
describe "record related attributes" do
|
232
|
-
it "can update related_attributes feild with hash array" do
|
233
|
-
post = create(:post)
|
234
|
-
comment = post.comments.create(related_attributes: {user_id: 1, location_name: 'Thailand'})
|
235
|
-
expect(comment.related_attributes['user_id']).to eq nil
|
236
|
-
expect(comment.related_attributes['location_name']).to eq nil
|
237
|
-
expect(comment.related_attributes[:user_id]).to eq '1'
|
238
|
-
expect(comment.related_attributes[:location_name]).to eq 'Thailand'
|
239
|
-
end
|
240
|
-
|
241
|
-
end
|
242
|
-
|
243
|
-
describe "setting :as to custom association name" do
|
244
|
-
it "role= :as.singulize" do
|
245
|
-
post_custom = create(:post_custom_asso_name)
|
246
|
-
comment = post_custom.creates_custom_comments
|
247
|
-
expect(comment.role).to eq 'custom_comment'
|
248
|
-
end
|
249
|
-
it "doen't have any roles" do
|
250
|
-
post_custom = create(:post_custom_asso_name)
|
251
|
-
expect{post_custom.custom_comments}.not_to raise_error
|
252
|
-
expect{post_custom.creates_custom_comments()}.not_to raise_error
|
253
|
-
|
254
|
-
expect{post_custom.comments}.to raise_error(NoMethodError)
|
255
|
-
expect{post_custom.creates_comments()}.to raise_error(NoMethodError)
|
256
|
-
end
|
257
|
-
|
258
|
-
it "has roles" do
|
259
|
-
note_custom = create(:note_custom_asso_name)
|
260
|
-
expect{note_custom.all_custom_comments}.not_to raise_error
|
261
|
-
expect{note_custom.private_custom_comments}.not_to raise_error
|
262
|
-
expect{note_custom.public_custom_comments}.not_to raise_error
|
263
|
-
expect{note_custom.creates_public_custom_comments()}.not_to raise_error
|
264
|
-
expect{note_custom.creates_private_custom_comments()}.not_to raise_error
|
265
|
-
|
266
|
-
expect{note_custom.all_comments}.to raise_error(NoMethodError)
|
267
|
-
expect{note_custom.private_comments}.to raise_error(NoMethodError)
|
268
|
-
expect{note_custom.public_comments()}.to raise_error(NoMethodError)
|
269
|
-
expect{note_custom.creates_public_comments()}.to raise_error(NoMethodError)
|
270
|
-
expect{note_custom.creates_private_comments()}.to raise_error(NoMethodError)
|
271
|
-
end
|
272
|
-
|
273
|
-
end
|
274
|
-
|
275
|
-
end
|