added nifty templates, and started a user model. session model is next
This commit is contained in:
parent
e1a0c2f365
commit
e068707158
16 changed files with 300 additions and 7 deletions
5
Gemfile
5
Gemfile
|
|
@ -9,7 +9,8 @@ gem 'rails', '3.0.0.beta4'
|
|||
gem "mongoid", :git => "http://github.com/durran/mongoid.git"
|
||||
gem "bson_ext", "1.0.1"
|
||||
|
||||
|
||||
gem "nifty-generators"
|
||||
gem "haml"
|
||||
# Use unicorn as the web server
|
||||
# gem 'unicorn'
|
||||
|
||||
|
|
@ -18,7 +19,7 @@ gem "bson_ext", "1.0.1"
|
|||
|
||||
# To use debugger
|
||||
gem 'ruby-debug'
|
||||
|
||||
gem "mocha"
|
||||
# Bundle the extra gems:
|
||||
# gem 'bj'
|
||||
# gem 'nokogiri', '1.4.1'
|
||||
|
|
|
|||
19
app/controllers/users_controller.rb
Normal file
19
app/controllers/users_controller.rb
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
class UsersController < ApplicationController
|
||||
def index
|
||||
@users = User.all
|
||||
end
|
||||
|
||||
def new
|
||||
@user = User.new
|
||||
end
|
||||
|
||||
def create
|
||||
@user = User.new(params[:user])
|
||||
if @user.save
|
||||
flash[:notice] = "Successfully created user."
|
||||
redirect_to users_url
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
end
|
||||
end
|
||||
23
app/helpers/error_messages_helper.rb
Normal file
23
app/helpers/error_messages_helper.rb
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
module ErrorMessagesHelper
|
||||
# Render error messages for the given objects. The :message and :header_message options are allowed.
|
||||
def error_messages_for(*objects)
|
||||
options = objects.extract_options!
|
||||
options[:header_message] ||= "Invalid Fields"
|
||||
options[:message] ||= "Correct the following errors and try again."
|
||||
messages = objects.compact.map { |o| o.errors.full_messages }.flatten
|
||||
unless messages.empty?
|
||||
content_tag(:div, :class => "error_messages") do
|
||||
list_items = messages.map { |msg| content_tag(:li, msg) }
|
||||
content_tag(:h2, options[:header_message]) + content_tag(:p, options[:message]) + content_tag(:ul, list_items.join.html_safe)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module FormBuilderAdditions
|
||||
def error_messages(options = {})
|
||||
@template.error_messages_for(@object, options)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
ActionView::Helpers::FormBuilder.send(:include, ErrorMessagesHelper::FormBuilderAdditions)
|
||||
22
app/helpers/layout_helper.rb
Normal file
22
app/helpers/layout_helper.rb
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# These helper methods can be called in your template to set variables to be used in the layout
|
||||
# This module should be included in all views globally,
|
||||
# to do so you may need to add this line to your ApplicationController
|
||||
# helper :layout
|
||||
module LayoutHelper
|
||||
def title(page_title, show_title = true)
|
||||
content_for(:title) { page_title.to_s }
|
||||
@show_title = show_title
|
||||
end
|
||||
|
||||
def show_title?
|
||||
@show_title
|
||||
end
|
||||
|
||||
def stylesheet(*args)
|
||||
content_for(:head) { stylesheet_link_tag(*args) }
|
||||
end
|
||||
|
||||
def javascript(*args)
|
||||
content_for(:head) { javascript_include_tag(*args) }
|
||||
end
|
||||
end
|
||||
2
app/helpers/users_helper.rb
Normal file
2
app/helpers/users_helper.rb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
module UsersHelper
|
||||
end
|
||||
5
app/models/user.rb
Normal file
5
app/models/user.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class User
|
||||
include Mongoid::Document
|
||||
|
||||
field :password
|
||||
end
|
||||
21
app/views/layouts/application.html.haml
Normal file
21
app/views/layouts/application.html.haml
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
!!!
|
||||
%html
|
||||
|
||||
%head
|
||||
%title
|
||||
= yield(:title) || "Untitled"
|
||||
%meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/
|
||||
= stylesheet_link_tag "application"
|
||||
= javascript_include_tag :defaults
|
||||
= csrf_meta_tag
|
||||
= yield(:head)
|
||||
|
||||
%body
|
||||
#container
|
||||
- flash.each do |name, msg|
|
||||
= content_tag :div, msg, :id => "flash_#{name}"
|
||||
|
||||
- if show_title?
|
||||
%h1= yield(:title)
|
||||
|
||||
= yield
|
||||
10
app/views/users/index.html.haml
Normal file
10
app/views/users/index.html.haml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
- title "Users"
|
||||
|
||||
%table
|
||||
%tr
|
||||
%th Password
|
||||
- for user in @users
|
||||
%tr
|
||||
%td= user.password
|
||||
|
||||
%p= link_to "New User", new_user_path
|
||||
13
app/views/users/new.html.haml
Normal file
13
app/views/users/new.html.haml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
- title "New User"
|
||||
|
||||
= form_for @user do |f|
|
||||
= f.error_messages
|
||||
%p
|
||||
= f.label :password
|
||||
%br
|
||||
= f.password_field :password
|
||||
%p
|
||||
= f.submit
|
||||
|
||||
|
||||
%p= link_to "Back to List", users_path
|
||||
|
|
@ -5,6 +5,13 @@ defaults: &defaults
|
|||
# port: 27018
|
||||
# - host: slave2.local
|
||||
# port: 27019
|
||||
allow_dynamic_fields: false
|
||||
parameterize_keys: true
|
||||
persist_in_safe_mode: true
|
||||
raise_not_found_error: true
|
||||
reconnect_time: 3
|
||||
use_object_ids: false
|
||||
|
||||
|
||||
development:
|
||||
<<: *defaults
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
Diaspora::Application.routes.draw do |map|
|
||||
resources :users
|
||||
|
||||
# The priority is based upon order of creation:
|
||||
# first created -> highest priority.
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ task :stats => "spec:statsetup"
|
|||
desc "Run all specs in spec directory (excluding plugin specs)"
|
||||
RSpec::Core::RakeTask.new(:spec => spec_prereq)
|
||||
|
||||
namespace :spec do
|
||||
namespace :"spec --color" do
|
||||
[:requests, :models, :controllers, :views, :helpers, :mailers, :lib].each do |sub|
|
||||
desc "Run the code examples in spec/#{sub}"
|
||||
RSpec::Core::RakeTask.new(sub => spec_prereq) do |t|
|
||||
|
|
|
|||
61
public/stylesheets/application.css
Normal file
61
public/stylesheets/application.css
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
body {
|
||||
background-color: #4b7399;
|
||||
font-family: Verdana, Helvetica, Arial;
|
||||
font-size: 14px; }
|
||||
|
||||
a {
|
||||
color: blue; }
|
||||
a img {
|
||||
border: none; }
|
||||
|
||||
.clear {
|
||||
clear: both;
|
||||
height: 0;
|
||||
overflow: hidden; }
|
||||
|
||||
#container {
|
||||
width: 75%;
|
||||
margin: 0 auto;
|
||||
background: white;
|
||||
padding: 20px 40px;
|
||||
border: solid 1px black;
|
||||
margin-top: 20px; }
|
||||
|
||||
#flash_notice,
|
||||
#flash_error,
|
||||
#flash_alert {
|
||||
padding: 5px 8px;
|
||||
margin: 10px 0; }
|
||||
|
||||
#flash_notice {
|
||||
background-color: #ccffcc;
|
||||
border: solid 1px #66cc66; }
|
||||
|
||||
#flash_error,
|
||||
#flash_alert {
|
||||
background-color: #ffcccc;
|
||||
border: solid 1px #cc6666; }
|
||||
|
||||
.fieldWithErrors {
|
||||
display: inline; }
|
||||
|
||||
.error_messages {
|
||||
width: 400px;
|
||||
border: 2px solid #cf0000;
|
||||
padding: 0;
|
||||
padding-bottom: 12px;
|
||||
margin-bottom: 20px;
|
||||
background-color: #f0f0f0;
|
||||
font-size: 12px; }
|
||||
.error_messages h2 {
|
||||
text-align: left;
|
||||
padding: 5px 5px 5px 15px;
|
||||
margin: 0;
|
||||
font-weight: bold;
|
||||
font-size: 12px;
|
||||
background-color: #cc0000;
|
||||
color: white; }
|
||||
.error_messages p {
|
||||
margin: 8px 10px; }
|
||||
.error_messages ul {
|
||||
margin: 0; }
|
||||
66
public/stylesheets/sass/application.sass
Normal file
66
public/stylesheets/sass/application.sass
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
!primary_color = #4B7399
|
||||
|
||||
body
|
||||
:background-color = !primary_color
|
||||
:font
|
||||
:family Verdana, Helvetica, Arial
|
||||
:size 14px
|
||||
|
||||
a
|
||||
:color #0000FF
|
||||
img
|
||||
:border none
|
||||
|
||||
.clear
|
||||
:clear both
|
||||
:height 0
|
||||
:overflow hidden
|
||||
|
||||
#container
|
||||
:width 75%
|
||||
:margin 0 auto
|
||||
:background #fff
|
||||
:padding 20px 40px
|
||||
:border solid 1px black
|
||||
:margin-top 20px
|
||||
|
||||
#flash_notice,
|
||||
#flash_error,
|
||||
#flash_alert
|
||||
:padding 5px 8px
|
||||
:margin 10px 0
|
||||
|
||||
#flash_notice
|
||||
:background-color #CFC
|
||||
:border solid 1px #6C6
|
||||
|
||||
#flash_error,
|
||||
#flash_alert
|
||||
:background-color #FCC
|
||||
:border solid 1px #C66
|
||||
|
||||
.fieldWithErrors
|
||||
:display inline
|
||||
|
||||
.error_messages
|
||||
:width 400px
|
||||
:border 2px solid #CF0000
|
||||
:padding 0
|
||||
:padding-bottom 12px
|
||||
:margin-bottom 20px
|
||||
:background-color #f0f0f0
|
||||
:font
|
||||
:size 12px
|
||||
h2
|
||||
:text-align left
|
||||
:padding 5px 5px 5px 15px
|
||||
:margin 0
|
||||
:font
|
||||
:weight bold
|
||||
:size 12px
|
||||
:background-color #c00
|
||||
:color #fff
|
||||
p
|
||||
:margin 8px 10px
|
||||
ul
|
||||
:margin 0
|
||||
28
spec/controllers/users_controller_spec.rb
Normal file
28
spec/controllers/users_controller_spec.rb
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
require File.dirname(__FILE__) + '/../spec_helper'
|
||||
|
||||
describe UsersController do
|
||||
fixtures :all
|
||||
render_views
|
||||
|
||||
it "index action should render index template" do
|
||||
get :index
|
||||
response.should render_template(:index)
|
||||
end
|
||||
|
||||
it "new action should render new template" do
|
||||
get :new
|
||||
response.should render_template(:new)
|
||||
end
|
||||
|
||||
it "create action should render new template when model is invalid" do
|
||||
User.any_instance.stubs(:valid?).returns(false)
|
||||
post :create
|
||||
response.should render_template(:new)
|
||||
end
|
||||
|
||||
it "create action should redirect when model is valid" do
|
||||
User.any_instance.stubs(:valid?).returns(true)
|
||||
post :create
|
||||
response.should redirect_to(users_url)
|
||||
end
|
||||
end
|
||||
|
|
@ -1,7 +1,20 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'user login' do
|
||||
it 'should be able for a user to create a new user' do
|
||||
puts "foo"
|
||||
describe 'a user should be able to log into his seed' do
|
||||
before do
|
||||
User.all.each {|x| x.delete}
|
||||
end
|
||||
|
||||
it 'should should have a name and password' do
|
||||
User.count.should == 0
|
||||
billy = User.create
|
||||
User.count.should == 1
|
||||
end
|
||||
|
||||
it 'should be able to log into a page with a password' do
|
||||
billy = User.create(:password => "foobar")
|
||||
billy.password.should == "foobar"
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue