proclaim 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +9 -0
  3. data/README.md +91 -10
  4. data/Rakefile +1 -1
  5. data/VERSION +1 -1
  6. data/app/assets/javascripts/proclaim/comments_handler.js.coffee +3 -0
  7. data/app/assets/stylesheets/proclaim/subscriptions.css.scss +33 -0
  8. data/app/controllers/proclaim/comments_controller.rb +3 -1
  9. data/app/controllers/proclaim/posts_controller.rb +10 -6
  10. data/app/controllers/proclaim/subscriptions_controller.rb +31 -14
  11. data/app/helpers/proclaim/application_helper.rb +3 -8
  12. data/app/models/proclaim/comment.rb +1 -0
  13. data/app/models/proclaim/post.rb +2 -0
  14. data/app/models/proclaim/subscription.rb +7 -6
  15. data/app/policies/proclaim/image_policy.rb +1 -1
  16. data/app/policies/proclaim/subscription_policy.rb +10 -6
  17. data/app/views/layouts/proclaim/subscription_mailer.html.erb +34 -4
  18. data/app/views/proclaim/posts/edit.html.erb +3 -1
  19. data/app/views/proclaim/posts/index.html.erb +2 -0
  20. data/app/views/proclaim/posts/new.html.erb +3 -1
  21. data/app/views/proclaim/posts/show.html.erb +3 -1
  22. data/app/views/proclaim/subscription_mailer/welcome_email.html.erb +9 -7
  23. data/app/views/proclaim/subscriptions/_form.html.erb +7 -2
  24. data/app/views/proclaim/subscriptions/index.html.erb +89 -0
  25. data/app/views/proclaim/subscriptions/new.html.erb +3 -1
  26. data/app/views/proclaim/subscriptions/show.html.erb +26 -0
  27. data/config/routes.rb +2 -6
  28. data/db/migrate/20150123115226_add_name_to_subscriptions.rb +7 -0
  29. data/lib/generators/proclaim/templates/initialize_proclaim.rb +19 -0
  30. data/lib/proclaim.rb +93 -0
  31. data/lib/proclaim/engine.rb +18 -0
  32. data/lib/proclaim/version.rb +1 -1
  33. data/test/controllers/proclaim/subscriptions_controller_test.rb +76 -21
  34. data/test/dummy/db/schema.rb +4 -3
  35. data/test/factories/proclaim/subscription.rb +1 -0
  36. data/test/integration/with_javascript/post_subscription_test.rb +29 -0
  37. data/test/integration/without_javascript/blog_subscription_test.rb +29 -2
  38. data/test/integration/without_javascript/manage_subscriptions_test.rb +37 -0
  39. data/test/integration/without_javascript/unsubscribe_test.rb +6 -6
  40. data/test/mailers/proclaim/subscription_mailer_test.rb +10 -6
  41. data/test/models/proclaim/subscription_test.rb +5 -0
  42. data/test/policies/proclaim/image_policy_test.rb +83 -0
  43. data/test/policies/proclaim/post_policy_test.rb +11 -0
  44. data/test/policies/proclaim/subscription_policy_test.rb +27 -15
  45. data/test/unit/proclaim/new_comment_callback_test.rb +62 -0
  46. data/test/unit/proclaim/new_subscription_callback_test.rb +62 -0
  47. data/test/unit/proclaim/post_published_callback_test.rb +74 -0
  48. metadata +15 -5
  49. data/app/views/proclaim/subscriptions/subscribed.html.erb +0 -7
  50. data/app/views/proclaim/subscriptions/unsubscribe.html.erb +0 -7
  51. data/app/views/proclaim/subscriptions/unsubscribed.html.erb +0 -3
@@ -0,0 +1,83 @@
1
+ require 'test_helper'
2
+
3
+ class ImagePolicyTest < ActiveSupport::TestCase
4
+ teardown do
5
+ image = Proclaim::Image.new
6
+ FileUtils.rm_rf(File.join(Rails.public_path, image.image.cache_dir))
7
+ FileUtils.rm_rf(File.join(Rails.public_path, image.image.store_dir))
8
+ end
9
+
10
+ test "image scope" do
11
+ user = FactoryGirl.create(:user)
12
+ image = FactoryGirl.create(:image)
13
+
14
+ # Verify that a user can view the image
15
+ images = Pundit.policy_scope(user, Proclaim::Image)
16
+ assert_includes images, image
17
+
18
+ # Verify that a guest cannot see any images
19
+ images = Pundit.policy_scope(nil, Proclaim::Image)
20
+ assert_empty images
21
+ end
22
+
23
+ test "image caching" do
24
+ user = FactoryGirl.create(:user)
25
+ image = FactoryGirl.build(:image)
26
+
27
+ # Verify that a user can cache an image
28
+ policy = Proclaim::ImagePolicy.new(user, image)
29
+ assert policy.cache?, "A user should be able to cache images"
30
+
31
+ # Verify that a guest cannot cache an image
32
+ policy = Proclaim::ImagePolicy.new(nil, image)
33
+ refute policy.cache?, "A guest should not be able to cache images"
34
+ end
35
+
36
+ test "image creation" do
37
+ user = FactoryGirl.create(:user)
38
+ image = FactoryGirl.build(:image)
39
+
40
+ # Verify that a user can create an image
41
+ policy = Proclaim::ImagePolicy.new(user, image)
42
+ assert policy.create?, "A user should be able to create images"
43
+
44
+ # Verify that a guest cannot create an image
45
+ policy = Proclaim::ImagePolicy.new(nil, image)
46
+ refute policy.create?, "A guest should not be able to create images"
47
+ end
48
+
49
+ test "image discard" do
50
+ user = FactoryGirl.create(:user)
51
+ cached_image = FactoryGirl.build(:image)
52
+ saved_image = FactoryGirl.create(:image)
53
+
54
+ # Verify that a user can discard a cached image
55
+ policy = Proclaim::ImagePolicy.new(user, cached_image)
56
+ assert policy.discard?, "A user should be able to discard a cached image"
57
+
58
+ # Verify that a user can discard a saved image
59
+ policy = Proclaim::ImagePolicy.new(user, saved_image)
60
+ assert policy.discard?, "A user should be able to discard a saved image"
61
+
62
+ # Verify that a guest cannot discard a cached image
63
+ policy = Proclaim::ImagePolicy.new(nil, cached_image)
64
+ refute policy.discard?, "A guest should not be able to discard a cached image"
65
+
66
+ # Verify that a guest cannot discard a saved image
67
+ policy = Proclaim::ImagePolicy.new(nil, saved_image)
68
+ refute policy.discard?, "A guest should not be able to discard a saved image"
69
+ end
70
+
71
+ test "image destroy" do
72
+ user = FactoryGirl.create(:user)
73
+ image = FactoryGirl.create(:image)
74
+
75
+ # Verify that a user can destroy an image
76
+ policy = Proclaim::ImagePolicy.new(user, image)
77
+ assert policy.destroy?, "A user should be able to destroy image"
78
+
79
+ # Verify that a guest cannot destroy an image
80
+ policy = Proclaim::ImagePolicy.new(nil, image)
81
+ refute policy.destroy?, "A guest should not be able to destroy image"
82
+ end
83
+ end
@@ -17,6 +17,17 @@ class PostPolicyTest < ActiveSupport::TestCase
17
17
  assert_includes posts, post2
18
18
  end
19
19
 
20
+ test "post index" do
21
+ user = FactoryGirl.create(:user)
22
+
23
+ # Verify that a user can visit the index
24
+ policy = Proclaim::PostPolicy.new(user, Proclaim::Post)
25
+ assert policy.index?, "A user should be able to visit the index"
26
+
27
+ # Verify that a guest can also visit the index
28
+ policy = Proclaim::PostPolicy.new(nil, Proclaim::Post)
29
+ assert policy.index?, "A guest should be able to visit the index"
30
+ end
20
31
 
21
32
  test "post create" do
22
33
  user = FactoryGirl.create(:user)
@@ -13,7 +13,32 @@ class SubscriptionPolicyTest < ActiveSupport::TestCase
13
13
 
14
14
  # Verify that without a user, no subscription can be seen
15
15
  subscriptions = Pundit.policy_scope(nil, Proclaim::Subscription)
16
- assert_nil subscriptions
16
+ assert_empty subscriptions
17
+ end
18
+
19
+ test "subscription index" do
20
+ user = FactoryGirl.create(:user)
21
+
22
+ # Verify that a user can visit the index
23
+ policy = Proclaim::SubscriptionPolicy.new(user, Proclaim::Subscription)
24
+ assert policy.index?, "A user should be able to visit the index"
25
+
26
+ # Verify that a guest cannot visit the index
27
+ policy = Proclaim::SubscriptionPolicy.new(nil, Proclaim::Subscription)
28
+ refute policy.index?, "A guest should not be able to visit the index"
29
+ end
30
+
31
+ test "subscription show" do
32
+ user = FactoryGirl.create(:user)
33
+ subscription = FactoryGirl.create(:subscription)
34
+
35
+ # Verify that a user can view a subscription
36
+ policy = Proclaim::SubscriptionPolicy.new(user, subscription)
37
+ assert policy.show?, "A user should be able to view a subscription"
38
+
39
+ # Verify that a guest can also view a subscription
40
+ policy = Proclaim::SubscriptionPolicy.new(nil, subscription)
41
+ assert policy.show?, "A guest should be able to view a subscription"
17
42
  end
18
43
 
19
44
  test "subscription creation" do
@@ -54,7 +79,7 @@ class SubscriptionPolicyTest < ActiveSupport::TestCase
54
79
  user = FactoryGirl.create(:user)
55
80
  subscription = FactoryGirl.create(:subscription)
56
81
 
57
- # Verify that a even a user can't update a subscription (for now)
82
+ # Verify that a even a user can't update a subscription
58
83
  policy = Proclaim::SubscriptionPolicy.new(user, subscription)
59
84
  refute policy.update?, "A user should not be able to update subscriptions!"
60
85
 
@@ -63,19 +88,6 @@ class SubscriptionPolicyTest < ActiveSupport::TestCase
63
88
  refute policy.update?, "A guest should not be able to update subscription!"
64
89
  end
65
90
 
66
- test "subscription unsubscribe" do
67
- user = FactoryGirl.create(:user)
68
- subscription = FactoryGirl.create(:subscription)
69
-
70
- # Verify that a user can unsubscribe
71
- policy = Proclaim::SubscriptionPolicy.new(user, subscription)
72
- assert policy.unsubscribe?, "A user should be able to unsubscribe!"
73
-
74
- # Verify that a guest can also unsubscribe
75
- policy = Proclaim::SubscriptionPolicy.new(nil, subscription)
76
- assert policy.unsubscribe?, "A guest should be able to unsubscribe!"
77
- end
78
-
79
91
  test "subscription destroy" do
80
92
  user = FactoryGirl.create(:user)
81
93
  subscription = FactoryGirl.create(:subscription)
@@ -0,0 +1,62 @@
1
+ # == Schema Information
2
+ #
3
+ # Table name: proclaim_comments
4
+ #
5
+ # id :integer not null, primary key
6
+ # post_id :integer
7
+ # parent_id :integer
8
+ # author :string
9
+ # body :text
10
+ # created_at :datetime not null
11
+ # updated_at :datetime not null
12
+ #
13
+
14
+ require 'test_helper'
15
+
16
+ module Proclaim
17
+ class NewCommentCallbackTest < ActiveSupport::TestCase
18
+ setup do
19
+ @callback_called = false
20
+
21
+ Proclaim.after_new_comment do
22
+ @callback_called = true
23
+ end
24
+ end
25
+
26
+ teardown do
27
+ Proclaim.reset_new_comment_callbacks
28
+ end
29
+
30
+ test "ensure callback supports blocks and procs" do
31
+ assert_nothing_raised do
32
+ Proclaim.after_new_comment lambda {|comment| puts "test Proc"}
33
+ end
34
+
35
+ assert_nothing_raised do
36
+ Proclaim.after_new_comment do
37
+ puts "test block"
38
+ end
39
+ end
40
+
41
+ assert_raise RuntimeError do
42
+ Proclaim.after_new_comment :foo
43
+ end
44
+ end
45
+
46
+ test "ensure callback is called when created" do
47
+ comment = FactoryGirl.build(:comment)
48
+ refute @callback_called
49
+
50
+ comment.save
51
+ assert @callback_called
52
+ end
53
+
54
+ test "ensure callback is not called when updated" do
55
+ comment = FactoryGirl.create(:comment)
56
+ @callback_called = false
57
+
58
+ comment.save
59
+ refute @callback_called
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,62 @@
1
+ # == Schema Information
2
+ #
3
+ # Table name: proclaim_comments
4
+ #
5
+ # id :integer not null, primary key
6
+ # post_id :integer
7
+ # parent_id :integer
8
+ # author :string
9
+ # body :text
10
+ # created_at :datetime not null
11
+ # updated_at :datetime not null
12
+ #
13
+
14
+ require 'test_helper'
15
+
16
+ module Proclaim
17
+ class NewSubscriptionCallbackTest < ActiveSupport::TestCase
18
+ setup do
19
+ @callback_called = false
20
+
21
+ Proclaim.after_new_subscription do
22
+ @callback_called = true
23
+ end
24
+ end
25
+
26
+ teardown do
27
+ Proclaim.reset_new_subscription_callbacks
28
+ end
29
+
30
+ test "ensure callback supports blocks and procs" do
31
+ assert_nothing_raised do
32
+ Proclaim.after_new_subscription lambda {|subscription| puts "test Proc"}
33
+ end
34
+
35
+ assert_nothing_raised do
36
+ Proclaim.after_new_subscription do
37
+ puts "test block"
38
+ end
39
+ end
40
+
41
+ assert_raise RuntimeError do
42
+ Proclaim.after_new_subscription :foo
43
+ end
44
+ end
45
+
46
+ test "ensure callback is called when created" do
47
+ subscription = FactoryGirl.build(:subscription)
48
+ refute @callback_called
49
+
50
+ subscription.save
51
+ assert @callback_called
52
+ end
53
+
54
+ test "ensure callback is not called when updated" do
55
+ subscription = FactoryGirl.create(:subscription)
56
+ @callback_called = false
57
+
58
+ subscription.save
59
+ refute @callback_called
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,74 @@
1
+ # == Schema Information
2
+ #
3
+ # Table name: proclaim_comments
4
+ #
5
+ # id :integer not null, primary key
6
+ # post_id :integer
7
+ # parent_id :integer
8
+ # author :string
9
+ # body :text
10
+ # created_at :datetime not null
11
+ # updated_at :datetime not null
12
+ #
13
+
14
+ require 'test_helper'
15
+
16
+ module Proclaim
17
+ class PostPublishedCallbackTest < ActiveSupport::TestCase
18
+ setup do
19
+ @callback_called = false
20
+
21
+ Proclaim.after_post_published do
22
+ @callback_called = true
23
+ end
24
+ end
25
+
26
+ teardown do
27
+ Proclaim.reset_post_published_callbacks
28
+ end
29
+
30
+ test "ensure callback supports blocks and procs" do
31
+ assert_nothing_raised do
32
+ Proclaim.after_post_published lambda {|post| puts "test Proc"}
33
+ end
34
+
35
+ assert_nothing_raised do
36
+ Proclaim.after_post_published do
37
+ puts "test block"
38
+ end
39
+ end
40
+
41
+ assert_raise RuntimeError do
42
+ Proclaim.after_post_published :foo
43
+ end
44
+ end
45
+
46
+ test "ensure callback is called when published" do
47
+ post = FactoryGirl.build(:post)
48
+ refute @callback_called
49
+
50
+ post.publish
51
+ refute @callback_called # Not saved yet, so callbacks shouldn't happen
52
+
53
+ post.save
54
+ assert @callback_called
55
+ end
56
+
57
+ test "ensure callback is not called when created" do
58
+ post = FactoryGirl.build(:post)
59
+ refute @callback_called
60
+
61
+ post.save
62
+ refute @callback_called,
63
+ "Callback shouldn't be called unless the post is published!"
64
+ end
65
+
66
+ test "ensure callback is not called when updated" do
67
+ post = FactoryGirl.create(:post)
68
+ @callback_called = false
69
+
70
+ post.save
71
+ refute @callback_called
72
+ end
73
+ end
74
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proclaim
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Fazzari
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-23 00:00:00.000000000 Z
11
+ date: 2015-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -392,16 +392,16 @@ files:
392
392
  - app/views/proclaim/subscription_mailer/new_post_notification_email.html.erb
393
393
  - app/views/proclaim/subscription_mailer/welcome_email.html.erb
394
394
  - app/views/proclaim/subscriptions/_form.html.erb
395
+ - app/views/proclaim/subscriptions/index.html.erb
395
396
  - app/views/proclaim/subscriptions/new.html.erb
396
- - app/views/proclaim/subscriptions/subscribed.html.erb
397
- - app/views/proclaim/subscriptions/unsubscribe.html.erb
398
- - app/views/proclaim/subscriptions/unsubscribed.html.erb
397
+ - app/views/proclaim/subscriptions/show.html.erb
399
398
  - config/routes.rb
400
399
  - db/migrate/20141108222616_create_proclaim_posts.rb
401
400
  - db/migrate/20141114235359_create_proclaim_comments.rb
402
401
  - db/migrate/20141115022230_create_proclaim_comment_hierarchies.rb
403
402
  - db/migrate/20141210234057_create_proclaim_subscriptions.rb
404
403
  - db/migrate/20141222224905_create_proclaim_images.rb
404
+ - db/migrate/20150123115226_add_name_to_subscriptions.rb
405
405
  - lib/generators/proclaim/install_generator.rb
406
406
  - lib/generators/proclaim/templates/README
407
407
  - lib/generators/proclaim/templates/initialize_proclaim.rb
@@ -464,6 +464,7 @@ files:
464
464
  - test/integration/with_javascript/post_show_test.rb
465
465
  - test/integration/with_javascript/post_subscription_test.rb
466
466
  - test/integration/without_javascript/blog_subscription_test.rb
467
+ - test/integration/without_javascript/manage_subscriptions_test.rb
467
468
  - test/integration/without_javascript/post_test.rb
468
469
  - test/integration/without_javascript/subscription_email_test.rb
469
470
  - test/integration/without_javascript/unsubscribe_test.rb
@@ -474,6 +475,7 @@ files:
474
475
  - test/models/proclaim/post_test.rb
475
476
  - test/models/proclaim/subscription_test.rb
476
477
  - test/policies/proclaim/comment_policy_test.rb
478
+ - test/policies/proclaim/image_policy_test.rb
477
479
  - test/policies/proclaim/post_policy_test.rb
478
480
  - test/policies/proclaim/subscription_policy_test.rb
479
481
  - test/proclaim_test.rb
@@ -482,6 +484,9 @@ files:
482
484
  - test/support/pages/posts/show_page.rb
483
485
  - test/support/wait_for_ajax.rb
484
486
  - test/test_helper.rb
487
+ - test/unit/proclaim/new_comment_callback_test.rb
488
+ - test/unit/proclaim/new_subscription_callback_test.rb
489
+ - test/unit/proclaim/post_published_callback_test.rb
485
490
  - vendor/assets/images/link.png
486
491
  - vendor/assets/images/remove.png
487
492
  - vendor/assets/images/resize-bigger.png
@@ -563,7 +568,11 @@ test_files:
563
568
  - test/integration/without_javascript/post_test.rb
564
569
  - test/integration/without_javascript/subscription_email_test.rb
565
570
  - test/integration/without_javascript/unsubscribe_test.rb
571
+ - test/integration/without_javascript/manage_subscriptions_test.rb
566
572
  - test/integration/without_javascript/blog_subscription_test.rb
573
+ - test/unit/proclaim/new_comment_callback_test.rb
574
+ - test/unit/proclaim/post_published_callback_test.rb
575
+ - test/unit/proclaim/new_subscription_callback_test.rb
567
576
  - test/proclaim_test.rb
568
577
  - test/support/pages/posts/edit_page.rb
569
578
  - test/support/pages/posts/show_page.rb
@@ -588,6 +597,7 @@ test_files:
588
597
  - test/controllers/proclaim/images_controller_test.rb
589
598
  - test/controllers/proclaim/subscriptions_controller_test.rb
590
599
  - test/controllers/proclaim/posts_controller_test.rb
600
+ - test/policies/proclaim/image_policy_test.rb
591
601
  - test/policies/proclaim/post_policy_test.rb
592
602
  - test/policies/proclaim/subscription_policy_test.rb
593
603
  - test/policies/proclaim/comment_policy_test.rb