Skip to content
Permalink
Browse files
Write failing tests to guide authorization feature.
  • Loading branch information
Steve Polito committed Aug 16, 2020
1 parent 75afac0 commit 7a742afb8deb4304ef707375e9d9f8217479f9fa
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
@@ -1,7 +1,34 @@
require 'test_helper'

class ActivitiesControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
def setup
@user_one = users(:confirmed_user_with_activities)
@user_two = users(:another_confirmed_user_with_activities)

@user_one_activity = @user_one.activities.first
@user_two_activity = @user_two.activities.first
end

test "should not delete another users activity" do
sign_in @user_one

assert_no_difference("Activity.count") do
delete activity_path(@user_two_activity)
end
end

test "should not update another users activity" do
sign_in @user_one
new_duration = 1

put activity_path(@user_two_activity), params: { activity: { duration: new_duration } }
assert_not_equal @user_two_activity.reload.duration, new_duration
end

test "should not get show for another users actvity" do
sign_in @user_one

get activity_path(@user_two_activity)
assert_redirected_to root_path
end
end
@@ -8,4 +8,14 @@ confirmed_user_activity_<%= i %>:
distance: <%= rand(1..26) %>
calculated_pace: <%= rand(360..600) %>
unit: miles
<% end %>

<% 1.upto(60) do |i| %>
another_confirmed_user_activity_<%= i %>:
date: <%= i.days.ago %>
user: another_confirmed_user_with_activities
duration: <%= rand(1800..7200) %>
distance: <%= rand(1..26) %>
calculated_pace: <%= rand(360..600) %>
unit: miles
<% end %>
@@ -18,4 +18,9 @@ confirmed_user_with_time_zone:
confirmed_user_with_activities:
email: confirmed_user_with_activities@example.com
confirmed_at: <%= Time.zone.now %>
encrypted_password: <%= Devise::Encryptor.digest(User, 'password') %>

another_confirmed_user_with_activities:
email: another_confirmed_user_with_activities@example.com
confirmed_at: <%= Time.zone.now %>
encrypted_password: <%= Devise::Encryptor.digest(User, 'password') %>
@@ -10,4 +10,5 @@ class ActiveSupport::TestCase
fixtures :all

# Add more helper methods to be used by all tests here...
include Devise::Test::IntegrationHelpers
end

0 comments on commit 7a742af

Please sign in to comment.