Permalink
Browse files

Add ability to create new states by admins

  • Loading branch information...
prakhar1989 committed Mar 26, 2012
1 parent 21c7fce commit d15c44db9e62df308caa0f032150e8ca1c9fa44a
@@ -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/
@@ -0,0 +1,3 @@
+// Place all the styles related to the admin/states controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,20 @@
+class Admin::StatesController < ApplicationController
+ def index
+ @states = State.all
+ end
+
+ def new
+ @state = State.new
+ end
+
+ def create
+ @state = State.new(params[:state])
+ if @state.save
+ flash[:notice] = "State has been created"
+ redirect_to admin_states_path
+ else
+ flash[:alert] = "State has not been created"
+ render 'new'
+ end
+ end
+end
@@ -1,5 +1,6 @@
class ApplicationController < ActionController::Base
protect_from_forgery
+ before_filter :find_states
def authorize_admin!
authenticate_user!
@@ -9,5 +10,9 @@ def authorize_admin!
end
end
+ def find_states
+ @states = State.all
+ end
+
end
@@ -0,0 +1,2 @@
+module Admin::StatesHelper
+end
@@ -1,2 +1,3 @@
<%= link_to "Users", admin_users_path %>
+<%= link_to "States", admin_states_path %>
<h2>Welcome to Ticketee's Admin Lounge. Please enjoy your stay</h2>
@@ -0,0 +1,4 @@
+<%= simple_form_for [:admin, @state] do |f| %>
+ <%= f.input :name %>
+ <%= f.submit %>
+<% end %>
@@ -0,0 +1,7 @@
+<%= link_to "New State", new_admin_state_path %>
+
+<ul id="states">
+ <% for state in @states %>
+ <li><%= state.name %></li>
+ <% end %>
+</ul>
@@ -0,0 +1,2 @@
+<h2>Add new state</h2>
+<%= render 'form' %>
@@ -22,6 +22,14 @@
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
</style>
<%= stylesheet_link_tag "application", :media => "all" %>
+ <style>
+ <% for state in @states %>
+ .state_<%= state.name.parameterize %> {
+ background: <%= state.background %>;
+ color: <%= state.color %>;
+ }
+ <% end %>
+ </style>
<!-- Le fav and touch icons -->
<body>
@@ -14,6 +14,7 @@
<ul id="tickets">
<% @project.tickets.each do |ticket| %>
<li>
+ <%= render ticket.state if ticket.state %>
#<%= ticket.id %> - <%= link_to ticket.title, project_ticket_path(ticket) %>
</li>
<% end %>
View
@@ -18,6 +18,7 @@
namespace :admin do
root :to => "base#index"
+ resources :states
resources :users do
resources :permissions
end
@@ -0,0 +1,18 @@
+Feature: Creating States
+ In order to be able to specify other states for tickets
+ As an admin
+ I want to add them to the application
+
+ Background:
+ Given there are the following users:
+ | email | password | admin |
+ | user@ticketee.com | password | true |
+ And I am signed in as them
+
+ Scenario: Creating a state
+ When I follow "Admin"
+ And I follow "States"
+ And I follow "New State"
+ And I fill in "Name" with "Duplicate"
+ And I press "Create State"
+ Then I should see "State has been created"
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe Admin::StatesController do
+
+end
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the Admin::StatesHelper. For example:
+#
+# describe Admin::StatesHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# helper.concat_strings("this","that").should == "this that"
+# end
+# end
+# end
+describe Admin::StatesHelper do
+ pending "add some examples to (or delete) #{__FILE__}"
+end

0 comments on commit d15c44d

Please sign in to comment.