Adding certifications; messed up adding certification_users so not staging those

This commit is contained in:
Will Bradley 2013-01-25 03:12:25 -07:00
parent fe283b051f
commit 43d949dc1d
20 changed files with 264 additions and 4 deletions

View File

@ -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://jashkenas.github.com/coffee-script/

View File

@ -0,0 +1,3 @@
// Place all the styles related to the Certifications controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -0,0 +1,77 @@
class CertificationsController < ApplicationController
load_and_authorize_resource :certification
load_and_authorize_resource :user, :through => :certification
before_filter :authenticate_user!
# GET /certifications
# GET /certifications.json
def index
@certifications = @certifications.sort_by(&:name)
respond_to do |format|
format.html # index.html.erb
format.json { render :json => @certifications }
end
end
# GET /certifications/1
# GET /certifications/1.json
def show
respond_to do |format|
format.html # show.html.erb
format.json { render :json => @certification }
end
end
# GET /certifications/new
# GET /certifications/new.json
def new
respond_to do |format|
format.html # new.html.erb
format.json { render :json => @certification }
end
end
# GET /certifications/1/edit
def edit
end
# POST /certifications
# POST /certifications.json
def create
respond_to do |format|
if @certification.save
format.html { redirect_to Certification, :notice => 'Certification was successfully created.' }
format.json { render :json => @certification, :status => :created, :location => @certification }
else
format.html { render :action => "new" }
format.json { render :json => @certification.errors, :status => :unprocessable_entity }
end
end
end
# PUT /certifications/1
# PUT /certifications/1.json
def update
respond_to do |format|
if @certification.update_attributes(params[:certification])
format.html { redirect_to Certification, :notice => 'Certification was successfully updated.' }
format.json { head :no_content }
else
format.html { render :action => "edit" }
format.json { render :json => @certification.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /certifications/1
# DELETE /certifications/1.json
def destroy
@certification.destroy
respond_to do |format|
format.html { redirect_to certifications_url }
format.json { head :no_content }
end
end
end

View File

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

View File

@ -5,10 +5,14 @@ class Ability
if !user.nil?
if user.admin?
can :manage, :all
else
can :read, User
can :read, Card, :user_id => user.id
end
if user.instructor?
can :manage, Certification
end
can :read, User
can :read, Certification
can :read, Card, :user_id => user.id
end
# Define abilities for the passed in user here. For example:
#

View File

@ -0,0 +1,4 @@
class Certification < ActiveRecord::Base
attr_accessible :description, :name
has_many :users, :through => :certifications_users
end

View File

@ -6,7 +6,8 @@ class User < ActiveRecord::Base
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :admin, :active, :emergency_name, :emergency_phone, :current_skills, :desired_skills, :waiver, :emergency_email, :phone, :payment_method, :orientation, :member_level
attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :admin, :instructor, :active, :emergency_name, :emergency_phone, :current_skills, :desired_skills, :waiver, :emergency_email, :phone, :payment_method, :orientation, :member_level
has_many :cards
has_many :certifications, :through => :certifications_users
end

View File

@ -0,0 +1,29 @@
<%= form_for(@certification) do |f| %>
<% if @certification.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@certification.errors.count, "error") %> prohibited this certification from being saved:</h2>
<ul>
<% @certification.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :description %><br />
<%= f.text_area :description %>
</div>
<% f.fields_for :users do |u| %>
<%= u.label :user %><br />
<%= collection_select(:certifications_users, :user_id, User.all.sort_by(&:name), :id, :name) %>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

View File

@ -0,0 +1,6 @@
<h1>Editing certification</h1>
<%= render 'form' %>
<%= link_to 'Show', @certification %> |
<%= link_to 'Back', certifications_path %>

View File

@ -0,0 +1,15 @@
<h1>Listing certifications</h1>
<%= link_to 'New Certification', new_certification_path if can? :create, Certification %>
<ul>
<% @certifications.each do |certification| %>
<li><%= link_to certification.name, certification %>
<% if can? :update, certification %> | <%= link_to 'Edit', edit_certification_path(certification) %><% end %>
<% if can? :delete, certification %> | <%= link_to 'Destroy', certification, :confirm => 'Are you sure?', :method => :delete %><% end %>
</li>
<% end %>
</ul>
<br />

View File

@ -0,0 +1,5 @@
<h1>New certification</h1>
<%= render 'form' %>
<%= link_to 'Back', certifications_path %>

View File

@ -0,0 +1,20 @@
<p>
<b>Name:</b>
<%= @certification.name %>
</p>
<p>
<b>Description:</b>
<%= simple_format @certification.description %>
</p>
<b>Certified Users:</b>
<ul>
<% @certification.users.each do |user| %>
<% unless user.name.blank? %><li><%= user.name %></li><% end %>
<% end %>
<% if @certification.users.blank? then %><li>n/a</li><% end %>
</ul>
<% if can? :update, @certification %><%= link_to 'Edit', edit_certification_path(@certification) %> |<% end %>
<%= link_to 'Back', certifications_path %>

View File

@ -10,6 +10,7 @@
<div id="header">
<%= link_to 'Users', users_path if can? :read, User %>
<%= link_to 'Cards', cards_path if can? :read, Card %>
<%= link_to 'Certifications', certifications_path if can? :read, Certification %>
<%= link_to 'Logs', door_logs_path if can? :read, DoorLog %>
<%= link_to 'Sign out', destroy_user_session_path, :method => :delete if user_signed_in? %>
<%= link_to 'Sign in', new_user_session_path unless user_signed_in? %>

View File

@ -19,5 +19,14 @@
<%= @user.admin %>
</p>
<b>Certifications:</b>
<ul>
<% @user.certifications.each do |certification| %>
<li>certification.name</li>
<% end %>
<% if @user.certifications.blank? %><li>n/a</li><% end %>
</ul>
<%= link_to 'Edit', edit_user_path(@user) %> |
<%= link_to 'Back', users_path %>

View File

@ -1,5 +1,7 @@
Dooraccess::Application.routes.draw do
resources :certifications
devise_for :users
resources :users

View File

@ -0,0 +1,10 @@
class CreateCertifications < ActiveRecord::Migration
def change
create_table :certifications do |t|
t.string :name
t.string :description
t.timestamps
end
end
end

9
test/fixtures/certifications.yml vendored Normal file
View File

@ -0,0 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
name: MyString
description: MyString
two:
name: MyString
description: MyString

View File

@ -0,0 +1,49 @@
require 'test_helper'
class CertificationsControllerTest < ActionController::TestCase
setup do
@certification = certifications(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:certifications)
end
test "should get new" do
get :new
assert_response :success
end
test "should create certification" do
assert_difference('Certification.count') do
post :create, :certification => { :description => @certification.description, :name => @certification.name }
end
assert_redirected_to certification_path(assigns(:certification))
end
test "should show certification" do
get :show, :id => @certification
assert_response :success
end
test "should get edit" do
get :edit, :id => @certification
assert_response :success
end
test "should update certification" do
put :update, :id => @certification, :certification => { :description => @certification.description, :name => @certification.name }
assert_redirected_to certification_path(assigns(:certification))
end
test "should destroy certification" do
assert_difference('Certification.count', -1) do
delete :destroy, :id => @certification
end
assert_redirected_to certifications_path
end
end

View File

@ -0,0 +1,7 @@
require 'test_helper'
class CertificationTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View File

@ -0,0 +1,4 @@
require 'test_helper'
class CertificationsHelperTest < ActionView::TestCase
end