1
0
Fork 0

Add Alerts controller

This commit is contained in:
Andrew Tomaka 2013-04-02 02:43:01 -04:00
parent 23d5a9f627
commit 01579ce68d
17 changed files with 362 additions and 0 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 Alerts 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,69 @@
body {
background-color: #fff;
color: #333;
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px;
}
p, ol, ul, td {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px;
}
pre {
background-color: #eee;
padding: 10px;
font-size: 11px;
}
a {
color: #000;
&:visited {
color: #666;
}
&:hover {
color: #fff;
background-color: #000;
}
}
div {
&.field, &.actions {
margin-bottom: 10px;
}
}
#notice {
color: green;
}
.field_with_errors {
padding: 2px;
background-color: red;
display: table;
}
#error_explanation {
width: 450px;
border: 2px solid red;
padding: 7px;
padding-bottom: 0;
margin-bottom: 20px;
background-color: #f0f0f0;
h2 {
text-align: left;
font-weight: bold;
padding: 5px 5px 5px 15px;
font-size: 12px;
margin: -7px;
margin-bottom: 0px;
background-color: #c00;
color: #fff;
}
ul li {
font-size: 12px;
list-style: square;
}
}

View file

@ -0,0 +1,83 @@
class AlertsController < ApplicationController
# GET /alerts
# GET /alerts.json
def index
@alerts = Alert.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @alerts }
end
end
# GET /alerts/1
# GET /alerts/1.json
def show
@alert = Alert.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @alert }
end
end
# GET /alerts/new
# GET /alerts/new.json
def new
@alert = Alert.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @alert }
end
end
# GET /alerts/1/edit
def edit
@alert = Alert.find(params[:id])
end
# POST /alerts
# POST /alerts.json
def create
@alert = Alert.new(params[:alert])
respond_to do |format|
if @alert.save
format.html { redirect_to @alert, notice: 'Alert was successfully created.' }
format.json { render json: @alert, status: :created, location: @alert }
else
format.html { render action: "new" }
format.json { render json: @alert.errors, status: :unprocessable_entity }
end
end
end
# PUT /alerts/1
# PUT /alerts/1.json
def update
@alert = Alert.find(params[:id])
respond_to do |format|
if @alert.update_attributes(params[:alert])
format.html { redirect_to @alert, notice: 'Alert was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @alert.errors, status: :unprocessable_entity }
end
end
end
# DELETE /alerts/1
# DELETE /alerts/1.json
def destroy
@alert = Alert.find(params[:id])
@alert.destroy
respond_to do |format|
format.html { redirect_to alerts_url }
format.json { head :no_content }
end
end
end

View file

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

3
app/models/alert.rb Normal file
View file

@ -0,0 +1,3 @@
class Alert < ActiveRecord::Base
attr_accessible :alerted, :course, :department, :user_id
end

View file

@ -0,0 +1,32 @@
<%= form_for @alert, :html => { :class => 'form-horizontal' } do |f| %>
<div class="control-group">
<%= f.label :user_id, :class => 'control-label' %>
<div class="controls">
<%= f.number_field :user_id, :class => 'number_field' %>
</div>
</div>
<div class="control-group">
<%= f.label :department, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :department, :class => 'text_field' %>
</div>
</div>
<div class="control-group">
<%= f.label :course, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :course, :class => 'text_field' %>
</div>
</div>
<div class="control-group">
<%= f.label :alerted, :class => 'control-label' %>
<div class="controls">
<%= f.check_box :alerted, :class => 'check_box' %>
</div>
</div>
<div class="form-actions">
<%= f.submit nil, :class => 'btn btn-primary' %>
<%= link_to t('.cancel', :default => t("helpers.links.cancel")),
alerts_path, :class => 'btn' %>
</div>
<% end %>

View file

@ -0,0 +1,5 @@
<%- model_class = Alert -%>
<div class="page-header">
<h1><%=t '.title', :default => [:'helpers.titles.edit', 'Edit %{model}'], :model => model_class.model_name.human %></h1>
</div>
<%= render :partial => 'form' %>

View file

@ -0,0 +1,42 @@
<%- model_class = Alert -%>
<div class="page-header">
<h1><%=t '.title', :default => model_class.model_name.human.pluralize %></h1>
</div>
<table class="table table-striped">
<thead>
<tr>
<th><%= model_class.human_attribute_name(:id) %></th>
<th><%= model_class.human_attribute_name(:user_id) %></th>
<th><%= model_class.human_attribute_name(:department) %></th>
<th><%= model_class.human_attribute_name(:course) %></th>
<th><%= model_class.human_attribute_name(:alerted) %></th>
<th><%= model_class.human_attribute_name(:created_at) %></th>
<th><%=t '.actions', :default => t("helpers.actions") %></th>
</tr>
</thead>
<tbody>
<% @alerts.each do |alert| %>
<tr>
<td><%= link_to alert.id, alert_path(alert) %></td>
<td><%= alert.user_id %></td>
<td><%= alert.department %></td>
<td><%= alert.course %></td>
<td><%= alert.alerted %></td>
<td><%=l alert.created_at %></td>
<td>
<%= link_to t('.edit', :default => t("helpers.links.edit")),
edit_alert_path(alert), :class => 'btn btn-mini' %>
<%= link_to t('.destroy', :default => t("helpers.links.destroy")),
alert_path(alert),
:method => :delete,
:data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
:class => 'btn btn-mini btn-danger' %>
</td>
</tr>
<% end %>
</tbody>
</table>
<%= link_to t('.new', :default => t("helpers.links.new")),
new_alert_path,
:class => 'btn btn-primary' %>

View file

@ -0,0 +1,5 @@
<%- model_class = Alert -%>
<div class="page-header">
<h1><%=t '.title', :default => [:'helpers.titles.new', 'New %{model}'], :model => model_class.model_name.human %></h1>
</div>
<%= render :partial => 'form' %>

View file

@ -0,0 +1,27 @@
<%- model_class = Alert -%>
<div class="page-header">
<h1><%=t '.title', :default => model_class.model_name.human %></h1>
</div>
<dl class="dl-horizontal">
<dt><strong><%= model_class.human_attribute_name(:user_id) %>:</strong></dt>
<dd><%= @alert.user_id %></dd>
<dt><strong><%= model_class.human_attribute_name(:department) %>:</strong></dt>
<dd><%= @alert.department %></dd>
<dt><strong><%= model_class.human_attribute_name(:course) %>:</strong></dt>
<dd><%= @alert.course %></dd>
<dt><strong><%= model_class.human_attribute_name(:alerted) %>:</strong></dt>
<dd><%= @alert.alerted %></dd>
</dl>
<div class="form-actions">
<%= link_to t('.back', :default => t("helpers.links.back")),
alerts_path, :class => 'btn' %>
<%= link_to t('.edit', :default => t("helpers.links.edit")),
edit_alert_path(@alert), :class => 'btn' %>
<%= link_to t('.destroy', :default => t("helpers.links.destroy")),
alert_path(@alert),
:method => 'delete',
:data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
:class => 'btn btn-danger' %>
</div>

View file

@ -1,4 +1,7 @@
MsuCourseAlerter::Application.routes.draw do
resources :alerts
# The priority is based upon order of creation:
# first created -> highest priority.

View file

@ -0,0 +1,12 @@
class CreateAlerts < ActiveRecord::Migration
def change
create_table :alerts do |t|
t.integer :user_id
t.string :department
t.string :course
t.boolean :alerted
t.timestamps
end
end
end

13
test/fixtures/alerts.yml vendored Normal file
View file

@ -0,0 +1,13 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
user_id: 1
department: MyString
course: MyString
alerted: false
two:
user_id: 1
department: MyString
course: MyString
alerted: false

View file

@ -0,0 +1,49 @@
require 'test_helper'
class AlertsControllerTest < ActionController::TestCase
setup do
@alert = alerts(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:alerts)
end
test "should get new" do
get :new
assert_response :success
end
test "should create alert" do
assert_difference('Alert.count') do
post :create, alert: { alerted: @alert.alerted, course: @alert.course, department: @alert.department, user_id: @alert.user_id }
end
assert_redirected_to alert_path(assigns(:alert))
end
test "should show alert" do
get :show, id: @alert
assert_response :success
end
test "should get edit" do
get :edit, id: @alert
assert_response :success
end
test "should update alert" do
put :update, id: @alert, alert: { alerted: @alert.alerted, course: @alert.course, department: @alert.department, user_id: @alert.user_id }
assert_redirected_to alert_path(assigns(:alert))
end
test "should destroy alert" do
assert_difference('Alert.count', -1) do
delete :destroy, id: @alert
end
assert_redirected_to alerts_path
end
end

7
test/unit/alert_test.rb Normal file
View file

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

View file

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