1
0
Fork 0
mirror of https://github.com/kbparagua/paloma synced 2023-03-27 23:21:17 -04:00

Initial spec for Rails

This commit is contained in:
kbparagua 2013-10-12 19:20:23 +08:00
parent eb4a34210a
commit 56c62047ac
19 changed files with 167 additions and 45 deletions

View file

@ -24,23 +24,20 @@ module Paloma
# Use on controllers to pass variables to Paloma controller.
#
def js params = {}
@paloma_params = params
session[:paloma_requests].last[:params] = params
end
#
# Executed every time a controller action is executed.
#
# Keeps track of what Rails controller/action is executed
# and their corresponding Paloma parameters.
# Keeps track of what Rails controller/action is executed.
#
def track_paloma_request
puts 'Tracking Request'
resource = controller_path.split('/').map(&:titleize).join('.')
paloma_request = {:resource => resource,
:action => self.action_name,
:params => @paloma_params}
:action => self.action_name}
session[:paloma_requests] ||= []
session[:paloma_requests].push paloma_request

1
test_app/.rspec Normal file
View file

@ -0,0 +1 @@
--color

View file

@ -4,4 +4,8 @@
require File.expand_path('../config/application', __FILE__)
if ['development', 'test'].include?(Rails.env)
require 'rspec/core/rake_task'
end
TestApp::Application.load_tasks

View file

@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View file

@ -15,38 +15,64 @@
//= require paloma
//= require_tree .
// Will be manipulated by Paloma controllers.
window.called = [];
//
//
// Routes
//
//
var router = Paloma.router;
router.resource('RailsUser', {controller: 'User'});
router.redirect('RailsUser#revise', {to: 'User#edit'});
router.resource('Foo', {controller: 'MyFoo'});
router.redirect('Foo#new', {to: 'AnotherFoo#build'});
var User = Paloma.controller('User');
User.prototype.edit = function(){
alert('Going to edit User ' + this.params['id']);
//
//
// Controllers
//
//
var Main = Paloma.controller('Main');
Main.prototype.index = function(){
window.called.push('Main#index');
};
User.prototype.update = function(){
alert('Going to update User with name = ' + this.params['name']);
var MyFoo = Paloma.controller('MyFoo');
MyFoo.prototype.index = function(){
window.called.push('MyFoo#index');
};
Paloma.controller('Main').prototype.index = function(){
//console.log('main');
alert('main');
MyFoo.prototype.show = function(){
window.called.push('MyFoo#show');
window.parameter = this.params.parameter;
};
/*
Paloma.engine.requests.push({resource: 'RailsUser', action: 'revise', params: {id: 23}});
Paloma.engine.requests.push({resource: 'RailsUser', action: 'revise', params: {id: 99}});
Paloma.engine.requests.push({resource: 'User', action: 'update', params: {name: 'Shibalboy'}});
Paloma.engine.requests.push({resource: 'Article', action: 'new'});
Paloma.engine.start();
var AnotherFoo = Paloma.controller('AnotherFoo');
*/
AnotherFoo.prototype.build = function(){
window.called.push('AnotherFoo#build');
};
var Bar = Paloma.controller('Admin/Bar');
Bar.prototype.show = function(){
window.called.push('Admin/Bar#show');
};

View file

@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View file

@ -0,0 +1,4 @@
/*
Place all the styles related to the matching controller here.
They will automatically be included in application.css.
*/

View file

@ -0,0 +1,4 @@
/*
Place all the styles related to the matching controller here.
They will automatically be included in application.css.
*/

View file

@ -0,0 +1,2 @@
class Admin::BarController < ApplicationController
end

View file

@ -0,0 +1,12 @@
class FooController < ApplicationController
def index
redirect_to main_index_path
end
def show
js :parameter => 'Parameter From Paloma'
render :inline => '<h1>Foo#show</h1>', :layout => 'application'
end
end

View file

@ -1,6 +1,7 @@
class MainController < ApplicationController
def index
render :inline => 'Main#index', :layout => 'application'
end
end

View file

@ -0,0 +1,2 @@
module Admin::BarHelper
end

View file

@ -0,0 +1,2 @@
module FooHelper
end

View file

@ -3,4 +3,12 @@ TestApp::Application.routes.draw do
mount JasmineRails::Engine => "/specs" if defined?(JasmineRails)
root :to => 'main#index'
resources :main, :controller => 'Main'
resources :foo, :controller => 'Foo'
namespace :admin do
resources :bar, :controller => 'Bar'
end
end

View file

@ -1,5 +0,0 @@
require 'spec_helper'
describe MainController do
end

View file

@ -1,15 +0,0 @@
require 'spec_helper'
# Specs in this file have access to a helper object that includes
# the MainHelper. For example:
#
# describe MainHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
describe MainHelper do
pending "add some examples to (or delete) #{__FILE__}"
end

View file

@ -0,0 +1,43 @@
require 'spec_helper'
feature 'executing Paloma controller', :js => true do
describe 'after rendering' do
it 'executes the corresponding Paloma controller action' do
visit foo_path(1)
called = page.evaluate_script 'window.called'
expect(called).to include 'MyFoo#show'
end
context 'coming from a redirect' do
before { visit foo_index_path }
it 'executes first the Paloma action of the first Rails action' do
first = page.evaluate_script 'window.called[0]'
expect(first).to eq 'MyFoo#index'
end
it 'executes next the Paloma action of the last Rails action' do
last = page.evaluate_script 'window.called.pop()'
expect(last).to eq 'Main#index'
end
end
context 'when js params is passed' do
it 'passes the parameters to Paloma controller action' do
visit foo_path(1)
parameter = page.evaluate_script 'window.parameter'
expect(parameter).to eq 'Parameter From Paloma'
end
end
end
end

View file

@ -0,0 +1,32 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
RSpec.configure do |config|
config.include Capybara::DSL
# 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
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
# 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"
end