Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- registration template and action Signed-off-by: Balint Erdi <balint.erdi@gmail.com>
- Loading branch information
1 parent
4733c28
commit 232b53d
Showing
10 changed files
with
181 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require "ruby-debug" | ||
|
||
module Sinatra::MyHelpers | ||
|
||
def self.included(base) | ||
base.class_eval do | ||
include Flash | ||
end | ||
end | ||
|
||
module Flash | ||
# NOTE: Yes, at one point I peaked at how Rails | ||
# implements the flash and now I pretty much | ||
# try to implement a rudimentary version of it. | ||
class FlashHash < Hash | ||
def initialize | ||
@keys_to_keep = [] | ||
end | ||
|
||
def []=(key, value) | ||
keep(key) | ||
super | ||
end | ||
|
||
def keep(key) | ||
# that key should be kept for the next action to be shown | ||
@keys_to_keep << key | ||
end | ||
|
||
def reset | ||
self.keys.each { |k| delete(k) unless @keys_to_keep.include?(k) } | ||
# flash messages are only preserved for the next action | ||
@keys_to_keep = [] | ||
end | ||
|
||
end | ||
|
||
def flash | ||
if !defined?(@_flash) | ||
@_flash = (session["flash"] ||= FlashHash.new) | ||
end | ||
@_flash | ||
end | ||
|
||
def reset_flash | ||
@_flash.reset if defined?(@_flash) | ||
session.delete("flash") | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require File.dirname(__FILE__) + '/spec_helper' | ||
|
||
describe "Sinatra::MyHelpers" do | ||
before do | ||
class Sinatra::Application | ||
include Sinatra::MyHelpers | ||
end | ||
end | ||
|
||
describe "param hash handling" do | ||
describe "with no nested attributes" do | ||
before do | ||
# @params = { "status" => "all right" } | ||
# @new_params = convert_with_nested_attributes(@params) | ||
end | ||
|
||
it "should not change the params hash" do | ||
mock_app { | ||
get '/' do | ||
@params = { "status" => "all right" } | ||
@new_params = convert_with_nested_attributes(@params) | ||
end | ||
} | ||
get '/' | ||
@params["status"].should == @new_params["status"] | ||
end | ||
end | ||
|
||
it "makes a hash of value params if they have a []" do | ||
pending | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/ %p= "Welcome, #{current_group.name}" | ||
%p Welcome |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
%div= current_group.inspect | ||
%div= current_group |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
%form{ :name => "register", :action => "/register", :method => "post" } | ||
%ul{ :class => "fieldset" } | ||
%li{ :class => "field" } | ||
%label{ :for => "name" } Name | ||
%input{ :type => "text", :id => "name", :name => "group[name]" } | ||
%li{ :class => "field" } | ||
%label{ :for => "login" } Login | ||
%input{ :type => "text", :id => "login", :name => "group[login]" } | ||
%li{ :class => "field" } | ||
%label{ :for => "password" } Password | ||
%input{ :type => "password", :id => "password", :name => "group[password]" } | ||
%li{ :class => "field" } | ||
%label{ :for => "re-password" } Re-password | ||
%input{ :type => "password", :id => "re-password", :name => "group[re_password]" } | ||
|
||
%li{ :class => "field" } | ||
%input{ :type => "submit", :value => "Register"} |