Skip to content

Commit

Permalink
Add DOMReference & BlackBoxNode server-side specs
Browse files Browse the repository at this point in the history
  • Loading branch information
jgaskins committed Apr 20, 2016
1 parent 8f3f945 commit 25049ed
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 8 deletions.
7 changes: 7 additions & 0 deletions lib/clearwater/black_box_node.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Clearwater
module BlackBoxNode
def to_s
node.to_s
end
end
end
13 changes: 5 additions & 8 deletions lib/clearwater/component.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
require 'clearwater/component/html_tags'
require 'clearwater/dom_reference'

module Clearwater
module Component
extend self

attr_accessor :outlet
attr_accessor :router

Expand Down Expand Up @@ -36,10 +39,6 @@ def params
router.params_for_path(router.current_path)
end

def param(key)
params[key]
end

def call &block
end

Expand Down Expand Up @@ -83,10 +82,8 @@ def sanitize_attributes attributes
}.join(';')
end

attributes.each do |key, handler|
if key[0, 2] == 'on'
attributes.delete key
end
attributes.reject! do |key, handler|
key[0, 2] == 'on' || DOMReference === handler
end

attributes
Expand Down
7 changes: 7 additions & 0 deletions lib/clearwater/dom_reference.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Clearwater
class DOMReference
def to_s
''.freeze
end
end
end
21 changes: 21 additions & 0 deletions spec/clearwater/black_box_node_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'spec_helper'
require 'clearwater/black_box_node'
require 'clearwater/component'

module Clearwater
describe BlackBoxNode do
let(:object) {
Class.new do
include Clearwater::BlackBoxNode

def node
Clearwater::Component.div({ id: 'foo' }, 'hi')
end
end.new
}

it 'just renders the specified node' do
expect(object.to_s).to eq '<div id="foo">hi</div>'
end
end
end
9 changes: 9 additions & 0 deletions spec/clearwater/component_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'spec_helper'
require_relative '../../lib/clearwater/component'

module Clearwater
Expand All @@ -23,6 +24,14 @@ module Clearwater
expect(html).to eq('<div style="font-size:24px;padding:3px">Hello world!</div>')
end

it 'removes DOMReference attributes' do
html = component.div({
ref: DOMReference.new,
}, 'Hello World!').to_s

expect(html).to eq('<div>Hello World!</div>')
end

describe 'content sanitization' do
it 'sanitizes content strings, but not elements' do
html = component.div(component.p('<em>hi</em>')).to_s
Expand Down
11 changes: 11 additions & 0 deletions spec/clearwater/dom_reference_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'clearwater/dom_reference'

module Clearwater
describe DOMReference do
let(:ref) { DOMReference.new }

it 'sanitizes to an empty string' do
expect(ref.to_s).to eq ''
end
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$:.unshift 'shared'

0 comments on commit 25049ed

Please sign in to comment.