crowdblog 0.0.16 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/.gitignore +2 -0
  2. data/Gemfile +0 -10
  3. data/README.md +94 -3
  4. data/Rakefile +1 -7
  5. data/app/assets/images/crowdblog/logo.png +0 -0
  6. data/app/assets/javascripts/crowdblog/models/post.js.coffee +4 -9
  7. data/app/assets/javascripts/crowdblog/views/attachment_view.js.coffee +12 -0
  8. data/app/assets/javascripts/crowdblog/views/post_form_view.js.coffee +21 -0
  9. data/app/assets/javascripts/crowdblog/views/post_view.js.coffee +52 -0
  10. data/app/assets/javascripts/crowdblog.js +7 -11
  11. data/app/assets/stylesheets/crowdblog/posts.css.scss +26 -5
  12. data/app/assets/stylesheets/crowdblog.css +0 -1
  13. data/app/controllers/crowdblog/application_controller.rb +13 -0
  14. data/app/controllers/crowdblog/assets_controller.rb +2 -2
  15. data/app/controllers/crowdblog/authors_controller.rb +2 -2
  16. data/app/controllers/crowdblog/devise/sessions_controller.rb +3 -0
  17. data/app/controllers/crowdblog/posts_controller.rb +37 -16
  18. data/app/models/crowdblog/asset.rb +0 -1
  19. data/app/models/crowdblog/post.rb +15 -5
  20. data/app/models/crowdblog/user.rb +9 -1
  21. data/app/views/crowdblog/application/_navbar.html.slim +11 -0
  22. data/app/views/crowdblog/application/_notices.html.slim +6 -0
  23. data/app/views/crowdblog/authors/index.html.slim +2 -2
  24. data/app/views/crowdblog/devise/_links.erb +25 -0
  25. data/app/views/crowdblog/devise/sessions/new.html.erb +21 -0
  26. data/app/views/crowdblog/posts/_form.html.slim +31 -0
  27. data/app/views/crowdblog/posts/_post.html.slim +13 -0
  28. data/app/views/crowdblog/posts/edit.html.slim +14 -0
  29. data/app/views/crowdblog/posts/index.html.slim +12 -10
  30. data/app/views/crowdblog/posts/new.html.slim +12 -0
  31. data/app/views/crowdblog/posts/update.json.jbuilder +2 -0
  32. data/app/views/layouts/crowdblog/application.html.slim +20 -0
  33. data/config/initializers/date_formats.rb +1 -0
  34. data/config/initializers/devise.rb +16 -0
  35. data/config/locales/devise.en.yml +57 -0
  36. data/config/routes.rb +1 -0
  37. data/crowdblog.gemspec +4 -12
  38. data/db/migrate/20120215232711_create_crowdblog_users.rb +23 -0
  39. data/db/migrate/20120217213920_create_crowdblog_posts.rb +17 -0
  40. data/db/migrate/20120219071614_create_crowdblog_assets.rb +10 -0
  41. data/lib/crowdblog/devise/failure_app.rb +9 -0
  42. data/lib/crowdblog/rspec/crowdblog_shared_examples.rb +108 -0
  43. data/lib/crowdblog/rspec.rb +1 -0
  44. data/lib/crowdblog/version.rb +1 -1
  45. data/lib/crowdblog.rb +10 -0
  46. data/spec/dummy/app/controllers/application_controller.rb +0 -16
  47. data/spec/dummy/app/views/home/show.html.slim +1 -1
  48. data/spec/dummy/config/application.rb +0 -10
  49. data/spec/dummy/config/initializers/devise.rb +0 -7
  50. data/spec/dummy/config/routes.rb +1 -8
  51. data/spec/dummy/db/schema.rb +11 -11
  52. data/spec/dummy/db/seed.rb +6 -0
  53. data/spec/integration/crowdblog_spec.rb +5 -0
  54. data/spec/models/post_spec.rb +3 -3
  55. data/spec/models/user_spec.rb +25 -1
  56. data/spec/spec_helper.rb +17 -1
  57. data/vendor/assets/javascripts/backbone_rails_sync.js +69 -0
  58. data/vendor/assets/javascripts/uploader/jquery.html5uploader.js +148 -0
  59. metadata +40 -183
  60. data/Gemfile.lock +0 -280
  61. data/app/assets/javascripts/crowdblog/posts_main.js.coffee +0 -42
  62. data/app/assets/javascripts/crowdblog/templates/posts/attachment.jst.eco.slim +0 -1
  63. data/app/assets/javascripts/crowdblog/templates/posts/edit.jst.eco.slim +0 -36
  64. data/app/assets/javascripts/crowdblog/templates/posts/index.jst.eco.slim +0 -14
  65. data/app/assets/javascripts/crowdblog/templates/posts/post.jst.eco.slim +0 -14
  66. data/app/assets/javascripts/crowdblog/views/posts/attachment_view.js.coffee +0 -8
  67. data/app/assets/javascripts/crowdblog/views/posts/edit_post_view.js.coffee +0 -46
  68. data/app/assets/javascripts/crowdblog/views/posts/index.js.coffee +0 -28
  69. data/app/assets/javascripts/crowdblog/views/posts/post_view.js.coffee +0 -57
  70. data/app/assets/javascripts/crowdblog/xhr_fix.js.coffee +0 -4
  71. data/app/controllers/crowdblog/controller.rb +0 -10
  72. data/app/views/layouts/crowdblog/crowdblog.html.slim +0 -26
  73. data/db/migrate/20120215232711_create_users.rb +0 -10
  74. data/db/migrate/20120216154516_add_devise_to_users.rb +0 -56
  75. data/db/migrate/20120217213920_create_posts.rb +0 -13
  76. data/db/migrate/20120219014520_add_author_to_posts.rb +0 -6
  77. data/db/migrate/20120219040607_add_state_to_post.rb +0 -7
  78. data/db/migrate/20120219071614_create_assets.rb +0 -10
  79. data/db/migrate/20120219234253_add_alias_to_users.rb +0 -6
  80. data/db/migrate/20120229160314_add_review_fields_to_post.rb +0 -6
  81. data/features/posts/listing.feature +0 -32
  82. data/features/posts/manage.feature +0 -36
  83. data/features/posts/publish.feature +0 -17
  84. data/features/step_definitions/global_steps.rb +0 -23
  85. data/features/step_definitions/navigation_steps.rb +0 -45
  86. data/features/step_definitions/posts_steps.rb +0 -138
  87. data/features/step_definitions/review_steps.rb +0 -27
  88. data/features/support/env.rb +0 -76
  89. data/spec/dummy/app/models/user.rb +0 -17
  90. data/spec/fabricators/posts_fabricator.rb +0 -21
  91. data/spec/fabricators/users_fabricator.rb +0 -19
  92. data/vendor/assets/javascripts/swfobject.js +0 -4
  93. data/vendor/assets/swf/uploadify.swf +0 -0
@@ -0,0 +1,14 @@
1
+ .span12
2
+ h2 Edit Post
3
+
4
+ = form_for @post do |f|
5
+ = render 'form', :f => f
6
+
7
+ .form-actions.clear
8
+ .row
9
+ .span1
10
+ = f.submit "Update", :class => "btn btn-primary"
11
+ .span1
12
+ = link_to 'Cancel', crowdblog.posts_path, :class => "btn"
13
+
14
+
@@ -1,13 +1,15 @@
1
- h1 Posts
1
+ .span12
2
+ h1 Posts
2
3
 
3
- #posts.container
4
+ .new-link
5
+ = link_to 'New Post', crowdblog.new_post_path, :class => "btn btn-primary btn-small"
4
6
 
5
- - content_for :scripts do
6
- coffee:
7
- $ ->
8
- new PostsApp.PostsView
9
- PostsApp.router = new PostsApp.Router
10
- Backbone.history.start()
7
+ #posts.container
8
+ table.table.table-striped= render @posts
11
9
 
12
- javascript:
13
- PostsApp.publisher = #{current_user.is_publisher?}
10
+ - content_for :scripts do
11
+ coffee:
12
+ $ ->
13
+ $('tr.post').each (index, el) ->
14
+ new Crowdblog.Views.PostView
15
+ el: el
@@ -0,0 +1,12 @@
1
+ .span12
2
+ h2 New Post
3
+
4
+ = form_for @post do |f|
5
+ = render 'form', :f => f
6
+
7
+ .form-actions.clear
8
+ .row
9
+ .span1
10
+ = f.submit "Create", :class => "btn btn-primary"
11
+ .span1
12
+ = link_to 'Cancel', crowdblog.posts_path, :class => "btn"
@@ -0,0 +1,2 @@
1
+ json.(@post, :state)
2
+ json.published_at @post.published_at.try(:to_s, :crowdblog_short)
@@ -0,0 +1,20 @@
1
+ doctype html
2
+ html
3
+ head
4
+ title Crowd Blog
5
+
6
+ = stylesheet_link_tag "//netdna.bootstrapcdn.com/twitter-bootstrap/2.1.1/css/bootstrap.min.css"
7
+ = stylesheet_link_tag :crowdblog, media: 'all'
8
+ = javascript_include_tag "//code.jquery.com/jquery.min.js"
9
+ = javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.1/underscore-min.js"
10
+ = javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js"
11
+ = javascript_include_tag :crowdblog
12
+ = csrf_meta_tags
13
+
14
+ = yield :scripts
15
+
16
+ body
17
+ .container
18
+ .row= render '/crowdblog/application/navbar'
19
+ .row= render '/crowdblog/application/notices'
20
+ .row= yield
@@ -0,0 +1 @@
1
+ Time::DATE_FORMATS[:crowdblog_short] = '%Y-%m-%d'
@@ -0,0 +1,16 @@
1
+ Devise.setup do |config|
2
+ require 'devise/orm/active_record'
3
+
4
+ config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
5
+ #config.apply_schema = false
6
+ config.case_insensitive_keys = [ :email ]
7
+ config.strip_whitespace_keys = [ :email ]
8
+ config.skip_session_storage = [:http_auth]
9
+ config.stretches = Rails.env.test? ? 1 : 10
10
+ config.reconfirmable = true
11
+ #config.use_salt_as_remember_token = true
12
+ config.reset_password_within = 6.hours
13
+ config.sign_out_via = :get
14
+
15
+ config.warden { |manager| manager.failure_app = Crowdblog::Devise::FailureApp }
16
+ end
@@ -0,0 +1,57 @@
1
+ # Additional translations at https://github.com/plataformatec/devise/wiki/I18n
2
+
3
+ en:
4
+ errors:
5
+ messages:
6
+ expired: "has expired, please request a new one"
7
+ not_found: "not found"
8
+ already_confirmed: "was already confirmed, please try signing in"
9
+ not_locked: "was not locked"
10
+ not_saved:
11
+ one: "1 error prohibited this %{resource} from being saved:"
12
+ other: "%{count} errors prohibited this %{resource} from being saved:"
13
+
14
+ devise:
15
+ failure:
16
+ already_authenticated: 'You are already signed in.'
17
+ unauthenticated: 'You need to sign in or sign up before continuing.'
18
+ unconfirmed: 'You have to confirm your account before continuing.'
19
+ locked: 'Your account is locked.'
20
+ invalid: 'Invalid email or password.'
21
+ invalid_token: 'Invalid authentication token.'
22
+ timeout: 'Your session expired, please sign in again to continue.'
23
+ inactive: 'Your account was not activated yet.'
24
+ sessions:
25
+ signed_in: 'Signed in successfully.'
26
+ signed_out: 'Signed out successfully.'
27
+ passwords:
28
+ send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
29
+ updated: 'Your password was changed successfully. You are now signed in.'
30
+ updated_not_active: 'Your password was changed successfully.'
31
+ send_paranoid_instructions: "If your e-mail exists on our database, you will receive a password recovery link on your e-mail"
32
+ confirmations:
33
+ send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
34
+ send_paranoid_instructions: 'If your e-mail exists on our database, you will receive an email with instructions about how to confirm your account in a few minutes.'
35
+ confirmed: 'Your account was successfully confirmed. You are now signed in.'
36
+ registrations:
37
+ signed_up: 'Welcome! You have signed up successfully.'
38
+ signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.'
39
+ signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.'
40
+ signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.'
41
+ updated: 'You updated your account successfully.'
42
+ update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
43
+ destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
44
+ unlocks:
45
+ send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
46
+ unlocked: 'Your account has been unlocked successfully. Please sign in to continue.'
47
+ send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.'
48
+ omniauth_callbacks:
49
+ success: 'Successfully authorized from %{kind} account.'
50
+ failure: 'Could not authorize you from %{kind} because "%{reason}".'
51
+ mailer:
52
+ confirmation_instructions:
53
+ subject: 'Confirmation instructions'
54
+ reset_password_instructions:
55
+ subject: 'Reset password instructions'
56
+ unlock_instructions:
57
+ subject: 'Unlock Instructions'
data/config/routes.rb CHANGED
@@ -8,4 +8,5 @@ Crowdblog::Engine.routes.draw do
8
8
 
9
9
  root to: 'posts#index'
10
10
 
11
+ devise_for :users, :class_name => 'Crowdblog::User', :module => 'crowdblog/devise'
11
12
  end
data/crowdblog.gemspec CHANGED
@@ -22,27 +22,19 @@ Gem::Specification.new do |s|
22
22
 
23
23
  # Added in the Gemfile, so they can be accessed in the dummy app
24
24
  # leave the dependencies here so our engine require those gems when added on base apps
25
- s.add_dependency 'jquery-rails'
26
- s.add_dependency 'backbone-rails'
27
25
  s.add_dependency 'carrierwave'
28
26
  s.add_dependency 'devise'
29
- s.add_dependency 'eco'
30
27
  s.add_dependency 'gravtastic'
31
- s.add_dependency 'less-rails-bootstrap'
28
+ s.add_dependency 'jquery-rails'
29
+ s.add_dependency 'jbuilder'
32
30
  s.add_dependency 'redcarpet'
33
- s.add_dependency 'slim_assets'
34
- s.add_dependency 'slim-rails'
31
+ s.add_dependency 'slim'
35
32
  s.add_dependency 'state_machine'
33
+ s.add_dependency 'strong_parameters'
36
34
 
37
35
  s.add_development_dependency 'capybara-webkit'
38
- s.add_development_dependency 'cucumber-ajaxer'
39
- s.add_development_dependency 'cucumber-rails'
40
36
  s.add_development_dependency 'database_cleaner'
41
- s.add_development_dependency 'fabrication'
42
- s.add_development_dependency 'faker'
43
37
  s.add_development_dependency 'fuubar'
44
- s.add_development_dependency 'fuubar-cucumber'
45
- s.add_development_dependency 'headless'
46
38
  s.add_development_dependency 'rspec-rails'
47
39
  s.add_development_dependency 'simplecov'
48
40
  s.add_development_dependency 'simplecov-rcov-text'
@@ -0,0 +1,23 @@
1
+ class CreateCrowdblogUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table :crowdblog_users do |t|
4
+ t.string :name
5
+ t.boolean :is_publisher
6
+ t.string :email, :null => false, :default => ""
7
+ t.string :encrypted_password, :null => false, :default => ""
8
+ t.datetime :remember_created_at
9
+ t.integer :sign_in_count, :default => 0
10
+ t.datetime :current_sign_in_at
11
+ t.datetime :last_sign_in_at
12
+ t.string :current_sign_in_ip
13
+ t.string :last_sign_in_ip
14
+ t.string :authentication_token
15
+ t.string :gravatar_alias
16
+
17
+ t.timestamps
18
+ end
19
+
20
+ add_index :crowdblog_users, :email, :unique => true
21
+ add_index :crowdblog_users, :authentication_token, :unique => true
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ class CreateCrowdblogPosts < ActiveRecord::Migration
2
+ def change
3
+ create_table :crowdblog_posts do |t|
4
+ t.string :title
5
+ t.text :body
6
+ t.string :permalink
7
+ t.datetime :published_at
8
+ t.integer :author_id
9
+ t.string :state
10
+ t.integer :publisher_id
11
+ t.boolean :ready_for_review
12
+ t.datetime :marked_for_review_at
13
+
14
+ t.timestamps
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ class CreateCrowdblogAssets < ActiveRecord::Migration
2
+ def change
3
+ create_table :crowdblog_assets do |t|
4
+ t.integer :post_id
5
+ t.string :attachment
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module Crowdblog
2
+ module Devise
3
+ class FailureApp < ::Devise::FailureApp
4
+ def redirect_url
5
+ crowdblog.new_user_session_path
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,108 @@
1
+ shared_examples_for "a crowdblog", :type => :integration do
2
+
3
+ let(:user) do
4
+ user = Crowdblog::User.new :email => 'test@example.com'
5
+ user.password = '123456'
6
+ user.password_confirmation = '123456'
7
+ user.save!
8
+ user
9
+ end
10
+
11
+ let(:post) do
12
+ Crowdblog::Post.create :title => 'A post title', :body => 'A post body'
13
+ end
14
+
15
+ describe "manage posts" do
16
+ before do
17
+ Crowdblog::PostsController.any_instance.stub(:authenticate_user!)
18
+ Crowdblog::PostsController.any_instance.stub(:current_user).and_return user
19
+ end
20
+
21
+ it "creates a post", :js => true do
22
+ visit crowdblog.posts_path
23
+ click_link 'New Post'
24
+
25
+ fill_in 'Title', :with => 'A post title'
26
+ fill_in 'Body' , :with => 'A post body'
27
+ click_button 'Update'
28
+
29
+ page.current_path.should == crowdblog.posts_path
30
+ page.should have_content 'A post title'
31
+ end
32
+
33
+ context "a post exists" do
34
+ before do
35
+ post
36
+ post.author = user
37
+ post.save!
38
+ end
39
+
40
+ it "edits a post" do
41
+ visit crowdblog.posts_path
42
+ within "#post_#{post.id}" do
43
+ click_link 'Edit'
44
+ end
45
+
46
+ fill_in 'Title', :with => 'A NEW post title'
47
+ fill_in 'Body' , :with => 'A NEW post body'
48
+ click_button 'Update'
49
+
50
+ page.current_path.should == crowdblog.posts_path
51
+ page.should have_content 'A NEW post title'
52
+ end
53
+
54
+ it "deletes a post" do
55
+ visit crowdblog.posts_path
56
+
57
+ within "#post_#{post.id}" do
58
+ click_link 'Delete'
59
+ end
60
+ page.current_path.should == crowdblog.posts_path
61
+ page.should_not have_content 'A post title'
62
+ end
63
+
64
+ it "publishes a post", :js => true do
65
+ user.publisher!
66
+
67
+ visit crowdblog.posts_path
68
+
69
+ within "#post_#{post.id}" do
70
+ button = find_link 'Publish'
71
+ button.click
72
+
73
+ page.should have_css 'a.btn-success'
74
+ post.reload.state.should eq 'published'
75
+ end
76
+ end
77
+
78
+ it "draftes a post", :js => true do
79
+ user.publisher!
80
+ post.publish!
81
+
82
+ visit crowdblog.posts_path
83
+
84
+ within "#post_#{post.id}" do
85
+ button = find_link 'Publish'
86
+ button.click
87
+
88
+ page.should have_css 'a.btn-danger'
89
+ post.reload.state.should eq 'drafted'
90
+ end
91
+ end
92
+
93
+ it "marks the post for review", :js => true do
94
+ user.publisher!
95
+
96
+ visit crowdblog.posts_path
97
+
98
+ within "#post_#{post.id}" do
99
+ button = find_link 'Review'
100
+ button.click
101
+
102
+ page.should have_css 'a.btn-warning'
103
+ post.reload.ready_for_review.should be_true
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1 @@
1
+ require 'crowdblog/rspec/crowdblog_shared_examples'
@@ -1,3 +1,3 @@
1
1
  module Crowdblog
2
- VERSION = '0.0.16'
2
+ VERSION = '0.1.0'
3
3
  end
data/lib/crowdblog.rb CHANGED
@@ -1,4 +1,14 @@
1
1
  require "crowdblog/engine"
2
2
 
3
+ require "carrierwave"
4
+ require "devise"
5
+ require "gravtastic"
6
+ require "jbuilder"
7
+ require "redcarpet"
8
+ require "slim"
9
+ require "state_machine"
10
+ require "strong_parameters"
11
+
3
12
  module Crowdblog
13
+ autoload :Devise, 'crowdblog/devise/failure_app'
4
14
  end
@@ -1,20 +1,4 @@
1
1
  class ApplicationController < ActionController::Base
2
2
  protect_from_forgery
3
3
 
4
- # Overwriting the sign_out redirect path method
5
- def after_sign_in_path_for(resource_or_scope)
6
- crowdblog_url
7
- end
8
-
9
- def authenticate!
10
- # sign out the user if trying to sign another user
11
- sign_out current_user if params['auth_token'] && current_user
12
-
13
- # if no one signed in, use the default user
14
- unless user_signed_in?
15
- user = Crowdblog::User.find_by_email('foo@crowdint.com') || Crowdblog::User.create!(email: 'foo@crowdint.com', is_publisher: true)
16
- sign_in user
17
- end
18
- end
19
-
20
4
  end
@@ -1,4 +1,4 @@
1
1
  h2 Your blog!
2
2
 
3
3
  = link_to 'Admin', crowdblog_path
4
- = link_to 'Sign in', new_user_session_path
4
+ = link_to 'Sign in', crowdblog.new_user_session_path
@@ -59,13 +59,3 @@ module Dummy
59
59
  config.assets.version = '1.0'
60
60
  end
61
61
  end
62
-
63
- # Require and configure Fabrication for test and dev environments (not production)
64
- unless Rails.env.production?
65
- require 'fabrication'
66
- require 'faker'
67
-
68
- Fabrication.configure do |config|
69
- config.fabricator_dir = '../../spec/fabricators'
70
- end
71
- end
@@ -11,9 +11,6 @@ Devise.setup do |config|
11
11
  # Configure the class responsible to send e-mails.
12
12
  # config.mailer = "Devise::Mailer"
13
13
 
14
- # Automatically apply schema changes in tableless databases
15
- config.apply_schema = false
16
-
17
14
  # ==> ORM configuration
18
15
  # Load and configure the ORM. Supports :active_record (default) and
19
16
  # :mongoid (bson_ext recommended) by default. Other ORMs may be
@@ -113,10 +110,6 @@ Devise.setup do |config|
113
110
  # If true, extends the user's remember period when remembered via cookie.
114
111
  # config.extend_remember_period = false
115
112
 
116
- # If true, uses the password salt as remember token. This should be turned
117
- # to false if you are not using database authenticatable.
118
- config.use_salt_as_remember_token = true
119
-
120
113
  # Options to be passed to the created cookie. For instance, you can set
121
114
  # :secure => true in order to force SSL only cookies.
122
115
  # config.cookie_options = {}
@@ -1,13 +1,6 @@
1
1
  Rails.application.routes.draw do
2
2
 
3
- mount Crowdblog::Engine => '/admin'
4
-
5
- devise_for :users
6
-
7
- devise_scope :user do
8
- match 'crowdblog_sign_in', to: 'devise/sessions#new'
9
- end
3
+ mount Crowdblog::Engine => '/blogadmin'
10
4
 
11
5
  root to: 'home#show'
12
-
13
6
  end
@@ -11,34 +11,32 @@
11
11
  #
12
12
  # It's strongly recommended to check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(:version => 20120229160314) do
14
+ ActiveRecord::Schema.define(:version => 20120220033923) do
15
15
 
16
- create_table "assets", :force => true do |t|
16
+ create_table "crowdblog_assets", :force => true do |t|
17
17
  t.integer "post_id"
18
18
  t.string "attachment"
19
19
  t.datetime "created_at", :null => false
20
20
  t.datetime "updated_at", :null => false
21
21
  end
22
22
 
23
- create_table "posts", :force => true do |t|
23
+ create_table "crowdblog_posts", :force => true do |t|
24
24
  t.string "title"
25
25
  t.text "body"
26
26
  t.string "permalink"
27
- t.date "published_at"
28
- t.datetime "created_at", :null => false
29
- t.datetime "updated_at", :null => false
27
+ t.datetime "published_at"
30
28
  t.integer "author_id"
31
29
  t.string "state"
32
30
  t.integer "publisher_id"
33
31
  t.boolean "ready_for_review"
34
32
  t.datetime "marked_for_review_at"
33
+ t.datetime "created_at", :null => false
34
+ t.datetime "updated_at", :null => false
35
35
  end
36
36
 
37
- create_table "users", :force => true do |t|
37
+ create_table "crowdblog_users", :force => true do |t|
38
38
  t.string "name"
39
39
  t.boolean "is_publisher"
40
- t.datetime "created_at", :null => false
41
- t.datetime "updated_at", :null => false
42
40
  t.string "email", :default => "", :null => false
43
41
  t.string "encrypted_password", :default => "", :null => false
44
42
  t.datetime "remember_created_at"
@@ -49,10 +47,12 @@ ActiveRecord::Schema.define(:version => 20120229160314) do
49
47
  t.string "last_sign_in_ip"
50
48
  t.string "authentication_token"
51
49
  t.string "gravatar_alias"
50
+ t.datetime "created_at", :null => false
51
+ t.datetime "updated_at", :null => false
52
52
  end
53
53
 
54
- add_index "users", ["authentication_token"], :name => "index_users_on_authentication_token", :unique => true
55
- add_index "users", ["email"], :name => "index_users_on_email", :unique => true
54
+ add_index "crowdblog_users", ["authentication_token"], :name => "index_crowdblog_users_on_authentication_token", :unique => true
55
+ add_index "crowdblog_users", ["email"], :name => "index_crowdblog_users_on_email", :unique => true
56
56
 
57
57
  create_table "versions", :force => true do |t|
58
58
  t.integer "versioned_id"
@@ -0,0 +1,6 @@
1
+ user = Crowdblog::User.new
2
+ user.email = "test@example.com"
3
+ user.password = "123456"
4
+ user.password_confirmation = "123456"
5
+
6
+ user.save!
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Crowdblog" do
4
+ it_should_behave_like "a crowdblog"
5
+ end
@@ -47,7 +47,7 @@ module Crowdblog
47
47
 
48
48
  context 'user is publisher' do
49
49
  it 'should see all the Posts' do
50
- Post.scoped_for(user).should == Post
50
+ Post.scoped_for(user).should == Post.scoped
51
51
  end
52
52
  end
53
53
 
@@ -87,7 +87,7 @@ module Crowdblog
87
87
  describe "#day" do
88
88
  context "published at in february" do
89
89
  before do
90
- subject.published_at = stub(:day => 2)
90
+ subject.published_at = Date.new(2012, 12, 2)
91
91
  end
92
92
 
93
93
  it "returns 02" do
@@ -130,7 +130,7 @@ module Crowdblog
130
130
  describe "#month" do
131
131
  context "published at in february" do
132
132
  before do
133
- subject.published_at = stub(:month => 2)
133
+ subject.published_at = Date.new(2012, 2, 1)
134
134
  end
135
135
 
136
136
  it "returns 02" do
@@ -46,12 +46,36 @@ module Crowdblog
46
46
  end
47
47
  end
48
48
 
49
+ describe "#last_published_at" do
50
+ context 'has published posts' do
51
+ let(:date) { Date.today }
52
+
53
+ before do
54
+ posts = [ mock_model(Post, :published_at => date), mock_model(Post, :published_at => 1.day.ago) ]
55
+ subject.stub(:published_posts).and_return posts
56
+ end
57
+
58
+ it "returns the published_at date of the first post" do
59
+ subject.last_published_at.should be(date)
60
+ end
61
+ end
62
+
63
+ context 'no published posts' do
64
+ before do
65
+ subject.stub(:published_posts).and_return []
66
+ end
67
+
68
+ it "returns nil" do
69
+ subject.last_published_at.should be_nil
70
+ end
71
+ end
72
+ end
73
+
49
74
  describe '#publisher!' do
50
75
  it 'should make User a Publisher' do
51
76
  subject.should_receive(:update_attribute).with(:is_publisher, true)
52
77
  subject.publisher!
53
78
  end
54
79
  end
55
-
56
80
  end
57
81
  end
data/spec/spec_helper.rb CHANGED
@@ -5,6 +5,9 @@ ENV["RAILS_ENV"] ||= 'test'
5
5
  require File.expand_path("../dummy/config/environment", __FILE__)
6
6
  require 'rspec/rails'
7
7
  require 'rspec/autorun'
8
+ require 'capybara/rspec'
9
+ require 'crowdblog/rspec'
10
+ require 'database_cleaner'
8
11
 
9
12
  ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
10
13
 
@@ -27,7 +30,7 @@ RSpec.configure do |config|
27
30
  # If you're not using ActiveRecord, or you'd prefer not to run each of your
28
31
  # examples within a transaction, remove the following line or assign false
29
32
  # instead of true.
30
- config.use_transactional_fixtures = true
33
+ config.use_transactional_fixtures = false
31
34
 
32
35
  # If true, the base class of anonymous controllers will be inferred
33
36
  # automatically. This will be the default behavior in future versions of
@@ -36,4 +39,17 @@ RSpec.configure do |config|
36
39
 
37
40
  # Include Engine routes (needed for Controller specs)
38
41
  config.include Crowdblog::Engine.routes.url_helpers
42
+
43
+ config.before(:suite) do
44
+ DatabaseCleaner.strategy = :truncation
45
+ DatabaseCleaner.clean_with(:truncation)
46
+ end
47
+
48
+ config.before(:each) do
49
+ DatabaseCleaner.start
50
+ end
51
+
52
+ config.after(:each) do
53
+ DatabaseCleaner.clean
54
+ end
39
55
  end