Skip to content

Instantly share code, notes, and snippets.

@cj

cj/auth_spec.rb Secret

Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cj/11a226a6df25c3a49e41 to your computer and use it in GitHub Desktop.
Save cj/11a226a6df25c3a49e41 to your computer and use it in GitHub Desktop.
require 'spec_helper'
require 'wedge/plugins/form'
require 'components/auth'
Document.trigger('wedge:loaded')
describe 'auth' do
context 'errors' do
if Wedge.server?
it 'to return wrong username or password' do
expect(Wedge[:auth].login_user({})[:errors]).to match /wrong username or password/i
end
else
puts Wedge.config.data.to_h
end
end
end
module Opal
def self.original_compile(source, options = {})
Compiler.new(source, options).original_compile
end
class Compiler
alias_method :original_compile, :compile
def compile
@result = original_compile
if defined? Wedge
logical_path = self.file
classes = Wedge.config.component_class
comp_class = classes["#{Wedge.config.app_dir}/#{logical_path}".gsub(/\//, '__')] || classes[logical_path.gsub(/\//, '__')]
if logical_path == 'wedge'
compiled_data = Base64.encode64 Wedge.config.client_data.to_json
# We need to merge in some data that is only set on the server.
# i.e. path, assets_key etc....
@result << <<-JS
$(document).on('wedge:loaded', function() {
#{Opal.original_compile("Wedge.config.data = HashObject.new(Wedge.config.data.to_h.merge JSON.parse(Base64.decode64('#{compiled_data}')))")}
});
JS
# load all global plugins into wedge
Wedge.config.plugins.each do |path|
@result << <<-JS
$(document).on('wedge:loaded', function() {
#{Builder.build(path).to_s}
});
JS
end
elsif comp_class
comp_class.config.on_compile.each { |blk| comp_class.instance_eval(&blk) }
comp_name = comp_class.config.name
compiled_data = Base64.encode64 comp_class.config.client_data.to_json
@result << <<-JS
$(document).on('wedge:loaded', function() {
#{Opal.original_compile("Wedge.config.component_class[:#{comp_name}].config.data = HashObject.new(Wedge.config.component_class[:#{comp_name}].config.data.to_h.merge JSON.parse(Base64.decode64('#{compiled_data}')))")}
});
JS
load_requires logical_path
end
end
@result
end
def load_requires path_name
if requires = Wedge.config.requires[path_name.gsub(/\//, '__')]
requires.each do |path|
next unless comp_class = Wedge.config.component_class[path]
comp_class.config.on_compile.each { |blk| comp_class.instance_eval(&blk) }
comp_name = comp_class.config.name
compiled_data = Base64.encode64 comp_class.config.client_data.to_json
load_requires path
@result << <<-JS
$(document).on('wedge:loaded', function() {
#{Opal.original_compile("Wedge.config.component_class[:#{comp_name}].config.data = HashObject.new(Wedge.config.component_class[:#{comp_name}].config.data.to_h.merge JSON.parse(Base64.decode64('#{compiled_data}')))")}
});
JS
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment