Skip to content
This repository has been archived by the owner on Jun 2, 2020. It is now read-only.

Commit

Permalink
Added Sign-Up for Admin Users
Browse files Browse the repository at this point in the history
Added tests modeled after MHs Tutorial. Also added routes and controller
actions, just for the admin user. Furthermore, changed the css somewhat.
  • Loading branch information
mamhoff committed Dec 2, 2013
1 parent 9bd4b2f commit 9e2bcd1
Show file tree
Hide file tree
Showing 17 changed files with 207 additions and 5 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
gem 'libnotify', '0.8.0'
gem 'factory_girl_rails', '4.2.1'
end

# Use Bootstrap and less.js for stylesheets
Expand Down
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ GEM
diff-lcs (1.2.5)
erubis (2.7.0)
execjs (2.0.2)
factory_girl (4.2.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.2.1)
factory_girl (~> 4.2.0)
railties (>= 3.0.0)
ffi (1.9.3)
formatador (0.2.4)
guard (2.2.3)
Expand Down Expand Up @@ -196,6 +201,7 @@ DEPENDENCIES
capybara (= 2.1.0)
childprocess (= 0.3.6)
coffee-rails (~> 4.0.0)
factory_girl_rails (= 4.2.1)
guard-rspec (= 2.5.0)
guard-spork (= 1.5.0)
jbuilder (~> 1.2)
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/admins.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
30 changes: 30 additions & 0 deletions app/assets/stylesheets/admins.css.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Place all the styles related to the Admins controller here.
// They will automatically be included in application.css.
// You can use Less here: http://lesscss.org/

.box_sizing() {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}


input, textarea, select, .uneditable-input {
border: 1px solid #bbb;
width: 100%;
margin-bottom: 15px;
.box_sizing;
}

input {
height: auto !important;
}

#error_explanation {
color: #f00;
ul {
list-style: none;
margin: 0 0 18px 0;
}
}

3 changes: 3 additions & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@
*= require_self
*= require_tree .
*/
/*
*= require twitter/bootstrap
*/
19 changes: 19 additions & 0 deletions app/assets/stylesheets/static_pages.css.less
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
// Place all the styles related to the StaticPages controller here.
// They will automatically be included in application.css.
// You can use Less here: http://lesscss.org/

.box_sizing {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}


input, textarea, select, .uneditable-input {
border: 1px solid #bbb;
width: 100%;
margin-bottom: 15px;
.box_sizing;
}

input {
height: auto !important;
}

26 changes: 26 additions & 0 deletions app/controllers/admins_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class AdminsController < ApplicationController
def new
@admin = Admin.new
end

def show
@admin = Admin.find(params[:id])
end

def create
@admin = Admin.new(admin_params)
if @admin.save
flash[:success] = "Welcome to the Solar Explorer!"
redirect_to @admin
else
render 'new'
end
end

private
def admin_params
params.require(:admin).permit(:name, :email, :password,
:password_confirmation)
end

end
2 changes: 2 additions & 0 deletions app/helpers/admins_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module AdminsHelper
end
23 changes: 23 additions & 0 deletions app/views/admins/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<% provide(:title, "Administrator sign up") %>
<h1>Administrator sign up</h1>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= form_for(@admin) do |f| %>
<%= render 'shared/error_messages' %>

<%= f.label :name %>
<%= f.text_field :name %>

<%= f.label :email %>
<%= f.text_field :email %>

<%= f.label :password %>
<%= f.password_field :password %>

<%= f.label :password_confirmation, "Confirmation" %>
<%= f.password_field :password_confirmation %>

<%= f.submit "Create new admin", class: "btn btn-large btn-primary" %>
<% end %>
</div>
</div>
3 changes: 3 additions & 0 deletions app/views/admins/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<% provide(:title, @admin.name) %>
<h1><%= "Profil für #{@admin.name}" %></h1>
<p><%= "Name: #{@admin.name}, E-Mail: #{@admin.email }" %></p>
10 changes: 7 additions & 3 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
<%= csrf_meta_tags %>
</head>
<body>

<%= yield %>

<div class="container well">
<% flash.each do |key, value| %>
<%= content_tag(:div, value, class: "alert alert-#{key}") %>
<% end %>
<%= yield %>
<%= debug(params) if Rails.env.development? %>
</div>
</body>
</html>
12 changes: 12 additions & 0 deletions app/views/shared/_error_messages.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<% if @admin.errors.any? %>
<div id="error_explanation">
<div class="alert alert-error">
The form contains <%= pluralize(@admin.errors.count, "error") %>.
</div>
<ul>
<% @admin.errors.full_messages.each do |msg| %>
<li>* <%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
6 changes: 4 additions & 2 deletions app/views/static_pages/home.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<% provide(:title, 'Impressum') %>
<h1>Hauptseite/h1>
<% provide(:title, 'Home') %>
<div class="page-header">
<h1>Hauptseite</h1>
</div>
<p>
Schauen sie mal, was für ein Boot...
</p>
3 changes: 3 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@

# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr

# In testing, passwords should not take long
ActiveModel::SecurePassword.min_cost = true
end
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
SolarExplorer::Application.routes.draw do
resources :admins

get "static_pages/home"
get "static_pages/imprint"
get "static_pages/boat"
Expand Down
8 changes: 8 additions & 0 deletions spec/factories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FactoryGirl.define do
factory :admin do
name "Martin Meyerhoff"
email "[email protected]"
password "foobar"
password_confirmation "foobar"
end
end
55 changes: 55 additions & 0 deletions spec/requests/admin_pages_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
require 'spec_helper'

describe "Admin pages" do

subject { page }

describe "profile page" do
let(:admin) { FactoryGirl.create(:admin) }
before { visit admin_path(admin) }

it { should have_content(admin.name) }
it { should have_title(admin.name) }
end
describe "signup page" do
before { visit new_admin_path }

it { should have_content('Administrator sign up') }
it { should have_title('Administrator sign up') }
end

describe "signup" do

before { visit new_admin_path }

let(:submit) { "Create new admin" }

describe "with invalid information" do
it "should not create a user" do
expect { click_button submit }.not_to change(Admin, :count)
end
end

describe "with valid information" do
before do
fill_in "Name", with: "Example User"
fill_in "Email", with: "[email protected]"
fill_in "Password", with: "foobar"
fill_in "Confirmation", with: "foobar"
end

it "should create a user" do
expect { click_button submit }.to change(Admin, :count).by(1)
end

describe "after saving the user" do
before { click_button submit }
let(:admin) { Admin.find_by(email: '[email protected]') }

it { should have_title(admin.name) }
it { should have_selector('div.alert.alert-success', text: 'Welcome') }
end
end
end

end

0 comments on commit 9e2bcd1

Please sign in to comment.