diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..c99d2e7 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--require spec_helper diff --git a/Gemfile b/Gemfile index 0edf502..30e96b2 100755 --- a/Gemfile +++ b/Gemfile @@ -13,3 +13,20 @@ gemspec # To use a debugger # gem 'byebug', group: [:development, :test] + +group :development, :test do + gem 'byebug' + + gem 'ffaker' + gem 'rspec-rails', '~> 3.4' + gem 'coffee-rails' + + gem 'teaspoon-jasmine' + gem 'teaspoon-mocha' + gem 'teaspoon-qunit' + + gem 'jquery-rails' + + gem 'codeclimate-test-reporter', '~> 1.0.0' + gem 'simplecov' +end diff --git a/Gemfile.lock b/Gemfile.lock index d48d1b9..33d4140 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,99 +7,194 @@ PATH GEM remote: https://rubygems.org/ specs: - actioncable (5.2.1) - actionpack (= 5.2.1) + actioncable (5.2.0) + actionpack (= 5.2.0) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.1) - actionpack (= 5.2.1) - actionview (= 5.2.1) - activejob (= 5.2.1) + actionmailer (5.2.0) + actionpack (= 5.2.0) + actionview (= 5.2.0) + activejob (= 5.2.0) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.2.1) - actionview (= 5.2.1) - activesupport (= 5.2.1) + actionpack (5.2.0) + actionview (= 5.2.0) + activesupport (= 5.2.0) rack (~> 2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.1) - activesupport (= 5.2.1) + actionview (5.2.0) + activesupport (= 5.2.0) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.2.1) - activesupport (= 5.2.1) + activejob (5.2.0) + activesupport (= 5.2.0) globalid (>= 0.3.6) - activemodel (5.2.1) - activesupport (= 5.2.1) - activerecord (5.2.1) - activemodel (= 5.2.1) - activesupport (= 5.2.1) + activemodel (5.2.0) + activesupport (= 5.2.0) + activerecord (5.2.0) + activemodel (= 5.2.0) + activesupport (= 5.2.0) arel (>= 9.0) - activestorage (5.2.1) - actionpack (= 5.2.1) - activerecord (= 5.2.1) + activestorage (5.2.0) + actionpack (= 5.2.0) + activerecord (= 5.2.0) marcel (~> 0.3.1) - activesupport (5.2.1) + activesupport (5.2.0) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) + addressable (2.5.2) + public_suffix (>= 2.0.2, < 4.0) arel (9.0.0) + ast (2.4.0) builder (3.2.3) - concurrent-ruby (1.0.5) + byebug (10.0.2) + capybara (3.12.0) + addressable + mini_mime (>= 0.1.3) + nokogiri (~> 1.8) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + regexp_parser (~> 1.2) + xpath (~> 3.2) + cliver (0.3.2) + codeclimate-test-reporter (1.0.9) + simplecov (<= 0.13) + coffee-rails (4.2.2) + coffee-script (>= 2.2.0) + railties (>= 4.0.0) + coffee-script (2.4.1) + coffee-script-source + execjs + coffee-script-source (1.12.2) + concurrent-ruby (1.1.3) + coveralls (0.7.2) + multi_json (~> 1.3) + rest-client (= 1.6.7) + simplecov (>= 0.7) + term-ansicolor (= 1.2.2) + thor (= 0.18.1) crass (1.0.4) + diff-lcs (1.3) + docile (1.1.5) erubi (1.7.1) + execjs (2.7.0) + factory_bot (4.11.1) + activesupport (>= 3.0.0) + factory_bot_rails (4.11.1) + factory_bot (~> 4.11.1) + railties (>= 3.0.0) + ffaker (2.10.0) globalid (0.4.1) activesupport (>= 4.2.0) - i18n (1.1.0) + i18n (1.2.0) concurrent-ruby (~> 1.0) - loofah (2.2.2) + jaro_winkler (1.5.1) + jquery-rails (4.3.3) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + json (2.1.0) + loofah (2.2.3) crass (~> 1.0.2) nokogiri (>= 1.5.9) - mail (2.7.0) + mail (2.7.1) mini_mime (>= 0.1.1) marcel (0.3.3) mimemagic (~> 0.3.2) - method_source (0.9.0) + method_source (0.9.2) + mime-types (3.2.2) + mime-types-data (~> 3.2015) + mime-types-data (3.2018.0812) mimemagic (0.3.2) mini_mime (1.0.1) mini_portile2 (2.3.0) minitest (5.11.3) + multi_json (1.13.1) nio4r (2.3.1) - nokogiri (1.8.4) + nokogiri (1.8.5) mini_portile2 (~> 2.3.0) - rack (2.0.5) + parallel (1.12.1) + parser (2.5.3.0) + ast (~> 2.4.0) + poltergeist (1.18.1) + capybara (>= 2.1, < 4) + cliver (~> 0.3.1) + websocket-driver (>= 0.2.0) + powerpack (0.1.2) + public_suffix (3.0.3) + rack (2.0.6) rack-test (1.1.0) rack (>= 1.0, < 3) - rails (5.2.1) - actioncable (= 5.2.1) - actionmailer (= 5.2.1) - actionpack (= 5.2.1) - actionview (= 5.2.1) - activejob (= 5.2.1) - activemodel (= 5.2.1) - activerecord (= 5.2.1) - activestorage (= 5.2.1) - activesupport (= 5.2.1) + rails (5.2.0) + actioncable (= 5.2.0) + actionmailer (= 5.2.0) + actionpack (= 5.2.0) + actionview (= 5.2.0) + activejob (= 5.2.0) + activemodel (= 5.2.0) + activerecord (= 5.2.0) + activestorage (= 5.2.0) + activesupport (= 5.2.0) bundler (>= 1.3.0) - railties (= 5.2.1) + railties (= 5.2.0) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) rails-html-sanitizer (1.0.4) loofah (~> 2.2, >= 2.2.2) - railties (5.2.1) - actionpack (= 5.2.1) - activesupport (= 5.2.1) + railties (5.2.0) + actionpack (= 5.2.0) + activesupport (= 5.2.0) method_source rake (>= 0.8.7) - thor (>= 0.19.0, < 2.0) - rake (12.3.1) + thor (>= 0.18.1, < 2.0) + rainbow (3.0.0) + rake (12.3.2) + regexp_parser (1.3.0) + rest-client (1.6.7) + mime-types (>= 1.16) + rspec (3.8.0) + rspec-core (~> 3.8.0) + rspec-expectations (~> 3.8.0) + rspec-mocks (~> 3.8.0) + rspec-core (3.8.0) + rspec-support (~> 3.8.0) + rspec-expectations (3.8.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.8.0) + rspec-mocks (3.8.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.8.0) + rspec-rails (3.8.1) + actionpack (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) + rspec-core (~> 3.8.0) + rspec-expectations (~> 3.8.0) + rspec-mocks (~> 3.8.0) + rspec-support (~> 3.8.0) + rspec-support (3.8.0) + rubocop (0.61.1) + jaro_winkler (~> 1.5.1) + parallel (~> 1.10) + parser (>= 2.5, != 2.5.1.1) + powerpack (~> 0.1) + rainbow (>= 2.2.2, < 4.0) + ruby-progressbar (~> 1.7) + unicode-display_width (~> 1.4.0) + ruby-progressbar (1.10.0) + simplecov (0.13.0) + docile (~> 1.1.0) + json (>= 1.8, < 3) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.2) sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) @@ -108,22 +203,49 @@ GEM activesupport (>= 4.0) sprockets (>= 3.0.0) sqlite3 (1.3.13) - sqlite3 (1.3.13-x86-mingw32) - thor (0.20.0) + teaspoon (1.1.5) + railties (>= 3.2.5, < 6) + teaspoon-jasmine (2.3.4) + teaspoon (>= 1.0.0) + teaspoon-mocha (2.3.3) + teaspoon (>= 1.0.0) + teaspoon-qunit (1.20.0) + teaspoon (>= 1.0.0) + term-ansicolor (1.2.2) + tins (~> 0.8) + thor (0.18.1) thread_safe (0.3.6) + tins (0.13.2) tzinfo (1.2.5) thread_safe (~> 0.1) + unicode-display_width (1.4.0) websocket-driver (0.7.0) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.3) + xpath (3.2.0) + nokogiri (~> 1.8) PLATFORMS ruby - x86-mingw32 DEPENDENCIES + byebug + codeclimate-test-reporter (~> 1.0.0) + coffee-rails + coveralls datashift_audio_engine! + factory_bot_rails (~> 4.8, >= 4.8.2) + ffaker + jquery-rails + poltergeist + rspec + rspec-rails (~> 3.4) + rubocop + simplecov sqlite3 + teaspoon-jasmine + teaspoon-mocha + teaspoon-qunit BUNDLED WITH - 1.16.4 + 1.16.3 diff --git a/Rakefile b/Rakefile index 05a75b6..3c72bb1 100755 --- a/Rakefile +++ b/Rakefile @@ -29,4 +29,4 @@ Rake::TestTask.new(:test) do |t| t.verbose = false end -task default: :test +task default: :spec diff --git a/app/assets/javascripts/datashift_audio_engine/application.js b/app/assets/javascripts/datashift_audio_engine/application.js index 80a06a9..bad7dd7 100755 --- a/app/assets/javascripts/datashift_audio_engine/application.js +++ b/app/assets/javascripts/datashift_audio_engine/application.js @@ -13,670 +13,6 @@ //= require rails-ujs //= require activestorage //= require wavesurfer.min +//= require audio_engine // -var datashift_audio_engine = { - state: null, - engine: null, - - save_interval: 1000, - - is_radio: false, - - routes: { - init_url: null, - load_url: null, - save_url: null, - radio_url: null - }, - - settings: { - autoplay: false, - random: false, - repeat: null, - volume: 1 - }, - - waveform_colors: {}, - - user_token: null, - client_token: null, - - playlist_id: 0, - playlist: {}, - audio_data: {}, - visual: {}, - - timer: null, - - init: function(init_url = null){ - if (init_url == null) init_url = this.routes.init_url; - // - // Load data from local storage first time - // - var self = this; - - // service - var user_token = window.localStorage.getItem('user_token'); - var client_token = window.localStorage.getItem('client_token'); - - // player - var autoplay = window.localStorage.getItem('autoplay'); - var random = window.localStorage.getItem('random'); - var repeat = window.localStorage.getItem('repeat'); - var volume = parseFloat(window.localStorage.getItem('volume')); - - if (isNaN(volume)) volume = 1; - - // normalize player settings - this.settings.autoplay = (autoplay == 'true'); - this.settings.random = (random == 'true'); - this.settings.repeat = repeat; - this.settings.volume = volume; - - // - // Update settings - // - - // sync settings - if (init_url != null) - $.ajax( - { - method: "POST", - url: init_url, - type: "script", - data: { - user_token: this.user_token, - client_token: this.client_token - } - }).done(function( json_data ) { - - var data = json_data; - - console.log("In INIT - JSON:"); - console.log(data); - self.user_token = data.saved.service.user_token; - self.client_token = data.saved.service.client_token; - - window.localStorage.setItem('user_token', self.user_token); - window.localStorage.setItem('client_token', self.client_token); - - // routes - if (data.routes) { - if (data.routes.save_url) datashift_audio_engine.routes.save_url = data.routes.save_url; - console.log('SET save_current_state - URL:'); - console.log(datashift_audio_engine.routes.save_url); - } - - // track - if (data.saved.audio) { - self.audio_data.playlist = parseInt(data.saved.audio.playlist); - self.audio_data.page = parseInt(data.saved.audio.page); - self.audio_data.total_pages = parseInt(data.saved.audio.total_pages); - self.audio_data.track = parseInt(data.saved.audio.track); - self.audio_data.position = parseFloat(data.saved.audio.position); - } - - if (self.audio_data.playlist == null || self.audio_data.playlist == NaN) self.audio_data.playlist = 0; - if (self.audio_data.page == null || self.audio_data.page == NaN) self.audio_data.page = 0; - if (self.audio_data.total_pages == null || self.audio_data.total_pages == NaN) self.audio_data.total_pages = 0; - if (self.audio_data.track == null || self.audio_data.track == NaN) self.audio_data.track = 0; - if (self.audio_data.position == null || self.audio_data.position == NaN) self.audio_data.position = 0; - - self.waveform_colors = { - wave_color: data.saved.waveform_colors.wave_color, - progress_color: data.saved.waveform_colors.progress_color, - cursor_color: data.saved.waveform_colors.cursor_color, - bar_width: data.saved.waveform_colors.bar_width, - } - - self.state = 'inited'; - console.log(self.state); - }).fail(function(){ - self.audio_data.playlist = -1; - self.audio_data.page = 0; - self.audio_data.track = 0; - self.audio_data.position = 0; - - self.waveform_colors = { - wave_color: 'grey', - progress_color: 'white', - cursor_color: '#dafcff', - bar_width: 2, - } - - self.state = 'fail inited'; - console.error(self.state); - }); - else { - self.audio_data.playlist = -1; - self.audio_data.page = 0; - self.audio_data.track = 0; - self.audio_data.position = 0; - - self.waveform_colors = { - wave_color: 'grey', - progress_color: 'white', - cursor_color: '#dafcff', - bar_width: 2, - } - - self.state = 'init url not found'; - console.info(self.state); - } - - - - // - // Visual update - // - this.visual = { - play: $('#datashift-audio-player .play'), - pause: $('#datashift-audio-player .pause'), - - prev: $('#datashift-audio-player .datashift-audio-track-controls .previous'), - next: $('#datashift-audio-player .datashift-audio-track-controls .next'), - - volume: $('#datashift-audio-player .datashift-audio-track-volume input[type=range].datashift-audio-input-range'), - - author_name: $('#datashift-audio-player .datashift-audio-track-basic-info .datashift-audio-author-name'), - track_name: $('#datashift-audio-player .datashift-audio-track-basic-info .datashift-audio-track-name'), - - cover_image: $('#datashift-audio-player .datashift-audio-track-cover'), - cover_image_img: $('#datashift-audio-track-cover-img'), - - playlist: $('#datashift-audio-playlist'), - waveform: $('#datashift-audio-player #waveform'), - - current_position: $('#datashift-audio-player .datashift-audio-current-position'), - total_duration: $('#datashift-audio-player .datashift-audio-total-duration'), - - pages: $('#datashift-audio-player .datashift-audio-pages'), - - btn_toggle_playlist: $('#datashift-audio-toggle-playlist'), - } - - // - // Events - // - - this.visual.play.on('click', function(){ - self.play(); - }); - - this.visual.pause.on('click', function(){ - self.pause(); - }); - - this.visual.prev.on('click', function(){ - self.previous(); - }); - - this.visual.next.on('click', function(){ - self.next(); - }); - - this.visual.btn_toggle_playlist.on('click', function(){ - if(self.visual.btn_toggle_playlist.hasClass('datashift-audio-active')){ - self.visual.btn_toggle_playlist.removeClass('datashift-audio-active'); - self.visual.playlist.addClass('datashift-audio-hide'); - } else { - self.visual.btn_toggle_playlist.addClass('datashift-audio-active'); - self.visual.playlist.removeClass('datashift-audio-hide'); - } - }); - - $('#datashift-audio-player .datashift-audio-track-volume i').on('click', function(){ - var current_value = parseInt(datashift_audio_engine.visual.volume.attr('value')); - var audio_dom_el = datashift_audio_engine.visual.volume.get(0); - console.log( 'volume: ' + current_value ); - - - if (current_value > 0){ - console.log('current_value > 0'); - - datashift_audio_engine.visual.volume.get(0).value = 0; - datashift_audio_engine.visual.volume.attr('value', 0); - - datashift_audio_engine.engine.setVolume(0); - - if(audio_dom_el.value == 0) { - $('.datashift-audio-track-volume i').addClass('datashift-audio-hide'); - $('.datashift-audio-track-volume i.volume_off').removeClass('datashift-audio-hide') - } - console.log(datashift_audio_engine.visual.volume.get(0).value); - } else { - console.log('current_value == 0'); - - if (current_value == 0 && datashift_audio_engine.settings.volume == 0){ - current_value = 1; - datashift_audio_engine.settings.volume = current_value; - } - - audio_dom_el.value = datashift_audio_engine.settings.volume * 100; - datashift_audio_engine.visual.volume.attr('value', datashift_audio_engine.settings.volume * 100); - datashift_audio_engine.volume(datashift_audio_engine.settings.volume); - - if(audio_dom_el.value >= 75) { - $('.datashift-audio-track-volume i').addClass('datashift-audio-hide'); - $('.datashift-audio-track-volume i.volume_up').removeClass('datashift-audio-hide') - } - - if(audio_dom_el.value >= 50 && audio_dom_el.value < 75) { - $('.datashift-audio-track-volume i').addClass('datashift-audio-hide'); - $('.datashift-audio-track-volume i.volume_down').removeClass('datashift-audio-hide') - } - - if(audio_dom_el.value >= 25 && audio_dom_el.value < 50) { - $('.datashift-audio-track-volume i').addClass('datashift-audio-hide'); - $('.datashift-audio-track-volume i.volume_mute').removeClass('datashift-audio-hide') - } - - console.log(datashift_audio_engine.visual.volume.attr('value')); - } - }); - - this.visual.volume.on('input change', function(update = true) { - if(this.value >= 75) { - $('.datashift-audio-track-volume i').addClass('datashift-audio-hide'); - $('.datashift-audio-track-volume i.volume_up').removeClass('datashift-audio-hide') - } - - if(this.value >= 50 && this.value < 75) { - $('.datashift-audio-track-volume i').addClass('datashift-audio-hide'); - $('.datashift-audio-track-volume i.volume_down').removeClass('datashift-audio-hide') - } - - if(this.value >= 25 && this.value < 50) { - $('.datashift-audio-track-volume i').addClass('datashift-audio-hide'); - $('.datashift-audio-track-volume i.volume_mute').removeClass('datashift-audio-hide') - } - - if(this.value == 0) { - $('.datashift-audio-track-volume i').addClass('datashift-audio-hide'); - $('.datashift-audio-track-volume i.volume_off').removeClass('datashift-audio-hide') - } - - if (update) - datashift_audio_engine.volume(this.value / 100.0); - }); - }, - - // LOAD DATA - // - // ajax request to back-end to get data about track/playlist/radio - // and save it to local variables - // - load: function(load_url = null, is_new = false) { - if (load_url == null) load_url = this.routes.load_url; - var self = this; - - if (load_url != null) { - $.ajax( - { - method: "GET", - url: load_url, - type: "script", - data: { - user_token: this.user_token, - client_token: this.client_token, - random: this.settings.random - } - }).done(function( pure_data ) { - - var data = pure_data; - - self.playlist = data.tracks; - - if(!data.hasOwnProperty('disable_playlist')) { - if (data.hasOwnProperty('playlist_partial')) { - // TOOD: Probably a cecurity hole ? How can se safely render this on the Rails side but return to this Ajax call ?? - self.visual.playlist.html(data.playlist_partial) - console.log('rendered supplied playlist partial'); - } else { - // render default playlist - self.playlist.forEach((track, index) => { - var duration = '
' + formatTime(track.duration) + '
'; - var full_name = '
' + track.author + " - " + track.name + '
'; - - var track_set = duration + full_name; - self.visual.playlist.append('
  • ' + track_set + '
  • '); - }); - self.state = 'created playlist'; - console.log(self.state); - } - - } - - datashift_audio_engine.visual.playlist.children('li').on('click', function(){ - datashift_audio_engine.audio_data.track = parseInt(this.id.split('-')[1]); - datashift_audio_engine.settings.autoplay = true; - datashift_audio_engine.render_wave_from_audio_file() - }); - - self.audio_data.playlist = parseInt(data.playlist); - self.audio_data.total_pages = parseInt(data.total_pages); - - for(counter = 1; counter <= self.audio_data.total_pages; counter++){ - $('.page-selectors .pages').append('
  • ' + counter + '
  • ') - } - - datashift_audio_engine.visual.pages.children('li').on('click', function(){ - datashift_audio_engine.audio_data.page = parseInt(this.id.split('-')[1]); - var next_page = parseInt(this.id.split('-')[1]); - var url = 'radio/' + next_page + '.json' - datashift_audio_engine.new_page(url) - }); - - if (is_new == true){ - self.audio_data.page = 1; - self.audio_data.track = 0; - self.audio_data.position = 0; - - console.log('is new playlist'); - } else { - self.audio_data.page = parseInt(data.page); - self.audio_data.track = parseInt(data.track); - self.audio_data.position = parseFloat(data.position); - } - - if (self.audio_data.playlist == null || self.audio_data.playlist == NaN) self.audio_data.playlist = 0; - if (self.audio_data.page == null || self.audio_data.page == NaN) self.audio_data.page = 0; - if (self.audio_data.total_pages == null || self.audio_data.total_pages == NaN) self.audio_data.total_pages = 0; - if (self.audio_data.track == null || self.audio_data.track == NaN) self.audio_data.track = 0; - if (self.audio_data.position == null || self.audio_data.position == NaN) self.audio_data.position = 0; - - self.state = 'rendering_wave_from_audio_file'; - console.log(self.state); - - self.render_wave_from_audio_file() - }).fail(function(){ - self.playlist = []; - self.state = 'fail playlist loaded'; - console.error(self.state); - }); - } else { - self.playlist = []; - self.state = 'load url not found'; - console.info(self.state); - } - }, - - update_info: function(){ - this.audio_data.position = this.engine.getCurrentTime(); - }, - - // Render audio wave from audio file or pure data - render_wave_from_audio_file: function(){ - // clear - this.visual.waveform.html(''); - - if( this.engine != null ) - this.engine.destroy(); - clearInterval(this.timer); - - this.is_radio = false; - this.visual.prev.removeClass('datashift-audio-hide'); - this.visual.next.removeClass('datashift-audio-hide'); - - // init new - this.engine = WaveSurfer.create({ - container: '#waveform', - waveColor: this.waveform_colors.wave_color, - progressColor: this.waveform_colors.progress_color, - cursorColor: this.waveform_colors.cursor_color, - barWidth: 3, - hideScrollbar: true - }); - - var track = this.playlist[this.audio_data.track]; - - console.info("Rendering wav for Track"); - - this.visual.playlist.children('.datashift-audio-playlist li').removeClass('datashift-audio-active'); - var visual_track = $('#track-' + this.audio_data.track); - visual_track.addClass('datashift-audio-active'); - - this.visual.pages.children('li').removeClass('datashift-audio-active'); - var visual_page = $('#page-' + this.audio_data.page); - visual_page.addClass('datashift-audio-active') - - this.engine.load(track.audio_url); - - this.visual.cover_image_img.html(''); - this.visual.track_name.html(track.name); - this.visual.author_name.html(track.author); - - var self = this; - this.engine.on('ready', function(){ - self.audio_data.position = 0; - self.seek(self.audio_data.position); - - self.visual.current_position.html(formatTime(self.audio_data.position)); - self.visual.total_duration.html(formatTime(self.engine.getDuration())); - - self.volume(self.settings.volume); - self.visual.volume.get(0).value = self.settings.volume * 100; - self.visual.volume.attr('value', self.settings.volume * 100); - - var volume = parseInt(self.visual.volume.attr('value')); - self.visual.volume.change(); - - if (self.settings.autoplay) { - self.play(); - } - - self.engine.on('finish', function(){ - self.save_current_state(); - clearInterval(self.timer); - self.next(); - console.log('track finished'); - }) - - self.state = 'loaded'; - console.log(self.state); - }); - }, - - render_wave_from_pure_data: function(url = null){ - if (url == null) url = this.routes.load_url; - // get data from back-end - // adapt data for render and play - this.visual.waveform.html(''); - this.is_radio = true; - this.visual.prev.addClass('datashift-audio-hide'); - this.visual.next.addClass('datashift-audio-hide'); - this.routes.radio_url = url; - - this.visual.waveform.append(""); - - this.engine = document.getElementById('radio'); - }, - - // MAIN AUDIO CONTROLS - play: function() { - this.visual.play.addClass('datashift-audio-hide'); - this.visual.pause.removeClass('datashift-audio-hide'); - - if (this.is_radio == false) { - this.audio_data.autoplay = true; - this.timer = setInterval(this.save_current_state, this.save_interval); - } else { - this.timer = setInterval(function(){ - $.post('radio_data', { - radio_url: this.radio_url - } - ).done(function(pure_data) { - - var data = pure_data; - - datashift_audio_engine.visual.cover_image_img.html(''); - datashift_audio_engine.visual.author_name.html(data.radio.author); - datashift_audio_engine.visual.track_name.html(data.radio.track); - - console.log('update radio metadata'); - }).fail(function(){ - // datashift_audio_engine.visual.cover_image.css('background-image', 'url("'+ test_audio_data_json.radio.cover_image +'")'); - datashift_audio_engine.visual.author_name.html('Not Found'); - datashift_audio_engine.visual.track_name.html('Not Found'); - - console.log('fail update radio metadata'); - }); - }, 1000); - } - - this.engine.play(); - }, - - pause: function() { - this.visual.pause.addClass('datashift-audio-hide'); - this.visual.play.removeClass('datashift-audio-hide'); - - if (this.is_radio == false) { - this.audio_data.autoplay = false; - this.save_current_state(); - } - clearInterval(this.timer); - - this.engine.pause(); - }, - - previous: function(){ - var new_track = this.audio_data.track - 1; - var track = this.playlist[new_track]; - - if (track != null) { - this.audio_data.track = new_track; - this.audio_data.position = 0; - this.settings.autoplay = true; - - this.render_wave_from_audio_file(); - this.save_current_state(); - } else { - if (this.audio_data.page > 1) - this.new_page('playlist/:id.new_page', false); - } - }, - - next: function(){ - var new_track = this.audio_data.track + 1; - var track = this.playlist[new_track]; - - if (track != null) { - this.audio_data.track = new_track; - this.audio_data.position = 0; - this.settings.autoplay = true; - - this.render_wave_from_audio_file(); - this.save_current_state(); - } else { - if (this.audio_data.page < this.audio_data.total_pages) - this.new_page('playlist/:id.new_page', true) - } - }, - - // url = 'playlist/:id.new_page' - new_page: function(url, fromBeginning = true){ - $.get(url).done(function(pure_data){ - console.log('render new page and select new track'); - - var data = pure_data; - - datashift_audio_engine.playlist = data.tracks; - datashift_audio_engine.page = parseInt(data.page); - - datashift_audio_engine.visual.playlist.html(''); - - datashift_audio_engine.visual.pages.children('li').removeClass('datashift-audio-active'); - var visual_page = $('#page-' + data.page); - visual_page.addClass('datashift-audio-active'); - - datashift_audio_engine.playlist.forEach((track, index) => { - var duration = '
    ' + formatTime(track.duration) + '
    '; - var full_name = '
    ' + track.author + " - " + track.name + '
    '; - - var track_set = duration + full_name; - datashift_audio_engine.visual.playlist.append('
  • ' + track_set + '
  • ') - }); - - datashift_audio_engine.visual.playlist.children('li').on('click', function(){ - datashift_audio_engine.audio_data.track = parseInt(this.id.split('-')[1]); - datashift_audio_engine.settings.autoplay = true; - datashift_audio_engine.render_wave_from_audio_file() - }); - - if (fromBeginning == true){ - datashift_audio_engine.audio_data.track = -1; - datashift_audio_engine.next(); - } else { - datashift_audio_engine.audio_data.track = datashift_audio_engine.playlist.length; - datashift_audio_engine.previous(); - } - }).fail(function(){ - console.error('page not found'); - console.log('page: ' + datashift_audio_engine.audio_data.page) - }); - }, - - volume: function(value){ - if (isNaN(value)) value = 1; - - this.settings.volume = value; - - if (this.is_radio == true){ - this.engine.volume = value; - } else { - this.engine.setVolume(value); - window.localStorage.setItem('volume', value); - } - }, - - seek: function(position){ - this.engine.setCurrentTime(position); - this.audio_data.position = position; - this.save_current_state(); - }, - - // Save current state of a player and send it to the back-end to sync it - save_current_state: function(save_url = null){ - - console.log('save_current_state - URL:'); - console.log(datashift_audio_engine.routes.save_url); - if ( save_url == null && (datashift_audio_engine.routes.save_url == null || datashift_audio_engine.routes.save_url == undefined) ) return; - - if ( datashift_audio_engine.state == undefined ) return; - - if ( save_url == null) save_url = datashift_audio_engine.routes.save_url; - - datashift_audio_engine.update_info(); - - datashift_audio_engine.visual.current_position.html(formatTime(datashift_audio_engine.audio_data.position)); - - var data = { - user_token: datashift_audio_engine.user_token, - client_token: datashift_audio_engine.client_token, - random: datashift_audio_engine.settings.random, - audio_data: datashift_audio_engine.audio_data, - } - - $.post(save_url, data ) - .done(function(){ - console.log('saved'); - }) - .fail(function(){ - console.log('fail to save'); - }); - } -}; - -function formatTime(time_in_seconds){ - var seconds = Math.floor(time_in_seconds); - var minutes = Math.floor(seconds / 60); - - minutes = (minutes >= 10) ? minutes : "0" + minutes; - - seconds = Math.floor(seconds % 60); - seconds = (seconds >= 10) ? seconds : "0" + seconds; - - return minutes + ":" + seconds; -} diff --git a/app/assets/javascripts/datashift_audio_engine/audio_engine.js b/app/assets/javascripts/datashift_audio_engine/audio_engine.js new file mode 100644 index 0000000..0a5344c --- /dev/null +++ b/app/assets/javascripts/datashift_audio_engine/audio_engine.js @@ -0,0 +1,683 @@ +//= require rails-ujs +//= require jquery +//= require jquery_ujs +//= require activestorage +//= require wavesurfer.min + +var datashift_audio_engine = { + state: null, + engine: null, + + save_interval: 1000, + + is_radio: false, + + routes: { + init_url: null, + load_url: null, + save_url: null, + radio_url: null + }, + + settings: { + autoplay: false, + random: false, + repeat: null, + volume: 1 + }, + + waveform_colors: {}, + + user_token: null, + client_token: null, + + playlist_id: 0, + playlist: {}, + audio_data: {}, + visual: {}, + + timer: null, + + init: function(init_url){ + if (init_url === undefined) init_url = this.routes.init_url; + // + // Load data from local storage first time + // + var self = this; + + // service + var user_token = window.localStorage.getItem('user_token'); + var client_token = window.localStorage.getItem('client_token'); + + // player + var autoplay = window.localStorage.getItem('autoplay'); + var random = window.localStorage.getItem('random'); + var repeat = window.localStorage.getItem('repeat'); + var volume = parseFloat(window.localStorage.getItem('volume')); + + if (isNaN(volume)) volume = 1; + + // normalize player settings + this.settings.autoplay = (autoplay == 'true'); + this.settings.random = (random == 'true'); + this.settings.repeat = repeat; + this.settings.volume = volume; + + // + // Update settings + // + + // sync settings + if (init_url !== undefined) { + self.state = 'sent init request'; + $.ajax( + { + method: "POST", + url: init_url, + type: "script", + data: { + user_token: this.user_token, + client_token: this.client_token, + } + }).done(function( json_data ) { + + var data = json_data; + + if(data.saved == undefined) + return; + + console.log("In INIT - JSON:"); + console.log(data); + self.user_token = data.saved.service.user_token; + self.client_token = data.saved.service.client_token; + + window.localStorage.setItem('user_token', self.user_token); + window.localStorage.setItem('client_token', self.client_token); + + // routes + if (data.routes) { + if (data.routes.save_url) datashift_audio_engine.routes.save_url = data.routes.save_url; + console.log('SET save_current_state - URL:'); + console.log(datashift_audio_engine.routes.save_url); + } + + // track + if (data.saved.audio) { + self.audio_data.playlist = parseInt(data.saved.audio.playlist); + self.audio_data.page = parseInt(data.saved.audio.page); + self.audio_data.total_pages = parseInt(data.saved.audio.total_pages); + self.audio_data.track = parseInt(data.saved.audio.track); + self.audio_data.position = parseFloat(data.saved.audio.position); + } + + if (self.audio_data.playlist == null || self.audio_data.playlist == NaN) self.audio_data.playlist = 0; + if (self.audio_data.page == null || self.audio_data.page == NaN) self.audio_data.page = 0; + if (self.audio_data.total_pages == null || self.audio_data.total_pages == NaN) self.audio_data.total_pages = 0; + if (self.audio_data.track == null || self.audio_data.track == NaN) self.audio_data.track = 0; + if (self.audio_data.position == null || self.audio_data.position == NaN) self.audio_data.position = 0; + + self.waveform_colors = { + wave_color: data.saved.waveform_colors.wave_color, + progress_color: data.saved.waveform_colors.progress_color, + cursor_color: data.saved.waveform_colors.cursor_color, + bar_width: data.saved.waveform_colors.bar_width, + } + + self.state = 'inited'; + console.log(self.state); + }).fail(function(){ + self.audio_data.playlist = -1; + self.audio_data.page = 0; + self.audio_data.track = 0; + self.audio_data.position = 0; + + self.waveform_colors = { + wave_color: 'grey', + progress_color: 'white', + cursor_color: '#dafcff', + bar_width: 2, + } + + self.state = 'fail inited'; + console.error(self.state); + }); + } else { + self.audio_data.playlist = -1; + self.audio_data.page = 0; + self.audio_data.track = 0; + self.audio_data.position = 0; + + self.waveform_colors = { + wave_color: 'grey', + progress_color: 'white', + cursor_color: '#dafcff', + bar_width: 2, + } + + self.state = 'init url not found'; + console.info(self.state); + } + + + + // + // Visual update + // + this.visual = { + play: $('#datashift-audio-player .play'), + pause: $('#datashift-audio-player .pause'), + + prev: $('#datashift-audio-player .datashift-audio-track-controls .previous'), + next: $('#datashift-audio-player .datashift-audio-track-controls .next'), + + volume: $('#datashift-audio-player .datashift-audio-track-volume input[type=range].datashift-audio-input-range'), + + author_name: $('#datashift-audio-player .datashift-audio-track-basic-info .datashift-audio-author-name'), + track_name: $('#datashift-audio-player .datashift-audio-track-basic-info .datashift-audio-track-name'), + + cover_image: $('#datashift-audio-player .datashift-audio-track-cover'), + cover_image_img: $('#datashift-audio-track-cover-img'), + + playlist: $('#datashift-audio-playlist'), + waveform: $('#datashift-audio-player #waveform'), + + current_position: $('#datashift-audio-player .datashift-audio-current-position'), + total_duration: $('#datashift-audio-player .datashift-audio-total-duration'), + + pages: $('#datashift-audio-player .datashift-audio-pages'), + + btn_toggle_playlist: $('#datashift-audio-toggle-playlist'), + } + + // + // Events + // + + this.visual.play.on('click', function(){ + self.play(); + }); + + this.visual.pause.on('click', function(){ + self.pause(); + }); + + this.visual.prev.on('click', function(){ + self.previous(); + }); + + this.visual.next.on('click', function(){ + self.next(); + }); + + this.visual.btn_toggle_playlist.on('click', function(){ + if(self.visual.btn_toggle_playlist.hasClass('datashift-audio-active')){ + self.visual.btn_toggle_playlist.removeClass('datashift-audio-active'); + self.visual.playlist.addClass('datashift-audio-hide'); + } else { + self.visual.btn_toggle_playlist.addClass('datashift-audio-active'); + self.visual.playlist.removeClass('datashift-audio-hide'); + } + }); + + $('#datashift-audio-player .datashift-audio-track-volume i').on('click', function(){ + var current_value = parseInt(datashift_audio_engine.visual.volume.attr('value')); + var audio_dom_el = datashift_audio_engine.visual.volume.get(0); + console.log( 'volume: ' + current_value ); + + + if (current_value > 0){ + console.log('current_value > 0'); + + datashift_audio_engine.visual.volume.get(0).value = 0; + datashift_audio_engine.visual.volume.attr('value', 0); + + datashift_audio_engine.engine.setVolume(0); + + if(audio_dom_el.value == 0) { + $('.datashift-audio-track-volume i').addClass('datashift-audio-hide'); + $('.datashift-audio-track-volume i.volume_off').removeClass('datashift-audio-hide') + } + console.log(datashift_audio_engine.visual.volume.get(0).value); + } else { + console.log('current_value == 0'); + + if (current_value == 0 && datashift_audio_engine.settings.volume == 0){ + current_value = 1; + datashift_audio_engine.settings.volume = current_value; + } + + audio_dom_el.value = datashift_audio_engine.settings.volume * 100; + datashift_audio_engine.visual.volume.attr('value', datashift_audio_engine.settings.volume * 100); + datashift_audio_engine.volume(datashift_audio_engine.settings.volume); + + if(audio_dom_el.value >= 75) { + $('.datashift-audio-track-volume i').addClass('datashift-audio-hide'); + $('.datashift-audio-track-volume i.volume_up').removeClass('datashift-audio-hide') + } + + if(audio_dom_el.value >= 50 && audio_dom_el.value < 75) { + $('.datashift-audio-track-volume i').addClass('datashift-audio-hide'); + $('.datashift-audio-track-volume i.volume_down').removeClass('datashift-audio-hide') + } + + if(audio_dom_el.value >= 25 && audio_dom_el.value < 50) { + $('.datashift-audio-track-volume i').addClass('datashift-audio-hide'); + $('.datashift-audio-track-volume i.volume_mute').removeClass('datashift-audio-hide') + } + + console.log(datashift_audio_engine.visual.volume.attr('value')); + } + }); + + this.visual.volume.on('input change', function(update) { + + if (update === undefined) update = true; + if(this.value >= 75) { + $('.datashift-audio-track-volume i').addClass('datashift-audio-hide'); + $('.datashift-audio-track-volume i.volume_up').removeClass('datashift-audio-hide') + } + + if(this.value >= 50 && this.value < 75) { + $('.datashift-audio-track-volume i').addClass('datashift-audio-hide'); + $('.datashift-audio-track-volume i.volume_down').removeClass('datashift-audio-hide') + } + + if(this.value >= 25 && this.value < 50) { + $('.datashift-audio-track-volume i').addClass('datashift-audio-hide'); + $('.datashift-audio-track-volume i.volume_mute').removeClass('datashift-audio-hide') + } + + if(this.value == 0) { + $('.datashift-audio-track-volume i').addClass('datashift-audio-hide'); + $('.datashift-audio-track-volume i.volume_off').removeClass('datashift-audio-hide') + } + + if (update) + datashift_audio_engine.volume(this.value / 100.0); + }); + }, + + // LOAD DATA + // + // ajax request to back-end to get data about track/playlist/radio + // and save it to local variables + // + load: function(load_url, is_new) { + if (load_url === undefined) load_url = this.routes.load_url; + var self = this; + + if (load_url !== undefined) { + self.state = 'sent load request'; + $.ajax( + { + method: "GET", + url: load_url, + type: "script", + data: { + user_token: this.user_token, + client_token: this.client_token, + random: this.settings.random + } + }).done(function( pure_data ) { + + var data = pure_data; + + self.playlist = data.tracks; + + if (self.playlist == undefined) + self.playlist = []; + + if(!data.hasOwnProperty('disable_playlist')) { + if (data.hasOwnProperty('playlist_partial')) { + // TOOD: Probably a cecurity hole ? How can se safely render this on the Rails side but return to this Ajax call ?? + self.visual.playlist.html(data.playlist_partial) + console.log('rendered supplied playlist partial'); + } else { + // render default playlist + self.playlist.forEach(function(track, index) { + var duration = '
    ' + formatTime(track.duration) + '
    '; + var full_name = '
    ' + track.author + " - " + track.name + '
    '; + + var track_set = duration + full_name; + self.visual.playlist.append('
  • ' + track_set + '
  • '); + }); + self.state = 'created playlist'; + console.log(self.state); + } + } + + datashift_audio_engine.visual.playlist.children('li').on('click', function(){ + datashift_audio_engine.audio_data.track = parseInt(this.id.split('-')[1]); + datashift_audio_engine.settings.autoplay = true; + datashift_audio_engine.render_wave_from_audio_file() + }); + + self.audio_data.playlist = parseInt(data.playlist); + self.audio_data.total_pages = parseInt(data.total_pages); + + for(counter = 1; counter <= self.audio_data.total_pages; counter++){ + $('.page-selectors .pages').append('
  • ' + counter + '
  • ') + } + + datashift_audio_engine.visual.pages.children('li').on('click', function(){ + datashift_audio_engine.audio_data.page = parseInt(this.id.split('-')[1]); + var next_page = parseInt(this.id.split('-')[1]); + var url = 'radio/' + next_page + '.json' + datashift_audio_engine.new_page(url) + }); + + if (is_new == true){ + self.audio_data.page = 1; + self.audio_data.track = 0; + self.audio_data.position = 0; + + console.log('is new playlist'); + } else { + self.audio_data.page = parseInt(data.page); + self.audio_data.track = parseInt(data.track); + self.audio_data.position = parseFloat(data.position); + } + + if (self.audio_data.playlist == null || self.audio_data.playlist == NaN) self.audio_data.playlist = 0; + if (self.audio_data.page == null || self.audio_data.page == NaN) self.audio_data.page = 0; + if (self.audio_data.total_pages == null || self.audio_data.total_pages == NaN) self.audio_data.total_pages = 0; + if (self.audio_data.track == null || self.audio_data.track == NaN) self.audio_data.track = 0; + if (self.audio_data.position == null || self.audio_data.position == NaN) self.audio_data.position = 0; + + self.state = 'rendering_wave_from_audio_file'; + console.log(self.state); + + self.render_wave_from_audio_file() + }).fail(function(){ + self.playlist = []; + self.state = 'fail playlist loaded'; + console.error(self.state); + }); + } else { + self.playlist = []; + self.state = 'load url not found'; + console.info(self.state); + } + }, + + update_info: function(){ + this.audio_data.position = this.engine.getCurrentTime(); + }, + + // Render audio wave from audio file or pure data + render_wave_from_audio_file: function(){ + + // clear + this.visual.waveform.html(''); + + if( this.engine != null ) + this.engine.destroy(); + clearInterval(this.timer); + + this.is_radio = false; + this.visual.prev.removeClass('datashift-audio-hide'); + this.visual.next.removeClass('datashift-audio-hide'); + + + console.log(WaveSurfer) + // init new + this.engine = WaveSurfer.create({ + container: '#waveform', + waveColor: this.waveform_colors.wave_color, + progressColor: this.waveform_colors.progress_color, + cursorColor: this.waveform_colors.cursor_color, + barWidth: 3, + hideScrollbar: true + }); + + var track = this.playlist[this.audio_data.track]; + + console.info("Rendering wav for Track"); + + this.visual.playlist.children('.datashift-audio-playlist li').removeClass('datashift-audio-active'); + var visual_track = $('#track-' + this.audio_data.track); + visual_track.addClass('datashift-audio-active'); + + this.visual.pages.children('li').removeClass('datashift-audio-active'); + var visual_page = $('#page-' + this.audio_data.page); + visual_page.addClass('datashift-audio-active') + + this.engine.load(track.audio_url); + + this.visual.cover_image_img.html(''); + this.visual.track_name.html(track.name); + this.visual.author_name.html(track.author); + + var self = this; + this.engine.on('ready', function(){ + self.audio_data.position = 0; + self.seek(self.audio_data.position); + + self.visual.current_position.html(formatTime(self.audio_data.position)); + self.visual.total_duration.html(formatTime(self.engine.getDuration())); + + self.volume(self.settings.volume); + self.visual.volume.get(0).value = self.settings.volume * 100; + self.visual.volume.attr('value', self.settings.volume * 100); + + var volume = parseInt(self.visual.volume.attr('value')); + self.visual.volume.change(); + + if (self.settings.autoplay) { + self.play(); + } + + self.engine.on('finish', function(){ + self.save_current_state(); + clearInterval(self.timer); + self.next(); + console.log('track finished'); + }) + + self.state = 'loaded'; + console.log(self.state); + }); + }, + + render_wave_from_pure_data: function(url){ + if (url === undefined) url = this.routes.load_url; + // get data from back-end + // adapt data for render and play + this.visual.waveform.html(''); + this.is_radio = true; + this.visual.prev.addClass('datashift-audio-hide'); + this.visual.next.addClass('datashift-audio-hide'); + this.routes.radio_url = url; + + this.visual.waveform.append(""); + + this.engine = document.getElementById('radio'); + }, + + // MAIN AUDIO CONTROLS + play: function() { + this.visual.play.addClass('datashift-audio-hide'); + this.visual.pause.removeClass('datashift-audio-hide'); + + if (this.is_radio == false) { + this.audio_data.autoplay = true; + this.timer = setInterval(this.save_current_state, this.save_interval); + } else { + this.timer = setInterval(function(){ + $.post('radio_data', { + radio_url: this.radio_url + } + ).done(function(pure_data) { + + var data = pure_data; + + datashift_audio_engine.visual.cover_image_img.html(''); + datashift_audio_engine.visual.author_name.html(data.radio.author); + datashift_audio_engine.visual.track_name.html(data.radio.track); + + console.log('update radio metadata'); + }).fail(function(){ + // datashift_audio_engine.visual.cover_image.css('background-image', 'url("'+ test_audio_data_json.radio.cover_image +'")'); + datashift_audio_engine.visual.author_name.html('Not Found'); + datashift_audio_engine.visual.track_name.html('Not Found'); + + console.log('fail update radio metadata'); + }); + }, 1000); + } + + this.engine.play(); + }, + + pause: function() { + this.visual.pause.addClass('datashift-audio-hide'); + this.visual.play.removeClass('datashift-audio-hide'); + + if (this.is_radio == false) { + this.audio_data.autoplay = false; + this.save_current_state(); + } + clearInterval(this.timer); + + this.engine.pause(); + }, + + previous: function(){ + var new_track = this.audio_data.track - 1; + var track = this.playlist[new_track]; + + if (track != null) { + this.audio_data.track = new_track; + this.audio_data.position = 0; + this.settings.autoplay = true; + + this.render_wave_from_audio_file(); + this.save_current_state(); + } else { + if (this.audio_data.page > 1) + this.new_page('playlist/:id.new_page', false); + } + }, + + next: function(){ + var new_track = this.audio_data.track + 1; + var track = this.playlist[new_track]; + + if (track != null) { + this.audio_data.track = new_track; + this.audio_data.position = 0; + this.settings.autoplay = true; + + this.render_wave_from_audio_file(); + this.save_current_state(); + } else { + if (this.audio_data.page < this.audio_data.total_pages) + this.new_page('playlist/:id.new_page', true) + } + }, + + // url = 'playlist/:id.new_page' + new_page: function(url, fromBeginning){ + if (fromBeginning === undefined) fromBeginning = true; + $.get(url).done(function(pure_data){ + console.log('render new page and select new track'); + + var data = pure_data; + + datashift_audio_engine.playlist = data.tracks; + datashift_audio_engine.page = parseInt(data.page); + + datashift_audio_engine.visual.playlist.html(''); + + datashift_audio_engine.visual.pages.children('li').removeClass('datashift-audio-active'); + var visual_page = $('#page-' + data.page); + visual_page.addClass('datashift-audio-active'); + + datashift_audio_engine.playlist.forEach(function(track, index) { + var duration = '
    ' + formatTime(track.duration) + '
    '; + var full_name = '
    ' + track.author + " - " + track.name + '
    '; + + var track_set = duration + full_name; + datashift_audio_engine.visual.playlist.append('
  • ' + track_set + '
  • ') + }); + + datashift_audio_engine.visual.playlist.children('li').on('click', function(){ + datashift_audio_engine.audio_data.track = parseInt(this.id.split('-')[1]); + datashift_audio_engine.settings.autoplay = true; + datashift_audio_engine.render_wave_from_audio_file() + }); + + if (fromBeginning == true){ + datashift_audio_engine.audio_data.track = -1; + datashift_audio_engine.next(); + } else { + datashift_audio_engine.audio_data.track = datashift_audio_engine.playlist.length; + datashift_audio_engine.previous(); + } + }).fail(function(){ + console.error('page not found'); + console.log('page: ' + datashift_audio_engine.audio_data.page) + }); + }, + + volume: function(value){ + if (isNaN(value)) value = 1; + + this.settings.volume = value; + + if (this.is_radio == true){ + this.engine.volume = value; + } else { + this.engine.setVolume(value); + window.localStorage.setItem('volume', value); + } + }, + + seek: function(position){ + this.engine.setCurrentTime(position); + this.audio_data.position = position; + this.save_current_state(); + }, + + // Save current state of a player and send it to the back-end to sync it + save_current_state: function(save_url){ + console.log('save_current_state - URL:'); + console.log(datashift_audio_engine.routes.save_url); + if ( save_url === undefined && (datashift_audio_engine.routes.save_url == null || datashift_audio_engine.routes.save_url === undefined) ) return; + + if ( datashift_audio_engine.state === undefined ) return; + + if ( save_url === undefined) save_url = datashift_audio_engine.routes.save_url; + + datashift_audio_engine.update_info(); + + datashift_audio_engine.visual.current_position.html(formatTime(datashift_audio_engine.audio_data.position)); + + var data = { + user_token: datashift_audio_engine.user_token, + client_token: datashift_audio_engine.client_token, + random: datashift_audio_engine.settings.random, + audio_data: datashift_audio_engine.audio_data, + } + + $.post(save_url, data ) + .done(function(){ + console.log('saved'); + }) + .fail(function(){ + console.log('fail to save'); + }); + } +}; + +function formatTime(time_in_seconds){ + var seconds = Math.floor(time_in_seconds); + var minutes = Math.floor(seconds / 60); + + minutes = (minutes >= 10) ? minutes : "0" + minutes; + + seconds = Math.floor(seconds % 60); + seconds = (seconds >= 10) ? seconds : "0" + seconds; + + return minutes + ":" + seconds; +} diff --git a/app/helpers/datashift_audio_engine/application_helper.rb b/app/helpers/datashift_audio_engine/application_helper.rb index bf7e03c..2d2f216 100644 --- a/app/helpers/datashift_audio_engine/application_helper.rb +++ b/app/helpers/datashift_audio_engine/application_helper.rb @@ -17,5 +17,9 @@ def datashift_audio_player_in_navbar(init_url: nil, load_url: nil) render partial: 'datashift_audio_engine/shared/player_in_navbar', locals: { init_url: init_url, load_url: load_url } end + def test + 'test' + end + end end diff --git a/datashift_audio_engine.gemspec b/datashift_audio_engine.gemspec index 8538657..9fdc8c6 100755 --- a/datashift_audio_engine.gemspec +++ b/datashift_audio_engine.gemspec @@ -17,6 +17,13 @@ Gem::Specification.new do |s| s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"] s.add_dependency "rails", "~> 5.2" + s.add_development_dependency "rspec" + s.add_development_dependency 'rubocop' + s.add_development_dependency 'factory_bot_rails', '~> 4.8', '>= 4.8.2' + + s.add_development_dependency "teaspoon-jasmine" + s.add_development_dependency "poltergeist" + s.add_development_dependency "coveralls" s.add_development_dependency "sqlite3" end diff --git a/lib/datashift_audio_engine/engine.rb b/lib/datashift_audio_engine/engine.rb index 6008988..f4f46a9 100755 --- a/lib/datashift_audio_engine/engine.rb +++ b/lib/datashift_audio_engine/engine.rb @@ -9,5 +9,13 @@ class Engine < ::Rails::Engine config.assets.paths << root.join("vendor", "assets", "javascripts") config.assets.precompile += %w[*.png] + + config.generators do |g| + g.test_framework :rspec, :fixture => false + g.fixture_replacement :factory_girl, :dir => 'spec/factories' + + g.assets false + g.helper false + end end end diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb new file mode 100644 index 0000000..e5e749b --- /dev/null +++ b/spec/helpers/application_helper_spec.rb @@ -0,0 +1,13 @@ +require 'rails_helper' + +RSpec.describe DatashiftAudioEngine::ApplicationHelper, :type => :helper do + + context "test" do + + it "test" do + expect(helper.test).to eq("test") + end + + end + +end \ No newline at end of file diff --git a/spec/javascripts/application_spec.js b/spec/javascripts/application_spec.js new file mode 100644 index 0000000..15a5db6 --- /dev/null +++ b/spec/javascripts/application_spec.js @@ -0,0 +1,89 @@ +//= require audio_engine + +describe("When the library in loaded", function() { + it("should have nullified basic variables", function() { + expect(jQuery).toBeDefined(); + expect(datashift_audio_engine).toBeDefined(); + }); + + it("should have nullified basic properties of datashift audio engine", function() { + expect(datashift_audio_engine.state).toBe(null); + expect(datashift_audio_engine.engine).toBe(null); + + expect(datashift_audio_engine.save_interval).toBe(1000); + expect(datashift_audio_engine.is_radio).toBe(false); + + expect(datashift_audio_engine.routes.init_url).toBe(null); + expect(datashift_audio_engine.routes.load_url).toBe(null); + expect(datashift_audio_engine.routes.save_url).toBe(null); + expect(datashift_audio_engine.routes.load_url).toBe(null); + + expect(datashift_audio_engine.settings.autoplay).toBe(false); + expect(datashift_audio_engine.settings.random).toBe(false); + expect(datashift_audio_engine.settings.repeat).toBe(null); + expect(datashift_audio_engine.settings.volume).toBe(1); + + expect(datashift_audio_engine.user_token).toBe(null); + expect(datashift_audio_engine.client_token).toBe(null); + + expect(datashift_audio_engine.playlist_id).toBe(0); + expect(datashift_audio_engine.timer).toBe(null); + }); + + it("should be avaliabled support function foratTime and work fine", function(){ + expect(formatTime).toBeDefined(); + + var time_in_seconds = 144; + var time_in_cute_form = '02:24'; + expect(formatTime(time_in_seconds)).toEqual(time_in_cute_form); + }); +}); + +describe("When the library is settings are OK", function(){ + // save current state + it('save current state', function(){ + //init + //load + //render + // datashift_audio_engine.save_current_state(); + }); + + // init + it('should be initialized by data that obtained through ajax request', function(){ + datashift_audio_engine.init('/init'); + expect(datashift_audio_engine.state).toBe('sent init request'); + }); + + it('should be inited without ajax request to server' ,function() { + var spy_on_init = spyOn(datashift_audio_engine, 'init'); + var spy_on_ajax_init = spyOn($, 'ajax'); + + datashift_audio_engine.init(); + + expect(spy_on_init).toHaveBeenCalled(); + expect(spy_on_ajax_init).not.toHaveBeenCalled() + }); + + // load + it('should load test data from list', function(){ + datashift_audio_engine.init(); + + all_elements = $('
    \ +
    \ +
    \ +
    '); + $(document.body).append(all_elements); + + datashift_audio_engine.load(); + expect(datashift_audio_engine.state).toBe('sent load request'); + }); + + // update info + it('update info', function(){ + datashift_audio_engine.init(); + var spy_on_update_info = spyOn(datashift_audio_engine, 'update_info'); + // datashift_audio_engine.load(); + datashift_audio_engine.update_info(); + expect(spy_on_update_info).toHaveBeenCalled(); + }); +}); \ No newline at end of file diff --git a/spec/javascripts/spec_helper.js b/spec/javascripts/spec_helper.js new file mode 100644 index 0000000..ef6c800 --- /dev/null +++ b/spec/javascripts/spec_helper.js @@ -0,0 +1,36 @@ +// Teaspoon includes some support files, but you can use anything from your own support path too. +// require support/jasmine-jquery-1.7.0 +// require support/jasmine-jquery-2.0.0 +// require support/jasmine-jquery-2.1.0 +// require support/sinon +// require support/your-support-file +// +// PhantomJS (Teaspoons default driver) doesn't have support for Function.prototype.bind, which has caused confusion. +// Use this polyfill to avoid the confusion. +//= require support/phantomjs-shims +// +// You can require your own javascript files here. By default this will include everything in application, however you +// may get better load performance if you require the specific files that are being used in the spec that tests them. +//= require jquery +//= require jquery_ujs +//= require application +// +// Deferring execution +// If you're using CommonJS, RequireJS or some other asynchronous library you can defer execution. Call +// Teaspoon.execute() after everything has been loaded. Simple example of a timeout: +// +// Teaspoon.defer = true +// setTimeout(Teaspoon.execute, 1000) +// +// Matching files +// By default Teaspoon will look for files that match _spec.{js,js.coffee,.coffee}. Add a filename_spec.js file in your +// spec path and it'll be included in the default suite automatically. If you want to customize suites, check out the +// configuration in teaspoon_env.rb +// +// Manifest +// If you'd rather require your spec files manually (to control order for instance) you can disable the suite matcher in +// the configuration and use this file as a manifest. +// +// For more information: http://github.com/modeset/teaspoon + + diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb new file mode 100644 index 0000000..956c8e9 --- /dev/null +++ b/spec/rails_helper.rb @@ -0,0 +1,63 @@ +# This file is copied to spec/ when you run 'rails generate rspec:install' +require 'spec_helper' +ENV['RAILS_ENV'] ||= 'test' +require File.expand_path('../../config/environment', __FILE__) +# Prevent database truncation if the environment is production +abort("The Rails environment is running in production mode!") if Rails.env.production? +require 'rspec/rails' +# Add additional requires below this line. Rails is not loaded until this point! + +# Requires supporting ruby files with custom matchers and macros, etc, in +# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are +# run as spec files by default. This means that files in spec/support that end +# in _spec.rb will both be required and run as specs, causing the specs to be +# run twice. It is recommended that you do not name files matching this glob to +# end with _spec.rb. You can configure this pattern with the --pattern +# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. +# +# The following line is provided for convenience purposes. It has the downside +# of increasing the boot-up time by auto-requiring all files in the support +# directory. Alternatively, in the individual `*_spec.rb` files, manually +# require only the support files necessary. +# +# Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f } + +# Checks for pending migrations and applies them before tests are run. +# If you are not using ActiveRecord, you can remove these lines. +begin + ActiveRecord::Migration.maintain_test_schema! +rescue ActiveRecord::PendingMigrationError => e + puts e.to_s.strip + exit 1 +end +RSpec.configure do |config| + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures + config.fixture_path = "#{::Rails.root}/spec/fixtures" + + # If you're not using ActiveRecord, or you'd prefer not to run each of your + # examples within a transaction, remove the following line or assign false + # instead of true. + config.use_transactional_fixtures = true + config.infer_base_class_for_anonymous_controllers = false + config.order = :random + + # RSpec Rails can automatically mix in different behaviours to your tests + # based on their file location, for example enabling you to call `get` and + # `post` in specs under `spec/controllers`. + # + # You can disable this behaviour by removing the line below, and instead + # explicitly tag your specs with their type, e.g.: + # + # RSpec.describe UsersController, :type => :controller do + # # ... + # end + # + # The different available types are documented in the features, such as in + # https://relishapp.com/rspec/rspec-rails/docs + config.infer_spec_type_from_file_location! + + # Filter lines from Rails gems in backtraces. + config.filter_rails_from_backtrace! + # arbitrary gems may also be filtered via: + # config.filter_gems_from_backtrace("gem name") +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..ce33d66 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,96 @@ +# This file was generated by the `rails generate rspec:install` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + + # This option will default to `:apply_to_host_groups` in RSpec 4 (and will + # have no way to turn it off -- the option exists only for backwards + # compatibility in RSpec 3). It causes shared context metadata to be + # inherited by the metadata hash of host groups and examples, rather than + # triggering implicit auto-inclusion in groups with matching metadata. + config.shared_context_metadata_behavior = :apply_to_host_groups + +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +=begin + # This allows you to limit a spec run to individual examples or groups + # you care about by tagging them with `:focus` metadata. When nothing + # is tagged with `:focus`, all examples get run. RSpec also provides + # aliases for `it`, `describe`, and `context` that include `:focus` + # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + config.filter_run_when_matching :focus + + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + config.example_status_persistence_file_path = "spec/examples.txt" + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ + # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode + config.disable_monkey_patching! + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = "doc" + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed +=end +end diff --git a/spec/teaspoon_env.rb b/spec/teaspoon_env.rb new file mode 100644 index 0000000..1fc5ab9 --- /dev/null +++ b/spec/teaspoon_env.rb @@ -0,0 +1,186 @@ +Teaspoon.configure do |config| + # Determines where the Teaspoon routes will be mounted. Changing this to "/jasmine" would allow you to browse to + # `http://localhost:3000/jasmine` to run your tests. + config.mount_at = "/teaspoon" + + # Specifies the root where Teaspoon will look for files. If you're testing an engine using a dummy application it can + # be useful to set this to your engines root (e.g. `Teaspoon::Engine.root`). + # Note: Defaults to `Rails.root` if nil. + config.root = '/home/user/projects/datashift_audio_engine/' + + # Paths that will be appended to the Rails assets paths + # Note: Relative to `config.root`. + config.asset_paths = ["spec/javascripts", "spec/javascripts/stylesheets"] + + # Fixtures are rendered through a controller, which allows using HAML, RABL/JBuilder, etc. Files in these paths will + # be rendered as fixtures. + config.fixture_paths = ["spec/javascripts/fixtures"] + + # SUITES + # + # You can modify the default suite configuration and create new suites here. Suites are isolated from one another. + # + # When defining a suite you can provide a name and a block. If the name is left blank, :default is assumed. You can + # omit various directives and the ones defined in the default suite will be used. + # + # To run a specific suite + # - in the browser: http://localhost/teaspoon/[suite_name] + # - with the rake task: rake teaspoon suite=[suite_name] + # - with the cli: teaspoon --suite=[suite_name] + config.suite do |suite| + # Specify the framework you would like to use. This allows you to select versions, and will do some basic setup for + # you -- which you can override with the directives below. This should be specified first, as it can override other + # directives. + # Note: If no version is specified, the latest is assumed. + # + # Versions: 1.3.1, 2.0.3, 2.1.3, 2.2.0, 2.2.1, 2.3.4 + suite.use_framework :jasmine, "2.3.4" + + # Specify a file matcher as a regular expression and all matching files will be loaded when the suite is run. These + # files need to be within an asset path. You can add asset paths using the `config.asset_paths`. + suite.matcher = "{spec/javascripts,app/assets}/**/*_spec.{js,js.coffee,coffee}" + + # Load additional JS files, but requiring them in your spec helper is the preferred way to do this. + #suite.javascripts = [] + + # You can include your own stylesheets if you want to change how Teaspoon looks. + # Note: Spec related CSS can and should be loaded using fixtures. + #suite.stylesheets = ["teaspoon"] + + # This suites spec helper, which can require additional support files. This file is loaded before any of your test + # files are loaded. + suite.helper = "spec_helper" + + # Partial to be rendered in the head tag of the runner. You can use the provided ones or define your own by creating + # a `_boot.html.erb` in your fixtures path, and adjust the config to `"/boot"` for instance. + # + # Available: boot, boot_require_js + suite.boot_partial = "boot" + + # Partial to be rendered in the body tag of the runner. You can define your own to create a custom body structure. + suite.body_partial = "body" + + # Hooks allow you to use `Teaspoon.hook("fixtures")` before, after, or during your spec run. This will make a + # synchronous Ajax request to the server that will call all of the blocks you've defined for that hook name. + #suite.hook :fixtures, &proc{} + + # Determine whether specs loaded into the test harness should be embedded as individual script tags or concatenated + # into a single file. Similar to Rails' asset `debug: true` and `config.assets.debug = true` options. By default, + # Teaspoon expands all assets to provide more valuable stack traces that reference individual source files. + #suite.expand_assets = true + + # Non-.js file extensions Teaspoon should consider JavaScript files + #suite.js_extensions = [/(\.js)?.coffee/, /(\.js)?.es6/, ".es6.js"] + end + + # Example suite. Since we're just filtering to files already within the root test/javascripts, these files will also + # be run in the default suite -- but can be focused into a more specific suite. + #config.suite :targeted do |suite| + # suite.matcher = "spec/javascripts/targeted/*_spec.{js,js.coffee,coffee}" + #end + + # CONSOLE RUNNER SPECIFIC + # + # These configuration directives are applicable only when running via the rake task or command line interface. These + # directives can be overridden using the command line interface arguments or with ENV variables when using the rake + # task. + # + # Command Line Interface: + # teaspoon --driver=phantomjs --server-port=31337 --fail-fast=true --format=junit --suite=my_suite /spec/file_spec.js + # + # Rake: + # teaspoon DRIVER=phantomjs SERVER_PORT=31337 FAIL_FAST=true FORMATTERS=junit suite=my_suite + + # Specify which headless driver to use. Supports PhantomJS, Selenium Webdriver and BrowserStack Webdriver. + # + # Available: :phantomjs, :selenium, :browserstack, :capybara_webkit + # PhantomJS: https://github.com/modeset/teaspoon/wiki/Using-PhantomJS + # Selenium Webdriver: https://github.com/modeset/teaspoon/wiki/Using-Selenium-WebDriver + # BrowserStack Webdriver: https://github.com/modeset/teaspoon/wiki/Using-BrowserStack-WebDriver + # Capybara Webkit: https://github.com/modeset/teaspoon/wiki/Using-Capybara-Webkit + config.driver = :phantomjs + + # Specify additional options for the driver. + # + # PhantomJS: https://github.com/modeset/teaspoon/wiki/Using-PhantomJS + # Selenium Webdriver: https://github.com/modeset/teaspoon/wiki/Using-Selenium-WebDriver + # BrowserStack Webdriver: https://github.com/modeset/teaspoon/wiki/Using-BrowserStack-WebDriver + # Capybara Webkit: https://github.com/modeset/teaspoon/wiki/Using-Capybara-Webkit + #config.driver_options = nil + + # Specify the timeout for the driver. Specs are expected to complete within this time frame or the run will be + # considered a failure. This is to avoid issues that can arise where tests stall. + #config.driver_timeout = 180 + + # Specify a server to use with Rack (e.g. thin, mongrel). If nil is provided Rack::Server is used. + #config.server = nil + + # Specify a host to run on a specific host, otherwise Teaspoon will use 127.0.0.1. + #config.server_host = nil + + # Specify a port to run on a specific port, otherwise Teaspoon will use a random available port. + config.server_port = 31337 + + # Timeout for starting the server in seconds. If your server is slow to start you may have to bump this, or you may + # want to lower this if you know it shouldn't take long to start. + #config.server_timeout = 20 + + # Force Teaspoon to fail immediately after a failing suite. Can be useful to make Teaspoon fail early if you have + # several suites, but in environments like CI this may not be desirable. + #config.fail_fast = true + + # Specify the formatters to use when outputting the results. + # Note: Output files can be specified by using `"junit>/path/to/output.xml"`. + # + # Available: :dot, :clean, :documentation, :json, :junit, :pride, :rspec_html, :snowday, :swayze_or_oprah, :tap, :tap_y, :teamcity + #config.formatters = [:dot] + + # Specify if you want color output from the formatters. + config.color = true + + # Teaspoon pipes all console[log/debug/error] to $stdout. This is useful to catch places where you've forgotten to + # remove them, but in verbose applications this may not be desirable. + #config.suppress_log = false + + # COVERAGE REPORTS / THRESHOLD ASSERTIONS + # + # Coverage reports requires Istanbul (https://github.com/gotwarlost/istanbul) to add instrumentation to your code and + # display coverage statistics. + # + # Coverage configurations are similar to suites. You can define several, and use different ones under different + # conditions. + # + # To run with a specific coverage configuration + # - with the rake task: rake teaspoon USE_COVERAGE=[coverage_name] + # - with the cli: teaspoon --coverage=[coverage_name] + + # Specify that you always want a coverage configuration to be used. Otherwise, specify that you want coverage + # on the CLI. + # Set this to "true" or the name of your coverage config. + #config.use_coverage = nil + + # You can have multiple coverage configs by passing a name to config.coverage. + # e.g. config.coverage :ci do |coverage| + # The default coverage config name is :default. + config.coverage do |coverage| + # Which coverage reports Istanbul should generate. Correlates directly to what Istanbul supports. + # + # Available: text-summary, text, html, lcov, lcovonly, cobertura, teamcity + #coverage.reports = ["text-summary", "html"] + + # The path that the coverage should be written to - when there's an artifact to write to disk. + # Note: Relative to `config.root`. + #coverage.output_path = "coverage" + + # Assets to be ignored when generating coverage reports. Accepts an array of filenames or regular expressions. The + # default excludes assets from vendor, gems and support libraries. + #coverage.ignore = [%r{/lib/ruby/gems/}, %r{/vendor/assets/}, %r{/support/}, %r{/(.+)_helper.}] + + # Various thresholds requirements can be defined, and those thresholds will be checked at the end of a run. If any + # aren't met the run will fail with a message. Thresholds can be defined as a percentage (0-100), or nil. + #coverage.statements = nil + #coverage.functions = nil + #coverage.branches = nil + #coverage.lines = nil + end +end diff --git a/test/integration/navigation_test.rb b/test/integration/navigation_test.rb index 29e59d8..f7cd1b7 100755 --- a/test/integration/navigation_test.rb +++ b/test/integration/navigation_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class NavigationTest < ActionDispatch::IntegrationTest - # test "the truth" do - # assert true - # end + test "the truth" do + assert true + end end