diff --git a/Gemfile b/Gemfile index e0c464835..7668fbb52 100644 --- a/Gemfile +++ b/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' diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 000000000..90bd71fa2 --- /dev/null +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/app/helpers/error_messages_helper.rb b/app/helpers/error_messages_helper.rb new file mode 100644 index 000000000..925757305 --- /dev/null +++ b/app/helpers/error_messages_helper.rb @@ -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) diff --git a/app/helpers/layout_helper.rb b/app/helpers/layout_helper.rb new file mode 100644 index 000000000..7c5ce5006 --- /dev/null +++ b/app/helpers/layout_helper.rb @@ -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 diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb new file mode 100644 index 000000000..2310a240d --- /dev/null +++ b/app/helpers/users_helper.rb @@ -0,0 +1,2 @@ +module UsersHelper +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 000000000..892d50953 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,5 @@ +class User + include Mongoid::Document + + field :password +end diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml new file mode 100644 index 000000000..3dccf3d79 --- /dev/null +++ b/app/views/layouts/application.html.haml @@ -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 diff --git a/app/views/users/index.html.haml b/app/views/users/index.html.haml new file mode 100644 index 000000000..7d8171db7 --- /dev/null +++ b/app/views/users/index.html.haml @@ -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 diff --git a/app/views/users/new.html.haml b/app/views/users/new.html.haml new file mode 100644 index 000000000..84b971b6e --- /dev/null +++ b/app/views/users/new.html.haml @@ -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 diff --git a/config/mongoid.yml b/config/mongoid.yml index e2b0a39b6..40d23b0ce 100644 --- a/config/mongoid.yml +++ b/config/mongoid.yml @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 7404eb7ec..10ac7a63f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@ Diaspora::Application.routes.draw do |map| + resources :users + # The priority is based upon order of creation: # first created -> highest priority. diff --git a/lib/tasks/rspec.rake b/lib/tasks/rspec.rake index 67a2bcf87..14ca3ea47 100644 --- a/lib/tasks/rspec.rake +++ b/lib/tasks/rspec.rake @@ -38,11 +38,11 @@ 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| - t.pattern = "./spec/#{sub}/**/*_spec.rb" + t.pattern = "./spec/#{sub}/**/*_spec.rb " end end diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css new file mode 100644 index 000000000..5853d7241 --- /dev/null +++ b/public/stylesheets/application.css @@ -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; } diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass new file mode 100644 index 000000000..fa0ec0a64 --- /dev/null +++ b/public/stylesheets/sass/application.sass @@ -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 diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb new file mode 100644 index 000000000..64194bd88 --- /dev/null +++ b/spec/controllers/users_controller_spec.rb @@ -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 diff --git a/spec/user_spec.rb b/spec/user_spec.rb index 4521b8107..b7b575682 100644 --- a/spec/user_spec.rb +++ b/spec/user_spec.rb @@ -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