Last active
July 12, 2016 00:38
-
-
Save atstockland/4cea8ec2bdecd22782f78743243da009 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test_helper' | |
describe AccountsController do | |
# class AccountsControllerTest < ActionDispatch::IntegrationTest | |
before do | |
user = users(:glenn) | |
sign_in(user) | |
end | |
def account | |
@account ||= accounts :one | |
end | |
it 'should get index' do | |
get one_accounts_url | |
value(response).must_be :success? | |
end | |
it 'should get new' do | |
get new_account_url(user_id: users(:glenn).id) | |
value(response).must_be :success? | |
end | |
it 'should edit' do | |
get edit_account_url(account) | |
value(response).must_be :success? | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ bin/rails test test/controllers/accounts_controller_test.rb:25 | |
Error: | |
AccountsController#test_0005_should edit: | |
ActionController::UrlGenerationError: No route matches {:action=>"http://test.host/accounts/980190962/edit", :controller=>"accounts"} | |
test/controllers/accounts_controller_test.rb:25:in `block (2 levels) in <top (required)>' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ENV['RAILS_ENV'] = 'test' | |
require File.expand_path('../../config/environment', __FILE__) | |
require 'rails/test_help' | |
require 'minitest/rails' | |
class CarrierWave::Mount::Mounter | |
def store! | |
# Not storing uploads in the tests | |
end | |
end | |
class ActionController::TestCase | |
include ActiveJob::TestHelper | |
include Devise::Test::ControllerHelpers | |
end | |
class ActionDispatch::IntegrationTest | |
include Devise::Test::IntegrationHelpers | |
end | |
class ActiveSupport::TestCase | |
ActiveRecord::Migration.check_pending! | |
fixtures :all | |
include ActionDispatch::TestProcess # fixture_file_upload | |
# look for files in test directory. | |
CarrierWave.root = Rails.root.join('test/fixtures/files') | |
def multi_page_pdf_file(filename = 'airframe.pdf') | |
File.new("#{Rails.root}/test/fixtures/files/#{filename}") | |
end | |
def sample_file(filename = 'test_image.png') | |
File.new("#{Rails.root}/test/fixtures/files/#{filename}") | |
end | |
def avatar_file(filename = 'avatar.jpg') | |
File.new("#{Rails.root}/test/fixtures/files/#{filename}") | |
end | |
def uploaded_file_object(klass, attribute, file, content_type = 'text/plain') | |
filename = File.basename(file.path) | |
klass_label = klass.to_s.underscore | |
ActionDispatch::Http::UploadedFile.new( | |
tempfile: file, | |
filename: filename, | |
head: %(Content-Disposition: form-data; name="#{klass_label}[#{attribute}]"; filename="#{filename}"), | |
content_type: content_type | |
) | |
end | |
def after_teardown | |
CarrierWave.clean_cached_files!(0) | |
Warden.test_reset! | |
super | |
end | |
def assert_permit(user, record, action) | |
msg = "User #{user.inspect} should be permitted to #{action} #{record}, but isn't permitted" | |
assert permit(user, record, action), msg | |
end | |
def refute_permit(user, record, action) | |
msg = "User #{user.inspect} should NOT be permitted to #{action} #{record}, but is permitted" | |
refute permit(user, record, action), msg | |
end | |
def permit(user, record, action) | |
cls = self.class.superclass.to_s.gsub(/Test/, '') | |
cls.constantize.new(user, record).public_send("#{action}?") | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
glenn: | |
username: mr_glenn | |
owner: one (School) | |
first_name: Glenn | |
last_name: Smith | |
email: glenn@email.com | |
birthdate: <%= Time.zone.today-40.years %> | |
encrypted_password: <%= Devise::Encryptor.digest(User, 'flightRecord@8') %> | |
legacy_password_salt: '' | |
legacy_password_hash: '' | |
confirmed_at: <%= Time.now %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment