integration-testing

How to access session from Rails Integration Test?

假装没事ソ 提交于 2019-12-12 08:26:52
问题 Consider the following integration test: test "if there is no user in session, redirect to index and flash message" do open_session do |sess| post '/login', :email => users(:client).email, :password => 'rumpelstiltskin' sess[:user] = nil get '/user_page' assert_redirected_to index_path assert_equal "Your session has expired. Please log in again", flash[:notice] end end This generates error: undefined method '[]=' And, changing to sess.session[:user] = nil generates an error as well:

combine @TestFor and @Integration Annotation grails 3

对着背影说爱祢 提交于 2019-12-12 06:35:52
问题 I migrate a large Grails 1.3.7 project to 3.1.6. Tests for Controllers are integration tests. This works fine because the tests inherit from ControllerSpec. Now i´m should be able to do something like this: @Integration @TestFor(SampleController) class SampleControllerIntSpec extends Specification { Because the TestFor Annotation allows usage of model/view/.. fields like in Unit tests. Is there a way to do something like this? Thanks in advance. 回答1: No the TestFor annotations are exclusively

has_many :through creating child after_save --> ActionView::Template::Error

梦想的初衷 提交于 2019-12-12 06:19:10
问题 I have three models: List, Food, and Quantity. List and Food are associated through Quantity via has_many :through. The model association is doing what I want, but when I test, there is an error. test_valid_list_creation_information#ListsCreateTest (1434538267.92s) ActionView::Template::Error: ActionView::Template::Error: Couldn't find Food with 'id'=14 app/views/lists/show.html.erb:11:in `block in _app_views_lists_show_html_erb__3286583530286700438_40342200' app/views/lists/show.html.erb:10

Ms Test or NUnit?

不问归期 提交于 2019-12-12 05:49:45
问题 Is there any advantage to picking NUnit for unit/integration testing vs the built in MsTest? 回答1: They are pretty similar. Differences are subtle. NUnit has testcases for parametrized tests; MSTest does not. You can write [TestCase(1, "one)] [TestCase(2, "two)] [TestCase(3, "three)] [TestCase(4, "four)] public void CanTranslate(int number, string expectedTranslation) { var translation = _sut.Translate(number); translation.Should().Be.EqualTo(expectedTranslation); } rather than writing 4 tests

Devise+CanCan AccessDenied redirect differs between dev and test environments

拟墨画扇 提交于 2019-12-12 04:38:59
问题 I have a Rails 3.1 (RC5) app with Devise and CanCan. Both are configured well and working as expected except that when I run integration tests to ensure that AccessDenied is being redirected as desired, the redirect goes to Devise's sign in instead of the application root. I can verify in my test that the user is still logged in and can still access applicable parts of the app. The redirect is defined in this short controller, which the other restricted controllers inherit (instead of

How to do Integration Test create through other model

孤街醉人 提交于 2019-12-12 04:35:29
问题 1) I have this model Job and the model institution class Job < ApplicationRecord belongs_to :institution # others attibutes end 2) This is my action create on JobsController - I need a institution to create a job. it is fine. def create build_job save_job || render(:new, status: :unprocessable_entity) end 3) This is the integration test that I created I am not getting the success test In params -I also tried institution: @institution -and also tried institution_id: @institution.id require

Allow all actions for authentication in integration test cakephp

百般思念 提交于 2019-12-12 03:34:32
问题 I'm currently trying to write an integration test for some controller whereby it is necessary to send an authentication header. In my controller I have some actions made public accessible through the following code: namespace App\Controller\Api; use Cake\Event\Event; use Cake\Network\Exception\UnauthorizedException; use Cake\Utility\Security; use Firebase\JWT\JWT; class UsersController extends AppController { public function initialize() { parent::initialize(); $this->Auth->allow(['add',

How do I test a Azure AD protected Web API in with Visual Studio Test Adapter?

℡╲_俬逩灬. 提交于 2019-12-12 03:29:37
问题 I've created a multi tenant Web API that works just fine. Now I want to build a native client for testing. The Web API app is defined in one tenant. The test app is defined in another tenant that has given admin consent to the Web API. I want to use the native app to authenticate with username and password in my (non-interactive) integration tests. I cannot use certificate/app-only authentication because I need a real user context. Getting a token var userCredential = new UserCredential(

Adding jacoco integration tests coverage for Sonar

◇◆丶佛笑我妖孽 提交于 2019-12-12 03:24:38
问题 Background: I have 2 separate java projects, call them A and B. Project A is the actual product (war application), with unit-tests. Gradle builds the project and then runs sonar analysis, and I can see the unit-tests coverage in Sonar. Project B is an integration test for the first project. It is run by Jenkins in a pipeline after building project A and deploying it on an integration-environment. The deployment also involves instrumenting the code so that the jacoco-it report will correlate

Integration test: `assert_select 'a[href=?]'` fails for paginated pages

瘦欲@ 提交于 2019-12-12 02:56:14
问题 I have many integration tests that look something like: first_page_of_users = User.page(1) # Using kaminari for pagination. first_page_of_users.each do |user| assert_select 'a[href=?]', user_path(user) end These tests fail with an error message such as: Expected at least 1 element matching "a[href="/users/1"]", found 0.. I added puts @response.body to the tests to see the code that it responded with. For all the users included in the response body it has correct hrefs, such as href="/users