Skip to content

Commit

Permalink
Merge pull request #5679 from svbergerem/update-jasmine-ajax
Browse files Browse the repository at this point in the history
Update jasmine-ajax
  • Loading branch information
jhass committed Feb 17, 2015
2 parents ce618b3 + eb7e2ea commit 34187c9
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 314 deletions.
7 changes: 4 additions & 3 deletions Gemfile
Expand Up @@ -262,7 +262,8 @@ group :development, :test do
gem 'cucumber-rails', '1.4.2', :require => false

# Jasmine (client side application tests (JS))
gem 'jasmine', '2.2.0'
gem 'jasmine-jquery-rails', '2.0.3'
gem 'sinon-rails', '1.10.3'
gem 'jasmine', '2.2.0'
gem 'jasmine-jquery-rails', '2.0.3'
gem 'rails-assets-jasmine-ajax', '3.0.0'
gem 'sinon-rails', '1.10.3'
end
4 changes: 4 additions & 0 deletions Gemfile.lock
Expand Up @@ -429,6 +429,9 @@ GEM
rails-assets-jquery-fullscreen (~> 1.1.4)
rails-assets-jquery-ui (~> 1.10.4)
rails-assets-jquery.slimscroll (~> 1.3.3)
rails-assets-jasmine (2.2.1)
rails-assets-jasmine-ajax (3.0.0)
rails-assets-jasmine (~> 2.0)
rails-assets-jeresig--jquery.hotkeys (0.2.0)
rails-assets-jquery (>= 1.4.2)
rails-assets-jquery (1.11.1)
Expand Down Expand Up @@ -693,6 +696,7 @@ DEPENDENCIES
rack-ssl (= 1.4.1)
rails (= 4.1.8)
rails-assets-diaspora_jsxc (~> 0.0.9)
rails-assets-jasmine-ajax (= 3.0.0)
rails-assets-jeresig--jquery.hotkeys (= 0.2.0)
rails-assets-jquery (= 1.11.1)
rails-assets-jquery-idletimer (= 1.0.1)
Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/jasmine-load-all.js
Expand Up @@ -8,3 +8,4 @@
//= require profile
//= require contact-list
//= require sinon
//= require jasmine-ajax
20 changes: 20 additions & 0 deletions spec/controllers/jasmine_fixtures/photos_spec.rb
@@ -0,0 +1,20 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.

require 'spec_helper'

describe PhotosController, :type => :controller do
before do
@alices_photo = alice.post(:photo, :user_file => uploaded_photo, :to => alice.aspects.first.id, :public => false)
sign_in :user, alice
end

describe '#index' do
it "generates a jasmine fixture", :fixture => true do
request.env['HTTP_ACCEPT'] = 'application/json'
get :index, :person_id => alice.person.guid.to_s
save_fixture(response.body, "photos_json")
end
end
end
1 change: 0 additions & 1 deletion spec/controllers/photos_controller_spec.rb
Expand Up @@ -99,7 +99,6 @@
get :index, :person_id => alice.person.guid.to_s

expect(response.headers['Content-Type']).to match 'application/json.*'
save_fixture(response.body, "photos_json")
end

it 'displays by date of creation' do
Expand Down
Expand Up @@ -26,15 +26,15 @@ describe("app.views.AspectMembershipBlueprint", function(){

it('marks the aspect as selected', function() {
this.newAspect.trigger('click');
jasmine.Ajax.requests.mostRecent().response(resp_success);
jasmine.Ajax.requests.mostRecent().respondWith(resp_success);

expect(this.newAspect.attr('class')).toContain('selected');
});

it('displays flash message when added to first aspect', function() {
spec.content().find('li').removeClass('selected');
this.newAspect.trigger('click');
jasmine.Ajax.requests.mostRecent().response(resp_success);
jasmine.Ajax.requests.mostRecent().respondWith(resp_success);

expect($('[id^="flash"]')).toBeSuccessFlashMessage(
Diaspora.I18n.t('aspect_dropdown.started_sharing_with', {name: this.person_name})
Expand All @@ -43,7 +43,7 @@ describe("app.views.AspectMembershipBlueprint", function(){

it('displays an error when it fails', function() {
this.newAspect.trigger('click');
jasmine.Ajax.requests.mostRecent().response(resp_fail);
jasmine.Ajax.requests.mostRecent().respondWith(resp_fail);

expect($('[id^="flash"]')).toBeErrorFlashMessage(
Diaspora.I18n.t('aspect_dropdown.error', {name: this.person_name})
Expand All @@ -59,15 +59,15 @@ describe("app.views.AspectMembershipBlueprint", function(){

it('marks the aspect as unselected', function(){
this.oldAspect.trigger('click');
jasmine.Ajax.requests.mostRecent().response(resp_success);
jasmine.Ajax.requests.mostRecent().respondWith(resp_success);

expect(this.oldAspect.attr('class')).not.toContain('selected');
});

it('displays a flash message when removed from last aspect', function() {
spec.content().find('li.selected:last').removeClass('selected');
this.oldAspect.trigger('click');
jasmine.Ajax.requests.mostRecent().response(resp_success);
jasmine.Ajax.requests.mostRecent().respondWith(resp_success);

expect($('[id^="flash"]')).toBeSuccessFlashMessage(
Diaspora.I18n.t('aspect_dropdown.stopped_sharing_with', {name: this.person_name})
Expand All @@ -76,7 +76,7 @@ describe("app.views.AspectMembershipBlueprint", function(){

it('displays an error when it fails', function() {
this.oldAspect.trigger('click');
jasmine.Ajax.requests.mostRecent().response(resp_fail);
jasmine.Ajax.requests.mostRecent().respondWith(resp_fail);

expect($('[id^="flash"]')).toBeErrorFlashMessage(
Diaspora.I18n.t('aspect_dropdown.error_remove', {name: this.person_name})
Expand Down
12 changes: 6 additions & 6 deletions spec/javascripts/app/views/aspect_membership_view_spec.js
Expand Up @@ -26,15 +26,15 @@ describe("app.views.AspectMembership", function(){

it('marks the aspect as selected', function() {
this.newAspect.trigger('click');
jasmine.Ajax.requests.mostRecent().response(resp_success);
jasmine.Ajax.requests.mostRecent().respondWith(resp_success);

expect(this.newAspect.attr('class')).toContain('selected');
});

it('displays flash message when added to first aspect', function() {
spec.content().find('li').removeClass('selected');
this.newAspect.trigger('click');
jasmine.Ajax.requests.mostRecent().response(resp_success);
jasmine.Ajax.requests.mostRecent().respondWith(resp_success);

expect($('[id^="flash"]')).toBeSuccessFlashMessage(
Diaspora.I18n.t('aspect_dropdown.started_sharing_with', {name: this.person_name})
Expand All @@ -43,7 +43,7 @@ describe("app.views.AspectMembership", function(){

it('displays an error when it fails', function() {
this.newAspect.trigger('click');
jasmine.Ajax.requests.mostRecent().response(resp_fail);
jasmine.Ajax.requests.mostRecent().respondWith(resp_fail);

expect($('[id^="flash"]')).toBeErrorFlashMessage(
Diaspora.I18n.t('aspect_dropdown.error', {name: this.person_name})
Expand All @@ -59,15 +59,15 @@ describe("app.views.AspectMembership", function(){

it('marks the aspect as unselected', function(){
this.oldAspect.trigger('click');
jasmine.Ajax.requests.mostRecent().response(resp_success);
jasmine.Ajax.requests.mostRecent().respondWith(resp_success);

expect(this.oldAspect.attr('class')).not.toContain('selected');
});

it('displays a flash message when removed from last aspect', function() {
spec.content().find('li.selected:last').removeClass('selected');
this.oldAspect.trigger('click');
jasmine.Ajax.requests.mostRecent().response(resp_success);
jasmine.Ajax.requests.mostRecent().respondWith(resp_success);

expect($('[id^="flash"]')).toBeSuccessFlashMessage(
Diaspora.I18n.t('aspect_dropdown.stopped_sharing_with', {name: this.person_name})
Expand All @@ -76,7 +76,7 @@ describe("app.views.AspectMembership", function(){

it('displays an error when it fails', function() {
this.oldAspect.trigger('click');
jasmine.Ajax.requests.mostRecent().response(resp_fail);
jasmine.Ajax.requests.mostRecent().respondWith(resp_fail);

expect($('[id^="flash"]')).toBeErrorFlashMessage(
Diaspora.I18n.t('aspect_dropdown.error_remove', {name: this.person_name})
Expand Down
2 changes: 1 addition & 1 deletion spec/javascripts/app/views/bookmarklet_view_spec.js
Expand Up @@ -54,7 +54,7 @@ describe('app.views.Bookmarklet', function() {
init_bookmarklet(test_data);
spec.content().find('form').submit();

jasmine.Ajax.requests.mostRecent().response({
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200, // success!
responseText: "{}"
});
Expand Down
10 changes: 4 additions & 6 deletions spec/javascripts/app/views/comment_stream_view_spec.js
Expand Up @@ -44,21 +44,19 @@ describe("app.views.CommentStream", function(){
});

it("fires an AJAX request", function() {
var params = JSON.parse(this.request.params);
// TODO: use this, once jasmine-ajax is updated to latest version
//params = this.request.data();
var params = this.request.data();

expect(params.text).toEqual("a new comment");
});

it("adds the comment to the view", function() {
this.request.response({status: 200, responseText: '[]'});
this.request.respondWith({status: 200, responseText: '[]'});
expect(this.view.$(".comment-content p").text()).toEqual("a new comment");
});

it("doesn't add the comment to the view, when the request fails", function(){
Diaspora.I18n.load({failed_to_post_message: "posting failed!"});
this.request.response({status: 500});
this.request.respondWith({status: 500});

expect(this.view.$(".comment-content p").text()).not.toEqual("a new comment");
expect($('*[id^="flash"]')).toBeErrorFlashMessage("posting failed!");
Expand Down Expand Up @@ -93,7 +91,7 @@ describe("app.views.CommentStream", function(){
this.view.$("textarea").val("great post!");
this.view.expandComments();

jasmine.Ajax.requests.mostRecent().response({ comments : [] });
jasmine.Ajax.requests.mostRecent().respondWith({ comments : [] });

expect(this.view.$("textarea").val()).toEqual("great post!");
});
Expand Down
12 changes: 6 additions & 6 deletions spec/javascripts/app/views/contact_view_spec.js
Expand Up @@ -50,7 +50,7 @@ describe("app.views.Contact", function(){
it('adds a aspect_membership to the contact', function() {
expect(this.model.aspect_memberships.length).toBe(1);
$('.contact_add-to-aspect',this.contact).trigger('click');
jasmine.Ajax.requests.mostRecent().response({
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200, // success
responseText: this.response
});
Expand All @@ -60,7 +60,7 @@ describe("app.views.Contact", function(){
it('calls render', function() {
spyOn(this.view, 'render');
$('.contact_add-to-aspect',this.contact).trigger('click');
jasmine.Ajax.requests.mostRecent().response({
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200, // success
responseText: this.response
});
Expand All @@ -70,7 +70,7 @@ describe("app.views.Contact", function(){

it('displays a flash message on errors', function(){
$('.contact_add-to-aspect',this.contact).trigger('click');
jasmine.Ajax.requests.mostRecent().response({
jasmine.Ajax.requests.mostRecent().respondWith({
status: 400, // fail
});
expect($('[id^="flash"]')).toBeErrorFlashMessage(
Expand Down Expand Up @@ -102,7 +102,7 @@ describe("app.views.Contact", function(){
it('removes the aspect_membership from the contact', function() {
expect(this.model.aspect_memberships.length).toBe(1);
$('.contact_remove-from-aspect',this.contact).trigger('click');
jasmine.Ajax.requests.mostRecent().response({
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200, // success
responseText: this.response
});
Expand All @@ -112,7 +112,7 @@ describe("app.views.Contact", function(){
it('calls render', function() {
spyOn(this.view, 'render');
$('.contact_remove-from-aspect',this.contact).trigger('click');
jasmine.Ajax.requests.mostRecent().response({
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200, // success
responseText: this.response,
});
Expand All @@ -121,7 +121,7 @@ describe("app.views.Contact", function(){

it('displays a flash message on errors', function(){
$('.contact_remove-from-aspect',this.contact).trigger('click');
jasmine.Ajax.requests.mostRecent().response({
jasmine.Ajax.requests.mostRecent().respondWith({
status: 400, // fail
});
expect($('[id^="flash"]')).toBeErrorFlashMessage(
Expand Down

0 comments on commit 34187c9

Please sign in to comment.