Skip to content

Commit

Permalink
Remove jasminerice and use jasmine-gem directly
Browse files Browse the repository at this point in the history
Use the latest version of jasmine via the jasmine-gem. This supports the
asset pipeline natively and works with the latest version of phantomjs.
There's no need to use jasminerice anymore.

- Add explicit jasmine gem dependency (was being implicitly pulled by
  guard-jasmine).
- Update guard-jasmine.
- Remove custom phantomjs download from Travis config file.
- Add configuration for jasmine via the jasmine.yml and
  jasmine_helper.rb.
- Rewrite the different page callbacks handling mechanism to make it
  compatible with the new jasmine harness. Previously the helper was
  loaded first, before the application JS. Since that's no longer the
  case, we can't overwrite each onPage function in the helper. Instead,
  in the onPage function we save the callbacks and execute them on DOM
  loaded all at once if the relevant piece of DOM is available, or by
  manually calling runPageCallbacks() from the spec helper.
- Fix some compatibility related Jasmine API usages.
  • Loading branch information
ggiraldez committed Apr 4, 2016
1 parent 4d5cd68 commit f9662ce
Show file tree
Hide file tree
Showing 27 changed files with 232 additions and 145 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ before_script:
script:
- bundle exec rspec spec/ plugins/
- bundle exec rspec -t js spec/integration/
- bundle exec guard-jasmine
- bundle exec rake jasmine:ci
notifications:
slack:
secure: DCdc+fWXLZ8ISmp4lA5NcpvJugQ/cPxLAdRxxYhvO4P3wpjpL4OXoiZHyb1lxcq9ripMrf/jqgb4p3GlYwN/1o+B9v9MwjmyyT3BQGvxVWA30XRaiCxGojfWTq2banOv6pZ3VQ7qwHVsU+8QMxlclEQUWO7yCJEoMlgIp3fWHks=
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ group :test, :development do
gem 'spring-commands-rspec'
gem 'faker'
gem 'machinist', '1.0.6'
gem 'jasminerice', '~> 0.1.0', :git => 'https://github.com/bradphelan/jasminerice'
gem 'guard-jasmine'
gem 'jasmine', '~> 2.4.0'
gem 'guard-jasmine', '~> 2.0.6'
gem 'pry-byebug'
end

Expand Down
11 changes: 2 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
GIT
remote: https://github.com/bradphelan/jasminerice
revision: 091349c27343bfa728b8e5745675f9ddbb7d9699
specs:
jasminerice (0.1.0)
coffee-rails

GIT
remote: https://github.com/instedd/alto_guisso
revision: 6d72573c211f45ff95d36847af733449acdfa04a
Expand Down Expand Up @@ -522,14 +515,14 @@ DEPENDENCIES
foreman
gettext (~> 3.1.2)
gettext_i18n_rails_js!
guard-jasmine
guard-jasmine (~> 2.0.6)
haml-magic-translations
haml-rails (~> 0.4)
ice_cube
includes-count
instedd-rails (~> 0.0.24)
instedd_telemetry!
jasminerice (~> 0.1.0)!
jasmine (~> 2.4.0)
jquery-rails (~> 2.0.2)
knockoutjs-rails
lodash-rails
Expand Down
9 changes: 5 additions & 4 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme

guard 'jasmine' do
watch(%r{spec/javascripts/spec\.(js\.coffee|js|coffee)$}) { "spec/javascripts" }
watch(%r{spec/javascripts/.+_spec\.(js\.coffee|js|coffee)$})
watch(%r{app/assets/javascripts/(.+?)\.(js\.coffee|js|coffee)$}) { |m| "spec/javascripts/#{m[1]}_spec.#{m[2]}" }
guard :jasmine, server_mount: '/' do
watch(%r{^(plugins/(.+)/)?spec/javascripts/.*(?:_s|S)pec\.(coffee|js)$})
watch(%r{app/assets/javascripts/(.+?)\.(js\.coffee|js|coffee)(?:\.\w+)*$}) do |m|
"spec/javascripts/#{ m[1] }_spec.#{ m[2] }"
end
end
6 changes: 6 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@
require File.expand_path('../config/application', __FILE__)

ResourceMap::Application.load_tasks

require 'guard/jasmine/task'

Guard::JasmineTask.new do |task|
task.options = '-m /'
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class @Membership extends Expandable
isSticky = $(".table-header").hasClass("sticky")
table_header = $(".table-header")
table = $("#memberPermissionsTable")
return unless table.length > 0

should_be_sticky = $(this).scrollTop() > table.offset().top && ($(this).scrollTop() < table.offset().top + table.outerHeight())
if should_be_sticky
Expand Down
5 changes: 4 additions & 1 deletion app/assets/javascripts/collections/on_collections.coffee
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
window.onCollections ?= (callback) -> $(-> callback() if $('#collections-main').length > 0)
collectionsCallbacks = []
window.onCollections = (callback) -> collectionsCallbacks.push(callback)
window.runCollectionsCallbacks = -> callback() for callback in collectionsCallbacks
$ -> runCollectionsCallbacks() if $('#collections-main').length > 0
10 changes: 8 additions & 2 deletions app/assets/javascripts/import_wizard/on_import_wizard.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
window.onImportWizard ?= (callback) -> $(-> callback() if $('#import-wizard-main').length > 0)
importWizardCallbacks = []
window.onImportWizard = (callback) -> importWizardCallbacks.push(callback)
window.runImportWizardCallbacks = -> callback() for callback in importWizardCallbacks
$ -> runImportWizardCallbacks() if $('#import-wizard-main').length > 0

window.onImportInProgress ?= (callback) -> $(-> callback() if $('#import-in-progress').length > 0)
importInProgressCallbacks = []
window.onImportInProgress = (callback) -> importInProgressCallbacks.push(callback)
window.runImportInProgressCallbacks = -> callback() for callback in importInProgressCallbacks
$ -> runImportInProgressCallbacks() if $('#import-in-progress').length > 0
5 changes: 4 additions & 1 deletion app/assets/javascripts/layers/on_layers.coffee
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
window.onLayers ?= (callback) -> $(-> callback() if $('#layers-main').length > 0)
layersCallbacks = []
window.onLayers = (callback) -> layersCallbacks.push(callback)
window.runLayersCallbacks = -> callback() for callback in layersCallbacks
$ -> runLayersCallbacks() if $('#layers-main').length > 0
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
window.onThresholds ?= (callback) -> $(-> callback() if $('#thresholds-main').length > 0)
thresholdsCallbacks = []
window.onThresholds = (callback) -> thresholdsCallbacks.push(callback)
window.runThresholdsCallbacks = -> callback() for callback in thresholdsCallbacks
$ -> runThresholdsCallbacks() if $('#thresholds-main').length > 0
1 change: 0 additions & 1 deletion plugins/alerts/spec/javascripts/alerts_spec.coffee

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe 'Condition', ->
describe 'formatted value', ->
beforeEach ->
@field = new Field id: 1, kind: 'numeric'
spyOn(window.model, 'findField').andReturn @field
spyOn(window.model, 'findField').and.returnValue @field

it 'should format value', ->
condition = new Condition field: '1', type: 'value', value: 12
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe 'MainViewModel', ->

it "should post the threshold's json", ->
@model.saveThreshold()
expect($.post).toHaveBeenCalledWith("/plugin/alerts/collections/#{@collectionId}/thresholds.json", {threshold: {conditions: [], color : 'tomato', ord: 1, name : 'beds', is_all_site : 'true', is_all_condition : 'true', is_notify : 'true', email_notification: {fields: ["1","2"], users: ["1", "2"], members: ["1", "2"]}, phone_notification: {fields: ["1","2"], users: ["1", "2"], members: ["1", "2"]}, message_notification : 'alert_01', sites : [ ]}}, @model.saveThresholdCallback)
expect($.post).toHaveBeenCalledWith("/plugin/alerts/collections/#{@collectionId}/thresholds.json", {threshold: {id: undefined, conditions: [], color : 'tomato', ord: 1, name : 'beds', is_all_site : 'true', is_all_condition : 'true', is_notify : 'true', email_notification: {fields: ["1","2"], users: ["1", "2"], members: ["1", "2"]}, phone_notification: {fields: ["1","2"], users: ["1", "2"], members: ["1", "2"]}, message_notification : 'alert_01', sites : [ ]}}, @model.saveThresholdCallback)

it "should put the threshold's json if it has an id", ->
@threshold.id(1)
Expand All @@ -73,7 +73,7 @@ describe 'MainViewModel', ->

describe 'add threshold', ->
beforeEach ->
spyOn(window.model, 'findField').andReturn @field
spyOn(window.model, 'findField').and.returnValue @field
@model.addThreshold()

it 'should add threshold to thresholds', ->
Expand Down Expand Up @@ -102,7 +102,7 @@ describe 'MainViewModel', ->
expect(@model.thresholds()[0].color()).toBe 'tomato'

it 'should restore the conditions when canceling', ->
spyOn(window.model, 'findField').andReturn @field
spyOn(window.model, 'findField').and.returnValue @field
@threshold.conditions [new Condition]
@model.cancelThreshold()
expect(@model.thresholds()[0].conditions().length).toEqual 0
Expand All @@ -118,10 +118,10 @@ describe 'MainViewModel', ->
expect(window.confirm).toHaveBeenCalledWith 'Are you sure to delete threshold?'

it "should delete the threshold's json", ->
spyOn(window, 'confirm').andReturn true
spyOn($, 'post').andReturn true
spyOn(window, 'confirm').and.returnValue true
spyOn($, 'post').and.returnValue true
@model.deleteThreshold @threshold
@expect($.post).toHaveBeenCalledWith "/plugin/alerts/collections/#{@collectionId}/thresholds/#{@threshold.id()}.json", { _method: 'delete' }, @model.deleteThresholdCallback
expect($.post).toHaveBeenCalledWith "/plugin/alerts/collections/#{@collectionId}/thresholds/#{@threshold.id()}.json", { _method: 'delete' }, @model.deleteThresholdCallback

describe 'move threshold', ->
beforeEach ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ describe 'Threshold', ->
expect(@threshold.valid()).toBeFalsy()

it 'should check is first condtion', ->
@threshold.isFirstCondition @threshold.conditions()[0]
expect(@threshold.isFirstCondition @threshold.conditions()[0]).toBeTruthy()

it 'should check is last condtion', ->
@threshold.isLastCondition @threshold.conditions()[0]
expect(@threshold.isLastCondition @threshold.conditions()[0]).toBeTruthy()

it 'should add condition', ->
spyOn(window.model, 'findField').andReturn @field_beds
spyOn(window.model, 'findField').and.returnValue @field_beds
@threshold.addNewCondition()
expect(@threshold.conditions().length).toEqual 2

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
window.onChannels ?= (callback) -> $(-> callback() if $('#channels-main').length > 0)
channelsCallbacks = []
window.onChannels = (callback) -> channelsCallbacks.push(callback)
window.runChannelsCallbacks = -> callback() for callback in channelsCallbacks
$ -> runChannelsCallbacks() if $('#channels-main').length > 0
53 changes: 26 additions & 27 deletions plugins/channels/spec/javascripts/channels/channel_spec.coffee
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
describe 'Channel', ->
xit ->
beforeEach ->
window.runOnCallbacks 'channels'
@collectionId = 1
@channel = new Channel {id:1, collection_id: @collectionId, name:'Regional (GSM)', ticket_code: '', password: '12345', is_manual_configuration: true, is_share: 'false', share_collections: []}, @collectionId
it 'should have 1 channel', ->
expect(@channel.valid()).toBeTruthy()
xdescribe 'Channel', ->
beforeEach ->
window.runOnCallbacks 'channels'
@collectionId = 1
@channel = new Channel {id:1, collection_id: @collectionId, name:'Regional (GSM)', ticket_code: '', password: '12345', is_manual_configuration: true, is_share: 'false', share_collections: []}, @collectionId
it 'should have 1 channel', ->
expect(@channel.valid()).toBeTruthy()

it 'should have property is_admin = true', ->
expect(@channel.isAdmin).toBeTruthy()
it 'should have property is_admin = true', ->
expect(@channel.isAdmin).toBeTruthy()

it 'should not valid when password less than 4 characters', ->
@channel.password '12'
expect(@channel.valid()).toBeFalsy()
it 'should not valid when password less than 4 characters', ->
@channel.password '12'
expect(@channel.valid()).toBeFalsy()

it 'should not valid when name less than 4 characters', ->
@channel.name 'ab'
expect(@channel.valid()).toBeFalsy()
it 'should not valid when name less than 4 characters', ->
@channel.name 'ab'
expect(@channel.valid()).toBeFalsy()

it 'should parsed to Json format', ->
expect(@channel.toJson()).toEqual {
id: 1
collection_id : @collectionId
name : 'Regional (GSM)'
is_share : 'false'
is_manual_configuration : true
password : '12345'
ticket_code : ''
share_collections : []
}
it 'should parsed to Json format', ->
expect(@channel.toJson()).toEqual {
id: 1
collection_id : @collectionId
name : 'Regional (GSM)'
is_share : 'false'
is_manual_configuration : true
password : '12345'
ticket_code : ''
share_collections : []
}
123 changes: 61 additions & 62 deletions plugins/channels/spec/javascripts/channels/main_view_model_spec.coffee
Original file line number Diff line number Diff line change
@@ -1,63 +1,62 @@
describe 'MainViewModel', ->
xit ->
xdescribe 'MainViewModel', ->
beforeEach ->
window.runOnCallbacks 'channels'
@collectionId =1
@model = new MainViewModel @collectionId
window.model = @model

describe 'create threshold', ->
beforeEach ->
window.runOnCallbacks 'channels'
@collectionId =1
@model = new MainViewModel @collectionId
window.model = @model

describe 'create threshold', ->
beforeEach ->
@model.addChannel()

it 'should add channel to channels', ->
expect(@model.channels().length).toEqual 1

it 'should add channel to channels with property isAdmin = true', ->
expect(@model.channels()[0].isAdmin).toEqual true

it 'should add channel to channels with property queued_messages_count = 0', ->
expect(@model.channels()[0].queuedMessageText()).toMatch(/Client disconected,0 message pending/)

it 'should add channel to channels with is_manual_configuration = true', ->
expect(@model.channels()[0].isManualConfiguration()).toBeTruthy

it 'should add channel to channels with is_share = true', ->
expect(@model.channels()[0].isShare()).toMatch(/false/)

describe 'edit channel', ->
beforeEach ->
@channel = new Channel {id:1, collection_id: @collectionId, name:'Regional (GSM)', password: '12345', is_enable: true, nuntium_channel_name: 'ch_01', is_manual_configuration: true, is_share: false, collections: [{id: 3, name: 'col 1'}, {id: 2, name: 'col 02'}]}
@model.channels.push @channel
@model.editChannel @channel

it 'should restore channel name after cancel', ->
@model.channels()[0].name()
@model.cancelChannel()
expect(@model.channels()[0].name()).toEqual('Regional (GSM)')

it "should restore channel's password after cancel", ->
@model.channels()[0].password(9999)
@model.cancelChannel()
expect(@model.channels()[0].password()).toMatch(/12345/)

it "should restore channel's shared_collections after cancel", ->
@model.channels()[0].sharedCollections()
@model.cancelChannel()
expect(@model.channels()[0].sharedCollections()).toEqual [{id: 3, name: 'col 1'}, {id: 2, name: 'col 02'}]

describe 'delete channel', ->
beforeEach ->
@channel = new Channel {id:1, collection_id: @collectionId, name:'Regional (GSM)', is_enable: true, nuntium_channel_name: 'ch_01', is_manual_configuration: true, is_share: false, collections: [{id: 1, name: 'col 1'}, {id: 2, name: 'col 02'}]}
@model.channels.push @channel

it 'should show confirm dialog', ->
spyOn window, 'confirm'
@model.deleteChannel @channel
expect(window.confirm).toHaveBeenCalledWith 'Are you sure to delete channel?'

it 'should delete the channel', ->
spyOn(window, 'confirm').andReturn true
spyOn($, 'post').andReturn true
@model.deleteChannel @channel
@expect($.post).toHaveBeenCalledWith "/plugin/channels/collections/#{@collectionId}/channels/#{@channel.id}.json", { _method: 'delete' }, @model.deleteChannelCallback
@model.addChannel()

it 'should add channel to channels', ->
expect(@model.channels().length).toEqual 1

it 'should add channel to channels with property isAdmin = true', ->
expect(@model.channels()[0].isAdmin).toEqual true

it 'should add channel to channels with property queued_messages_count = 0', ->
expect(@model.channels()[0].queuedMessageText()).toMatch(/Client disconected,0 message pending/)

it 'should add channel to channels with is_manual_configuration = true', ->
expect(@model.channels()[0].isManualConfiguration()).toBeTruthy

it 'should add channel to channels with is_share = true', ->
expect(@model.channels()[0].isShare()).toMatch(/false/)

describe 'edit channel', ->
beforeEach ->
@channel = new Channel {id:1, collection_id: @collectionId, name:'Regional (GSM)', password: '12345', is_enable: true, nuntium_channel_name: 'ch_01', is_manual_configuration: true, is_share: false, collections: [{id: 3, name: 'col 1'}, {id: 2, name: 'col 02'}]}
@model.channels.push @channel
@model.editChannel @channel

it 'should restore channel name after cancel', ->
@model.channels()[0].name()
@model.cancelChannel()
expect(@model.channels()[0].name()).toEqual('Regional (GSM)')

it "should restore channel's password after cancel", ->
@model.channels()[0].password(9999)
@model.cancelChannel()
expect(@model.channels()[0].password()).toMatch(/12345/)

it "should restore channel's shared_collections after cancel", ->
@model.channels()[0].sharedCollections()
@model.cancelChannel()
expect(@model.channels()[0].sharedCollections()).toEqual [{id: 3, name: 'col 1'}, {id: 2, name: 'col 02'}]

describe 'delete channel', ->
beforeEach ->
@channel = new Channel {id:1, collection_id: @collectionId, name:'Regional (GSM)', is_enable: true, nuntium_channel_name: 'ch_01', is_manual_configuration: true, is_share: false, collections: [{id: 1, name: 'col 1'}, {id: 2, name: 'col 02'}]}
@model.channels.push @channel

it 'should show confirm dialog', ->
spyOn window, 'confirm'
@model.deleteChannel @channel
expect(window.confirm).toHaveBeenCalledWith 'Are you sure to delete channel?'

it 'should delete the channel', ->
spyOn(window, 'confirm').and.returnValue true
spyOn($, 'post').and.returnValue true
@model.deleteChannel @channel
@expect($.post).toHaveBeenCalledWith "/plugin/channels/collections/#{@collectionId}/channels/#{@channel.id}.json", { _method: 'delete' }, @model.deleteChannelCallback
1 change: 0 additions & 1 deletion plugins/channels/spec/javascripts/channels_spec.coffee

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
window.onReminders ?= (callback) -> $(-> callback() if $('#reminders-main').length > 0)
remindersCallbacks = []
window.onReminders = (callback) -> remindersCallbacks.push(callback)
window.runRemindersCallbacks = -> callback() for callback in remindersCallbacks
$ -> runRemindersCallbacks() if $('#reminders-main').length > 0
1 change: 0 additions & 1 deletion plugins/reminders/spec/javascripts/reminders_spec.coffee

This file was deleted.

4 changes: 2 additions & 2 deletions spec/javascripts/collections/site_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ describe 'Collection', ->

it "should show a property changed in the diff", ->

spyOn(@collection, 'fetchFields').andCallFake((callback) =>
spyOn(@collection, 'fetchFields').and.callFake((callback) =>
callback()
)

Expand Down Expand Up @@ -179,7 +179,7 @@ describe 'Collection', ->
expect(@site.diff().properties[28]).toBeUndefined()

it "should give similar toJSON() and diff() outputs when all site's properties have changed - except for the id", ->
spyOn(@collection, 'fetchFields').andCallFake((callback) =>
spyOn(@collection, 'fetchFields').and.callFake((callback) =>
callback()
)

Expand Down
Loading

0 comments on commit f9662ce

Please sign in to comment.