kublog 0.0.1.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -5
- data/.rspec +2 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +89 -77
- data/README.rdoc +102 -61
- data/Rakefile +5 -10
- data/app/assets/javascripts/kublog/email.js.coffee +24 -9
- data/app/assets/javascripts/kublog/posts.js.coffee +46 -19
- data/app/assets/javascripts/kublog/shared.js.coffee.erb +1 -1
- data/app/assets/javascripts/kublog/wysiwyg.controls.js.coffee +0 -1
- data/app/assets/plugins/kublog/ajaxyupload/javascripts/jquery.ajaxyupload.js +1 -1
- data/app/assets/stylesheets/kublog/posts.css +2 -2
- data/app/controllers/kublog/application_controller.rb +18 -2
- data/app/controllers/kublog/categories_controller.rb +2 -2
- data/app/controllers/kublog/notifications_controller.rb +13 -0
- data/app/controllers/kublog/posts_controller.rb +7 -18
- data/app/helpers/kublog/application_helper.rb +15 -0
- data/app/helpers/kublog/notifications_helper.rb +4 -0
- data/app/helpers/kublog/posts_helper.rb +4 -0
- data/app/jobs/kublog/deliver_comment.rb +14 -0
- data/app/mailers/kublog/comment_mailer.rb +11 -0
- data/app/mailers/kublog/post_mailer.rb +4 -5
- data/app/models/kublog/category.rb +13 -5
- data/app/models/kublog/comment.rb +17 -6
- data/app/models/kublog/notification.rb +27 -0
- data/app/models/kublog/post.rb +11 -6
- data/app/presenters/kublog/post_form_presenter.rb +19 -0
- data/app/presenters/kublog/posts_presenter.rb +7 -1
- data/app/uploaders/kublog/file_uploader.rb +0 -3
- data/app/views/kublog/comment_mailer/new_comment.html.erb +11 -0
- data/app/views/kublog/post_mailer/new_post.html.erb +1 -1
- data/app/views/kublog/post_mailer/new_post.liquid.html.erb +9 -1
- data/app/views/kublog/posts/_email_form.html.erb +27 -9
- data/app/views/kublog/posts/_facebook_form.html.erb +10 -0
- data/app/views/kublog/posts/_form.html.erb +7 -45
- data/app/views/kublog/posts/_twitter_form.html.erb +11 -0
- data/app/views/kublog/posts/edit.html.erb +1 -1
- data/app/views/kublog/posts/index.atom.builder +1 -2
- data/app/views/kublog/posts/index.rss.builder +20 -0
- data/app/views/kublog/posts/new.html.erb +1 -1
- data/config/locales/kublog/en.yml +9 -0
- data/config/routes.rb +8 -0
- data/db/migrate/20110816211552_create_kublog_posts.rb +1 -9
- data/db/migrate/20110901205127_create_kublog_notifications.rb +18 -0
- data/index.html +10 -0
- data/kublog.gemspec +10 -10
- data/lib/generators/kublog/install/USAGE +8 -0
- data/lib/generators/kublog/install/install_generator.rb +78 -0
- data/lib/generators/kublog/install/templates/configuration.rb.tt +45 -0
- data/lib/kublog.rb +43 -13
- data/lib/kublog/author.rb +2 -3
- data/lib/kublog/engine.rb +1 -0
- data/lib/kublog/network/email.rb +113 -0
- data/lib/kublog/network/facebook.rb +54 -0
- data/lib/kublog/network/twitter.rb +55 -0
- data/lib/kublog/notifiable.rb +2 -5
- data/lib/kublog/processor.rb +27 -0
- data/lib/kublog/version.rb +2 -2
- data/script/rails +1 -1
- data/{test → spec}/dummy/Rakefile +0 -0
- data/{test → spec}/dummy/app/assets/javascripts/application.js +0 -0
- data/{test → spec}/dummy/app/assets/javascripts/sessions.js +0 -0
- data/{test → spec}/dummy/app/assets/javascripts/users.js +0 -0
- data/{test → spec}/dummy/app/assets/stylesheets/application.css +0 -0
- data/{test → spec}/dummy/app/assets/stylesheets/sessions.css +0 -0
- data/{test → spec}/dummy/app/assets/stylesheets/users.css +0 -0
- data/{test → spec}/dummy/app/controllers/application_controller.rb +0 -0
- data/{test → spec}/dummy/app/controllers/sessions_controller.rb +0 -0
- data/{test → spec}/dummy/app/controllers/users_controller.rb +0 -0
- data/{test → spec}/dummy/app/helpers/application_helper.rb +0 -0
- data/{test → spec}/dummy/app/helpers/error_messages_helper.rb +0 -0
- data/{test → spec}/dummy/app/helpers/layout_helper.rb +0 -0
- data/{test → spec}/dummy/app/helpers/sessions_helper.rb +0 -0
- data/{test → spec}/dummy/app/helpers/users_helper.rb +0 -0
- data/{test → spec}/dummy/app/mailers/.gitkeep +0 -0
- data/{test → spec}/dummy/app/models/.gitkeep +0 -0
- data/{test → spec}/dummy/app/models/ability.rb +0 -0
- data/{test → spec}/dummy/app/models/user.rb +1 -5
- data/{test → spec}/dummy/app/views/layouts/_account.html.erb +0 -0
- data/{test → spec}/dummy/app/views/layouts/application.html.erb +0 -0
- data/{test → spec}/dummy/app/views/layouts/kublog/application.html.erb +0 -0
- data/{test → spec}/dummy/app/views/sessions/new.html.erb +0 -0
- data/{test → spec}/dummy/app/views/users/new.html.erb +0 -0
- data/{test → spec}/dummy/config.ru +0 -0
- data/{test → spec}/dummy/config/application.rb +0 -0
- data/{test → spec}/dummy/config/boot.rb +0 -0
- data/{test → spec}/dummy/config/database.yml +0 -0
- data/{test → spec}/dummy/config/environment.rb +0 -0
- data/{test → spec}/dummy/config/environments/development.rb +0 -0
- data/{test → spec}/dummy/config/environments/production.rb +0 -0
- data/{test → spec}/dummy/config/environments/test.rb +0 -0
- data/{test → spec}/dummy/config/initializers/backtrace_silencers.rb +0 -0
- data/{test → spec}/dummy/config/initializers/inflections.rb +0 -0
- data/spec/dummy/config/initializers/kublog.rb +34 -0
- data/{test → spec}/dummy/config/initializers/mime_types.rb +0 -0
- data/{test → spec}/dummy/config/initializers/secret_token.rb +0 -0
- data/{test → spec}/dummy/config/initializers/session_store.rb +0 -0
- data/{test → spec}/dummy/config/initializers/wrap_parameters.rb +0 -0
- data/{test → spec}/dummy/config/locales/en.yml +9 -0
- data/{test → spec}/dummy/config/routes.rb +0 -0
- data/{test → spec}/dummy/db/migrate/20110816225222_create_users.rb +1 -0
- data/{test → spec}/dummy/db/migrate/20110819135547_create_delayed_jobs.rb +0 -0
- data/{test → spec}/dummy/db/schema.rb +16 -10
- data/{test → spec}/dummy/lib/assets/.gitkeep +0 -0
- data/{test → spec}/dummy/log/.gitkeep +0 -0
- data/{test → spec}/dummy/public/404.html +0 -0
- data/{test → spec}/dummy/public/422.html +0 -0
- data/{test → spec}/dummy/public/500.html +0 -0
- data/{test → spec}/dummy/public/favicon.ico +0 -0
- data/{test → spec}/dummy/script/delayed_job +0 -0
- data/{test → spec}/dummy/script/rails +0 -0
- data/spec/factories.rb +54 -0
- data/spec/fixtures/Adrian.png +0 -0
- data/spec/fixtures/rendered_email.html +15 -0
- data/spec/lib/author_spec.rb +25 -0
- data/spec/lib/network/email_spec.rb +113 -0
- data/spec/lib/network/facebook_spec.rb +68 -0
- data/spec/lib/network/twitter_spec.rb +68 -0
- data/spec/lib/notifiable_spec.rb +23 -0
- data/spec/lib/processor_spec.rb +25 -0
- data/spec/models/kublog/category_spec.rb +43 -0
- data/spec/models/kublog/comment_spec.rb +56 -0
- data/spec/models/kublog/image_spec.rb +37 -0
- data/spec/models/kublog/notification_spec.rb +53 -0
- data/spec/models/kublog/post_spec.rb +63 -0
- data/spec/spec_helper.rb +43 -0
- metadata +198 -208
- data/app/assets/stylesheets/kublog/categories.css +0 -4
- data/app/assets/stylesheets/kublog/comments.css +0 -4
- data/lib/kublog/notification/email.rb +0 -86
- data/lib/kublog/notification/email_job.rb +0 -14
- data/lib/kublog/notification/fb_post.rb +0 -43
- data/lib/kublog/notification/fb_post_job.rb +0 -16
- data/lib/kublog/notification/tweet.rb +0 -68
- data/lib/kublog/notification/tweet_job.rb +0 -16
- data/test/dummy/test/fixtures/users.yml +0 -9
- data/test/dummy/test/functional/sessions_controller_test.rb +0 -7
- data/test/dummy/test/functional/users_controller_test.rb +0 -7
- data/test/dummy/test/unit/helpers/sessions_helper_test.rb +0 -4
- data/test/dummy/test/unit/helpers/users_helper_test.rb +0 -4
- data/test/dummy/test/unit/user_test.rb +0 -7
- data/test/factories.rb +0 -9
- data/test/fixtures/kublog/categories.yml +0 -7
- data/test/fixtures/kublog/comments.yml +0 -7
- data/test/fixtures/kublog/images.yml +0 -9
- data/test/fixtures/kublog/posts.yml +0 -9
- data/test/functional/kublog/categories_controller_test.rb +0 -9
- data/test/functional/kublog/comments_controller_test.rb +0 -9
- data/test/functional/kublog/images_controller_test.rb +0 -9
- data/test/functional/kublog/post_mailer_test.rb +0 -9
- data/test/functional/kublog/posts_controller_test.rb +0 -9
- data/test/integration/navigation_test.rb +0 -10
- data/test/kublog_test.rb +0 -7
- data/test/test_helper.rb +0 -12
- data/test/unit/helpers/kublog/categories_helper_test.rb +0 -6
- data/test/unit/helpers/kublog/comments_helper_test.rb +0 -6
- data/test/unit/helpers/kublog/images_helper_test.rb +0 -6
- data/test/unit/helpers/kublog/posts_helper_test.rb +0 -6
- data/test/unit/kublog/category_test.rb +0 -9
- data/test/unit/kublog/comment_test.rb +0 -9
- data/test/unit/kublog/image_test.rb +0 -9
- data/test/unit/kublog/post_test.rb +0 -19
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Kublog::Network
|
4
|
+
describe Email do
|
5
|
+
|
6
|
+
describe '#validate' do
|
7
|
+
before :all do
|
8
|
+
@notification = Factory.build(:email_notification)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'is valid with content and kind' do
|
12
|
+
@notification.should be_valid
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'is invalid without tweet content' do
|
16
|
+
@notification.content = ''
|
17
|
+
@notification.should_not be_valid
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#email?' do
|
22
|
+
before :all do
|
23
|
+
@notification = Factory.build(:email_notification)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'is true when kind is twitter' do
|
27
|
+
@notification.email?.should == true
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'is false when other than twitter' do
|
31
|
+
@notification.kind = 'twitter'
|
32
|
+
@notification.email?.should == false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#default_email?' do
|
37
|
+
before :all do
|
38
|
+
@notification = Factory.build(:email_notification, :post => Kublog::Post.new)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'is false always' do
|
42
|
+
@notification.default_email.should == false
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#delivered' do
|
47
|
+
before(:all) do
|
48
|
+
@notification = Factory(:email_notification)
|
49
|
+
end
|
50
|
+
it 'increases the number of delivered times' do
|
51
|
+
@notification.update_attribute :times_delivered, 0
|
52
|
+
@notification.delivered
|
53
|
+
@notification.times_delivered.should == 1
|
54
|
+
end
|
55
|
+
it 'increases to 1 if delivered times is nil' do
|
56
|
+
@notification.update_attribute :times_delivered, nil
|
57
|
+
@notification.reload.delivered
|
58
|
+
@notification.times_delivered.should == 1
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#after_create' do
|
63
|
+
it 'sends emails to all users when notify_post? is default true' do
|
64
|
+
notification = Factory.build(:email_notification)
|
65
|
+
Kublog::Processor.should_receive(:work)
|
66
|
+
notification.save
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '.email_template' do
|
71
|
+
before :all do
|
72
|
+
@post = Factory :post, :body => 'Hello'
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'renders the body of the post as the template' do
|
76
|
+
Kublog::Notification.email_template(@post).should == Support.fixture('rendered_email.html')
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe Email::BulkEmail do
|
81
|
+
before :all do
|
82
|
+
User.destroy_all
|
83
|
+
2.times { Factory(:user) }
|
84
|
+
@bulk_email = Email::BulkEmail.new(Factory(:email_notification))
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '#perform' do
|
88
|
+
it 'sends e-mails to all users when notify_post? is true' do
|
89
|
+
notification = Factory.build(:email_notification)
|
90
|
+
Kublog::Processor.should_receive(:work).exactly(User.count).times
|
91
|
+
@bulk_email.perform
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'sends e-mail to no users when notify_post? defaults to false' do
|
95
|
+
Support.dont_notify_users_by_default
|
96
|
+
Kublog::Processor.should_not_receive(:work)
|
97
|
+
@bulk_email.perform
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'evaluates notify_post? before sending e-mails' do
|
101
|
+
Support.notify_select_users
|
102
|
+
Factory(:user, :kind => 'cool')
|
103
|
+
notification = Factory.build(:email_notification, :roles => ['cool'])
|
104
|
+
bulk_email = Email::BulkEmail.new(notification)
|
105
|
+
Kublog::Processor.should_receive(:work).once
|
106
|
+
bulk_email.perform
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Kublog::Network::Facebook do
|
4
|
+
|
5
|
+
describe '#validate' do
|
6
|
+
|
7
|
+
before :all do
|
8
|
+
@notification = Factory.build(:facebook_notification)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'is valid with content and kind' do
|
12
|
+
@notification.should be_valid
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'is invalid without tweet content' do
|
16
|
+
@notification.content = ''
|
17
|
+
@notification.should_not be_valid
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#facebook?' do
|
22
|
+
|
23
|
+
before :all do
|
24
|
+
@notification = Factory.build(:facebook_notification)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'is true when kind is twitter' do
|
28
|
+
@notification.facebook?.should == true
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'is false when other than twitter' do
|
32
|
+
@notification.kind = 'email'
|
33
|
+
@notification.facebook?.should == false
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'default_twitter?' do
|
39
|
+
|
40
|
+
before :all do
|
41
|
+
@notification = Factory.build(:facebook_notification, :post => Kublog::Post.new)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'is true when building a new post' do
|
45
|
+
@notification.default_facebook.should == true
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'is false when updating a post' do
|
49
|
+
@notification.post = Factory(:post)
|
50
|
+
@notification.default_facebook.should == false
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#after_create' do
|
56
|
+
|
57
|
+
before :all do
|
58
|
+
@notification = Factory.build(:facebook_notification, :content => 'test content')
|
59
|
+
@post = @notification.post
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should send the content of the notification + a link to the post to twitter' do
|
63
|
+
Kublog.facebook_client.should_receive(:link!).with(:link => @post.url, :message => 'test content')
|
64
|
+
@notification.save
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Kublog::Network::Twitter do
|
4
|
+
|
5
|
+
describe '#validate' do
|
6
|
+
|
7
|
+
before :all do
|
8
|
+
@notification =Factory.build(:twitter_notification)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'is valid with content and kind' do
|
12
|
+
@notification.should be_valid
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'is invalid without tweet content' do
|
16
|
+
@notification.content = ''
|
17
|
+
@notification.should_not be_valid
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#twitter?' do
|
22
|
+
|
23
|
+
before :all do
|
24
|
+
@notification = Factory.build(:twitter_notification)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'is true when kind is twitter' do
|
28
|
+
@notification.twitter?.should == true
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'is false when other than twitter' do
|
32
|
+
@notification.kind = 'facebook'
|
33
|
+
@notification.twitter?.should == false
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'default_twitter?' do
|
39
|
+
|
40
|
+
before :all do
|
41
|
+
@notification = Factory.build(:twitter_notification, :post => Kublog::Post.new)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'is true when building a new post' do
|
45
|
+
@notification.default_twitter.should == true
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'is false when updating a post' do
|
49
|
+
@notification.post = Factory(:post)
|
50
|
+
@notification.default_twitter.should == false
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#after_create' do
|
56
|
+
|
57
|
+
before :all do
|
58
|
+
@notification = Factory.build(:twitter_notification, :content => 'test content')
|
59
|
+
@post = @notification.post
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should send the content of the notification + a link to the post to twitter' do
|
63
|
+
Kublog.twitter_client.should_receive(:update).with("test content #{@post.url}")
|
64
|
+
@notification.save
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Kublog::Notifiable do
|
4
|
+
|
5
|
+
class TestUser; end
|
6
|
+
|
7
|
+
describe '.included' do
|
8
|
+
|
9
|
+
before :all do
|
10
|
+
TestUser.send :include, Kublog::Notifiable
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'sets up a configuration variable for the user class to notify to' do
|
14
|
+
Kublog.notify_class.should == 'TestUser'
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'defaults notify_post? to true' do
|
18
|
+
TestUser.new.notify_post?(Kublog::Post.new).should == true
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Kublog::Processor do
|
4
|
+
|
5
|
+
class TestTask
|
6
|
+
def perform
|
7
|
+
true
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '.work' do
|
12
|
+
|
13
|
+
it 'performs a task immediately if notification processing is immediate' do
|
14
|
+
Kublog.notification_processing = :immediate
|
15
|
+
Kublog::Processor.work(TestTask.new).should == true
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'creates a job in delayed job for later processing' do
|
19
|
+
Kublog.notification_processing = :delayed_job
|
20
|
+
Kublog::Processor.work(TestTask.new).should be_an_instance_of(Delayed::Backend::ActiveRecord::Job)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Kublog::Category do
|
4
|
+
|
5
|
+
describe '#validate' do
|
6
|
+
before :each do
|
7
|
+
@category = Factory :category
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'is valid with the mandatory attributes' do
|
11
|
+
@category.should be_valid
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'is invalid without a name' do
|
15
|
+
@category.name = ''
|
16
|
+
@category.should_not be_valid
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#to_s' do
|
22
|
+
it 'is the titleized version of the name' do
|
23
|
+
Factory.build(:category, :name => 'some name').to_s.should == 'Some Name'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#as_json' do
|
28
|
+
before :all do
|
29
|
+
@json = JSON.parse(Factory(:category).to_json)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'includes the name of the category' do
|
33
|
+
@json["name"].match('Features').should_not be_nil
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'includes the path to the category' do
|
37
|
+
@json["path"].match(/features/).should_not be_nil
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Kublog::Comment do
|
4
|
+
describe '#validate' do
|
5
|
+
it 'is valid with an associated user' do
|
6
|
+
Factory.build(:user_comment).should be_valid
|
7
|
+
end
|
8
|
+
it 'is valid with a complete anonimous user' do
|
9
|
+
Factory.build(:anonymous_comment).should be_valid
|
10
|
+
end
|
11
|
+
it 'is not valid with an empty comment' do
|
12
|
+
Factory.build(:user_comment, :body => '').should_not be_valid
|
13
|
+
Factory.build(:anonymous_comment, :body => '').should_not be_valid
|
14
|
+
end
|
15
|
+
it 'is not valid to be anonymous without email' do
|
16
|
+
Factory.build(:anonymous_comment, :author_email => '').should_not be_valid
|
17
|
+
end
|
18
|
+
it 'is not valid to be anonymous with an invalid email' do
|
19
|
+
Factory.build(:anonymous_comment, :author_email => 'invalidstuff').should_not be_valid
|
20
|
+
end
|
21
|
+
it 'is not valid to be anonymous without a name' do
|
22
|
+
Factory.build(:anonymous_comment, :author_name => '').should_not be_valid
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#author' do
|
27
|
+
it 'is the user string version when its a user comment' do
|
28
|
+
comment = Factory.build(:user_comment)
|
29
|
+
comment.author.should == comment.user.to_s
|
30
|
+
end
|
31
|
+
it 'is the author name when an anonymous comments' do
|
32
|
+
comment = Factory.build(:anonymous_comment)
|
33
|
+
comment.author.should == comment.author_name
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#as_json' do
|
38
|
+
before :all do
|
39
|
+
@comment = Factory(:user_comment)
|
40
|
+
@json = JSON.parse(@comment.to_json)
|
41
|
+
end
|
42
|
+
it 'includes a path to the comment' do
|
43
|
+
@json['path'].match(/\/#{@comment.id}/).should_not be_nil
|
44
|
+
end
|
45
|
+
it 'includes the author of the comment' do
|
46
|
+
@json['author'].should == @comment.author
|
47
|
+
end
|
48
|
+
it 'includes the i18nized created_at of the comment' do
|
49
|
+
@json['ftime'].should_not be_nil
|
50
|
+
end
|
51
|
+
it 'includes whether or not is an admin comment' do
|
52
|
+
@json['admin?'].should == false
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Kublog::Image do
|
4
|
+
|
5
|
+
describe '#validate' do
|
6
|
+
before :each do
|
7
|
+
@image = Kublog::Image.new(:file => Support.image_fixture('adrian.png'))
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'is valid with a file' do
|
11
|
+
@image.should be_valid
|
12
|
+
end
|
13
|
+
|
14
|
+
# Saves the image to delete the file from filesystem
|
15
|
+
it 'is invalid without a file' do
|
16
|
+
@image.file.remove!
|
17
|
+
@image.should_not be_valid
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#before_validation' do
|
22
|
+
it 'sets a default alt with the name of the image' do
|
23
|
+
image = Kublog::Image.create(:file => Support.image_fixture('adrian.png'))
|
24
|
+
image.alt.should == 'adrian'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#after_create' do
|
29
|
+
it 'gets the width and height of the image' do
|
30
|
+
image = Kublog::Image.create(:file => Support.image_fixture('adrian.png'))
|
31
|
+
image.file_width.should == 48
|
32
|
+
image.file_height.should == 48
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Kublog::Notification do
|
4
|
+
|
5
|
+
describe '#validate' do
|
6
|
+
before(:each) do
|
7
|
+
@notification = Factory.build(:notification)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should be valid with the correct attributes' do
|
11
|
+
@notification.should be_valid
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should not be valid without a kind' do
|
15
|
+
@notification.kind = ''
|
16
|
+
@notification.should_not be_valid
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#roles' do
|
21
|
+
it 'serializes roles into a hash or an array' do
|
22
|
+
notification = Factory(:notification)
|
23
|
+
notification.roles = [:shipper, :carrier, :logistics]
|
24
|
+
notification.save
|
25
|
+
notification.reload
|
26
|
+
notification.roles.should == [:shipper, :carrier, :logistics]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#title' do
|
31
|
+
it 'delegates title to post' do
|
32
|
+
@notification = Factory.build :notification, :post => Factory.build(:post)
|
33
|
+
@notification.title.should == @notification.post.title
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#url' do
|
38
|
+
it 'delegates url to the post' do
|
39
|
+
@notification = Factory.build :notification, :post => Factory.create(:post)
|
40
|
+
@notification.url.should == @notification.post.url
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#after_create' do
|
45
|
+
it 'calls deliver_#{notification_kind} on after create' do
|
46
|
+
notification = Factory.build(:twitter_notification)
|
47
|
+
notification.should_receive(:deliver_twitter).and_return(nil)
|
48
|
+
notification.save
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
end
|