Permalink
Browse files

Coverage with Rspec 3

  • Loading branch information...
1 parent 6e67d6e commit 063461571a2242e1e609cae22fc20fe9ddc9425e @kirs kirs committed Jun 7, 2014
Showing with 809 additions and 401 deletions.
  1. +2 −0 .rspec
  2. +9 −4 .travis.yml
  3. +6 −0 Gemfile
  4. +27 −0 Gemfile.lock
  5. +37 −0 spec/controllers/password_resets_controller_spec.rb
  6. +27 −0 spec/controllers/sessions_controller_spec.rb
  7. +62 −0 spec/controllers/settings_controller_spec.rb
  8. +88 −0 spec/controllers/starred_entries_controller_spec.rb
  9. +95 −0 spec/controllers/subscriptions_controller_spec.rb
  10. +33 −0 spec/controllers/unread_entries_controller_spec.rb
  11. +92 −0 spec/controllers/users_controller_spec.rb
  12. +7 −0 spec/factories/coupons.rb
  13. +7 −0 spec/factories/entries.rb
  14. +6 −0 spec/factories/feeds.rb
  15. +6 −0 spec/factories/plans.rb
  16. +9 −0 spec/factories/starred_entries.rb
  17. +8 −0 spec/factories/subscriptions.rb
  18. +11 −0 spec/factories/users.rb
  19. +5 −0 spec/models/coupon_spec.rb
  20. +47 −0 spec/models/entry_spec.rb
  21. +5 −0 spec/models/feed_spec.rb
  22. +5 −0 spec/models/plan_spec.rb
  23. +5 −0 spec/models/starred_entry_spec.rb
  24. +31 −0 spec/models/subscription_spec.rb
  25. +41 −0 spec/models/user_spec.rb
  26. +51 −0 spec/rails_helper.rb
  27. +78 −0 spec/spec_helper.rb
  28. +9 −0 spec/support/auth_session_helper.rb
  29. 0 test/controllers/.keep
  30. +0 −32 test/controllers/api/v2/unread_entries_controller_test.rb
  31. +0 −7 test/controllers/apple_push_notifications_controller_test.rb
  32. +0 −4 test/controllers/collections_controller_test.rb
  33. +0 −4 test/controllers/emails_controller_test.rb
  34. +0 −4 test/controllers/feeds_controller_test.rb
  35. +0 −4 test/controllers/imports_controller_test.rb
  36. +0 −4 test/controllers/password_resets_controller_test.rb
  37. +0 −4 test/controllers/sessions_controller_test.rb
  38. +0 −4 test/controllers/settings_controller_test.rb
  39. +0 −4 test/controllers/sharing_services_controller_test.rb
  40. +0 −4 test/controllers/site_controller_test.rb
  41. +0 −4 test/controllers/starred_controller_test.rb
  42. +0 −4 test/controllers/subscriptions_controller_test.rb
  43. +0 −4 test/controllers/sync_controller_test.rb
  44. +0 −4 test/controllers/user_mailer_test.rb
  45. +0 −4 test/controllers/users_controller_test.rb
  46. 0 test/fixtures/.gitkeep
  47. +0 −11 test/fixtures/actions.yml
  48. +0 −13 test/fixtures/coupons.yml
  49. +0 −9 test/fixtures/deleted_users.yml
  50. +0 −7 test/fixtures/feed_stats.yml
  51. +0 −11 test/fixtures/recently_read_entries.yml
  52. +0 −11 test/fixtures/saved_searches.yml
  53. +0 −9 test/fixtures/sharing_services.yml
  54. +0 −13 test/fixtures/starred_entries.yml
  55. +0 −11 test/fixtures/supported_sharing_services.yml
  56. 0 test/helpers/.keep
  57. +0 −4 test/helpers/apple_push_notifications_helper_test.rb
  58. +0 −4 test/helpers/emails_helper_test.rb
  59. +0 −4 test/helpers/sharing_services_helper_test.rb
  60. +0 −4 test/helpers/starred_helper_test.rb
  61. 0 test/integration/.gitkeep
  62. 0 test/mailers/.keep
  63. 0 test/models/.keep
  64. +0 −7 test/models/action_test.rb
  65. +0 −7 test/models/billing_event_test.rb
  66. +0 −7 test/models/coupon_test.rb
  67. +0 −7 test/models/deleted_user_test.rb
  68. +0 −7 test/models/entry_test.rb
  69. +0 −7 test/models/feed_stat_test.rb
  70. +0 −7 test/models/feed_test.rb
  71. +0 −4 test/models/helpers/collections_helper_test.rb
  72. +0 −4 test/models/helpers/feeds_helper_test.rb
  73. +0 −4 test/models/helpers/imports_helper_test.rb
  74. +0 −4 test/models/helpers/password_resets_helper_test.rb
  75. +0 −4 test/models/helpers/sessions_helper_test.rb
  76. +0 −4 test/models/helpers/settings_helper_test.rb
  77. +0 −4 test/models/helpers/site_helper_test.rb
  78. +0 −4 test/models/helpers/subscriptions_helper_test.rb
  79. +0 −4 test/models/helpers/sync_helper_test.rb
  80. +0 −4 test/models/helpers/users_helper_test.rb
  81. +0 −7 test/models/import_item_test.rb
  82. +0 −7 test/models/import_test.rb
  83. +0 −7 test/models/plan_test.rb
  84. +0 −7 test/models/recently_read_entry_test.rb
  85. +0 −7 test/models/saved_search_test.rb
  86. +0 −7 test/models/sharing_service_test.rb
  87. +0 −7 test/models/starred_entry_test.rb
  88. +0 −7 test/models/subscription_test.rb
  89. +0 −7 test/models/supported_sharing_service_test.rb
  90. +0 −7 test/models/tag_test.rb
  91. +0 −7 test/models/tagging_test.rb
  92. +0 −7 test/models/unread_entry_test.rb
  93. +0 −7 test/models/user_test.rb
  94. +0 −11 test/test_helper.rb
View
2 .rspec
@@ -0,0 +1,2 @@
+--color
+--require spec_helper
View
@@ -1,12 +1,17 @@
+services:
+ - redis-server
+addons:
+ postgresql: "9.2"
language: ruby
rvm:
- - 2.0.0
+ - 2.1
env:
- DB=postgresql
before_script:
- psql -c 'create database feedbin_test;' -U postgres
-script:
+before_script:
- export POSTGRES_USERNAME=postgres
- - export RAILS_ENV=test
+ - export AWS_ACCESS_KEY_ID=foo
+ - export AWS_SECRET_ACCESS_KEY=bar
- bundle exec rake db:setup
- - bundle exec rake db:test:prepare
+ - bundle exec rake db:test:prepare
View
@@ -14,6 +14,12 @@ group :development do
gem 'spring'
end
+group :development, :test do
+ gem 'rspec-rails', '~> 3.0.0'
+ gem 'factory_girl_rails'
+ gem 'faker'
+end
+
group :production do
gem "therubyracer", require: 'v8'
end
View
@@ -124,6 +124,7 @@ GEM
connection_pool (2.0.0)
curb (0.8.5)
dalli (2.7.0)
+ diff-lcs (1.2.5)
dotenv (0.10.0)
dotenv-rails (0.10.0)
dotenv (= 0.10.0)
@@ -134,6 +135,13 @@ GEM
oauth (>= 0.4.1)
excon (0.32.1)
execjs (2.0.2)
+ factory_girl (4.3.0)
+ activesupport (>= 3.0.0)
+ factory_girl_rails (4.3.0)
+ factory_girl (~> 4.3.0)
+ railties (>= 3.0.0)
+ faker (1.3.0)
+ i18n (~> 0.5)
faraday (0.8.9)
multipart-post (~> 1.2.0)
faraday_middleware (0.9.0)
@@ -253,6 +261,22 @@ GEM
actionpack (>= 2.1)
rest-client (1.6.7)
mime-types (>= 1.16)
+ rspec-core (3.0.0)
+ rspec-support (~> 3.0.0)
+ rspec-expectations (3.0.0)
+ diff-lcs (>= 1.2.0, < 2.0)
+ rspec-support (~> 3.0.0)
+ rspec-mocks (3.0.1)
+ rspec-support (~> 3.0.0)
+ rspec-rails (3.0.1)
+ actionpack (>= 3.0)
+ activesupport (>= 3.0)
+ railties (>= 3.0)
+ rspec-core (~> 3.0.0)
+ rspec-expectations (~> 3.0.0)
+ rspec-mocks (~> 3.0.0)
+ rspec-support (~> 3.0.0)
+ rspec-support (3.0.0)
rubyzip (1.1.0)
sanitize (2.1.0)
nokogiri (>= 1.4.4)
@@ -344,6 +368,8 @@ DEPENDENCIES
dalli
dotenv-rails
evernote_oauth
+ factory_girl_rails
+ faker
feedzirra!
fog
foreman
@@ -368,6 +394,7 @@ DEPENDENCIES
readability_parser
redis (>= 3.0.5)
request_exception_handler
+ rspec-rails (~> 3.0.0)
rubyzip (= 1.1.0)
sanitize
sass-rails (~> 4.0.0)
@@ -0,0 +1,37 @@
+require 'rails_helper'
+
+describe PasswordResetsController do
+ describe "create" do
+ it "works" do
+ user = create(:user)
+ sign_in user
+
+ post :create, email: user.email
+
+ user.reload
+ expect(user.password_reset_sent_at).to be_present
+ expect(user.password_reset_token).to be_present
+
+ expect(response).to redirect_to login_path
+ end
+ end
+
+ describe "#update" do
+ it "works" do
+ user = create(:user)
+
+ token = user.generate_token(:password_reset_token, true)
+ user.password_reset_sent_at = Time.now
+ user.save!
+
+ post :update, id: token, user: { password: '12345678' }
+
+ user.reload
+
+ expect(user.password_reset_token).to be_nil
+ expect(flash[:notice]).to eq "Password has been reset."
+
+ expect(response).to redirect_to login_path
+ end
+ end
+end
@@ -0,0 +1,27 @@
+require 'rails_helper'
+
+describe SessionsController do
+ describe "#create" do
+ let(:password) { "foobarisnoteasy" }
+
+ it "works" do
+ user = create(:user, password: password)
+ post :create, email: user.email, password: password
+
+ expect(response.status).to eq 302
+ expect(response).to redirect_to root_url
+ end
+ end
+
+ describe "#destroy" do
+ it "works" do
+ user = create(:user)
+ sign_in user
+
+ post :destroy
+
+ expect(session[:auth_token]).to be_nil
+ expect(response).to redirect_to root_path
+ end
+ end
+end
@@ -0,0 +1,62 @@
+require 'rails_helper'
+
+describe SettingsController do
+ describe "#help" do
+ it "works" do
+ get :help
+ end
+ end
+
+ describe "#settings" do
+ it "works" do
+ get :settings
+ end
+ end
+
+ describe "#account" do
+ it "works" do
+ get :account
+ end
+ end
+
+ describe "#update_credit_card" do
+ it "works" do
+ user = create(:user)
+ sign_in user
+
+ post :update_credit_card, stripe_token: 'foobar'
+
+ expect(response).to redirect_to settings_billing_url
+ end
+ end
+
+ describe "#settings_update" do
+ let(:settings_params) {
+ {
+ entry_sort: 'DESC',
+ starred_feed_enabled: "true",
+ hide_tagged_feeds: "false",
+ precache_images: "true",
+ show_unread_count: "true",
+ sticky_view_inline: "false",
+ mark_as_read_confirmation: "true",
+ apple_push_notification_device_token: '123foo'
+ }
+ }
+
+ it "updates settings" do
+ user = create(:user)
+ sign_in user
+
+ post :settings_update, user: settings_params, id: user.id
+
+ user.reload
+
+ settings_params.each do |key, value|
+ expect(user.send(key)).to eq value
+ end
+
+ expect(response).to redirect_to settings_url
+ end
+ end
+end
@@ -0,0 +1,88 @@
+require 'rails_helper'
+
+describe StarredEntriesController do
+ describe "#index" do
+ context "user has enabled stars" do
+ it "works" do
+ user = create(:user, starred_feed_enabled: 1)
+ feed = create(:feed)
+
+ entries = create_list(:entry, 2, feed: feed)
+
+ create(:starred_entry, entry: entries[0], feed: feed, user: user)
+ create(:starred_entry, entry: entries[1], feed: feed, user: user)
+
+ sign_in user
+
+ get :index, starred_token: user.starred_token, format: :xml
+
+ expect(assigns(:entries).size).to eq 2
+ expect(assigns(:starred_entries).size).to eq 2
+ end
+ end
+ end
+
+ describe "#export" do
+ it "works" do
+ user = create(:user, starred_feed_enabled: 1)
+ sign_in user
+
+ expect(StarredEntriesExport).to receive(:perform_async).once.with(user.id)
+
+ get :export
+
+ expect(response).to redirect_to settings_import_export_path
+ end
+ end
+
+ describe "#update" do
+ context "with starred=true" do
+ context "not starred yet" do
+ it "works" do
+ user = create(:user, starred_feed_enabled: 1)
+ sign_in user
+
+ entry = create(:entry)
+
+ expect {
+ post :update, id: entry.id, starred: 'true', format: :js
+ }.to change(StarredEntry, :count).by(1)
+
+ expect(response.status).to eq 200
+ end
+ end
+
+ context "already starred" do
+ it "works" do
+ user = create(:user, starred_feed_enabled: 1)
+ sign_in user
+
+ entry = create(:entry)
+ StarredEntry.create_from_owners(user, entry)
+
+ expect {
+ post :update, id: entry.id, starred: 'true', format: :js
+ }.not_to change(StarredEntry, :count)
+
+ expect(response.status).to eq 200
+ end
+ end
+ end
+
+ context "with starred=false" do
+ it "works" do
+ user = create(:user, starred_feed_enabled: 1)
+ sign_in user
+
+ entry = create(:entry)
+ StarredEntry.create_from_owners(user, entry)
+
+ expect {
+ post :update, id: entry.id, starred: 'false', format: :js
+ }.to change(StarredEntry, :count).by(-1)
+
+ expect(response.status).to eq 200
+ end
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit 0634615

Please sign in to comment.