# coding: UTF-8 require_relative 'spec_helper' def javascript_tag(str, *args) "#{str}" end describe 'AngularJS::Rails::Cdn::ActionViewExtensions' do subject { Class.new.extend(AngularJS::Rails::Cdn::ActionViewExtensions) } describe 'angularjs_url' do context :google do it 'returns url with version without specific module name' do subject.angularjs_url(:google, 'angular', '1.0.7').should == '//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js' end end end describe :modules do it 'returns default modules list' do subject.send(:modules, nil).should == [:angular] end it 'returns extended modules list' do subject.send(:modules, [:resource, :cookies]).should == [:angular, :'angular-resource', :'angular-cookies'] end end describe :angularjs_include_tag do before do subject.should_receive(:javascript_include_tag).with(:angular).and_return('angular.js') end context 'offline mode' do context 'no additional modules' do it { subject.angularjs_include_tag(:google).should == 'angular.js' } it { subject.angularjs_include_tag(:google).should be_html_safe } it { subject.angularjs_include_tag(:google, version: '1.0.7').should == 'angular.js' } it { subject.angularjs_include_tag(:google, version: '1.0.7').should be_html_safe } end context 'with additional module' do before { subject.should_receive(:javascript_include_tag).with(:'angular-cookies').and_return('angular-cookies.js') } it { subject.angularjs_include_tag(:google, modules: [:cookies]).should == 'angular.jsangular-cookies.js' } it { subject.angularjs_include_tag(:google, modules: [:cookies]).should be_html_safe } it { subject.angularjs_include_tag(:google, version: '1.0.7', modules: [:cookies]).should == 'angular.jsangular-cookies.js' } it { subject.angularjs_include_tag(:google, version: '1.0.7', modules: [:cookies]).should be_html_safe } end end context 'CDN is enforced' do context 'no additional modules' do before do subject.should_receive(:javascript_include_tag).with('//ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js', force: true, version: '1.1.5').and_return('//angular.min.js') end it { subject.angularjs_include_tag(:google, force: true, version: '1.1.5').should == "//angular.min.jswindow.angular || document.write(unescape('%3Cs>angular.js%3C/s>'))" } it { subject.angularjs_include_tag(:google, force: true, version: '1.1.5').should be_html_safe } end context 'with additional module' do before do subject.should_receive(:javascript_include_tag).with('//ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js', force: true, version: '1.1.5', modules: [:cookies]).and_return('//angular.min.js') subject.should_receive(:javascript_include_tag).with(:'angular-cookies').and_return('angular-cookies.js') subject.should_receive(:javascript_include_tag).with('//ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular-cookies.min.js', force: true, version: '1.1.5', modules: [:cookies]).and_return('//angular-cookies.min.js') end it { subject.angularjs_include_tag(:google, force: true, version: '1.1.5', modules: [:cookies]).should == "//angular.min.js//angular-cookies.min.jswindow.angular || document.write(unescape('%3Cs>angular.js%3C/s>%3Cs>angular-cookies.js%3C/s>'))" } it { subject.angularjs_include_tag(:google, force: true, version: '1.1.5', modules: [:cookies]).should be_html_safe } end end end end