Skip to content

Commit

Permalink
Merge pull request #20 from n-rodriguez/feat_add_options
Browse files Browse the repository at this point in the history
Add an optional hash to not include <script> tag
  • Loading branch information
simonoff committed Sep 7, 2015
2 parents b620fdf + 369cb05 commit f24670a
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.swp
**/*.swp
**/*.log
*.gem
Gemfile.lock
.bundle
Expand Down
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
rvm:
- 2.1.2
- 2.1.7
- 2.2.1
- 2.2.2
- 2.2.3
- rbx-2
bundler_args: --without development
before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
sudo: false
20 changes: 12 additions & 8 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
source 'http://rubygems.org'
gemspec

gem 'rake'
gem 'faye-redis'
gem 'guard'
gem 'guard-coffeescript'
gem 'jasmine', '>= 2.0.0'
gem 'rspec', '>= 3.0.0'
gem 'rspec-mocks', '>= 3.0.0'
gem 'webmock'
gem 'coveralls', require: false

group :development, :test do
gem 'rake'
gem 'guard'
gem 'guard-coffeescript'
gem 'jasmine', '>= 2.0.0'
gem 'rspec', '>= 3.0.0'
gem 'rspec-mocks', '>= 3.0.0'
gem 'webmock'
gem 'coveralls', require: false
gem 'rails'
end
12 changes: 12 additions & 0 deletions danthes.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,17 @@ Gem::Specification.new do |s|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
s.require_paths = ['lib']
s.add_dependency 'faye', '>= 1.0.1'
s.add_dependency 'faye-redis'
s.add_dependency 'yajl-ruby', '~> 1.2.0'

s.add_development_dependency 'rake'
s.add_development_dependency 'guard'
s.add_development_dependency 'guard-coffeescript'
s.add_development_dependency 'jasmine', '>= 2.0.0'
s.add_development_dependency 'rspec', '>= 3.0.0'
s.add_development_dependency 'rspec-mocks', '>= 3.0.0'
s.add_development_dependency 'webmock'
s.add_development_dependency 'coveralls'
s.add_development_dependency 'therubyracer'
s.add_development_dependency 'rails'
end
8 changes: 4 additions & 4 deletions lib/danthes/view_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ def publish_to(channel, data = nil, &block)
# Subscribe the client to the given channel. This generates
# some JavaScript calling Danthes.sign with the subscription
# options.
def subscribe_to(channel)
def subscribe_to(channel, opts = {})
js_tag = opts.delete(:include_js_tag){ true }
subscription = Danthes.subscription(channel: channel)
content_tag 'script', type: 'text/javascript' do
raw("if (typeof Danthes != 'undefined') { Danthes.sign(#{subscription.to_json}) }")
end
content = raw("if (typeof Danthes != 'undefined') { Danthes.sign(#{subscription.to_json}) }")
js_tag ? content_tag('script', content, type: 'text/javascript') : content
end
end
end
26 changes: 26 additions & 0 deletions spec/danthes/view_helpers_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'spec_helper'
require 'danthes/view_helpers'

module Danthes
describe ViewHelpers do

let(:klass) do
Class.new do
include ActionView::Helpers::TagHelper
include ActionView::Context
include ViewHelpers
end
end

describe '#subscribe_to' do
it "generates javascript tag by default" do
expect(klass.new.subscribe_to('hello')).to match /\A<script.*<\/script>\z/
end

it "removes javascript tag when *include_js_tag* is set to false" do
expect(klass.new.subscribe_to('hello', include_js_tag: false)).to match /\Aif \(typeof Danthes \!= 'undefined'\) { Danthes.sign\(.*\) }\z/
end
end

end
end
18 changes: 18 additions & 0 deletions spec/fake_app/rails_app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ENV['RAILS_ENV'] ||= 'test'

require 'action_controller/railtie'
require 'danthes'

module RailsApp
class Application < Rails::Application
config.active_support.deprecation = :log
config.cache_classes = true
config.eager_load = false
config.root = __dir__
config.secret_token = 'x'*100
config.session_store :cookie_store, key: '_myapp_session'
end
end

Rails.backtrace_cleaner.remove_silencers!
RailsApp::Application.initialize!
9 changes: 9 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'bundler/setup'
require 'simplecov'
require 'coveralls'

SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter
Expand All @@ -16,5 +17,13 @@
require 'faye'
require 'faye/redis'
require 'webmock/rspec'

begin
require 'rails'
rescue LoadError
else
require 'fake_app/rails_app'
end

RSpec.configure do |_config|
end

0 comments on commit f24670a

Please sign in to comment.