From f2030050a16b2b8d759bca5aa9b85e2c3dab2116 Mon Sep 17 00:00:00 2001 From: Aja Hammerly Date: Wed, 23 Jan 2013 20:06:36 -0800 Subject: [PATCH] Talk topic suggestions --- app/controllers/suggestions_controller.rb | 32 +++++++ app/models/suggestion.rb | 3 + app/views/suggestions/_form.html.erb | 21 +++++ app/views/suggestions/index.html.erb | 19 ++++ app/views/suggestions/new.html.erb | 5 + app/views/talks/index.html.erb | 2 + config/routes.rb | 4 + .../20130124033130_create_suggestions.rb | 9 ++ db/schema.rb | 94 ++++++++++--------- .../suggestions_controller_test.rb | 26 +++++ test/fixtures/suggestions.yml | 8 ++ test/models/suggestion_test.rb | 13 +++ 12 files changed, 192 insertions(+), 44 deletions(-) create mode 100644 app/controllers/suggestions_controller.rb create mode 100644 app/models/suggestion.rb create mode 100644 app/views/suggestions/_form.html.erb create mode 100644 app/views/suggestions/index.html.erb create mode 100644 app/views/suggestions/new.html.erb create mode 100644 db/migrate/20130124033130_create_suggestions.rb create mode 100644 test/controllers/suggestions_controller_test.rb create mode 100644 test/fixtures/suggestions.yml create mode 100644 test/models/suggestion_test.rb diff --git a/app/controllers/suggestions_controller.rb b/app/controllers/suggestions_controller.rb new file mode 100644 index 0000000..e6edf28 --- /dev/null +++ b/app/controllers/suggestions_controller.rb @@ -0,0 +1,32 @@ +class SuggestionsController < ApplicationController + # GET /suggestions + def index + @suggestions = Suggestion.all + + respond_to do |format| + format.html # index.html.erb + end + end + + # GET /suggestions/new + def new + @suggestion = Suggestion.new + + respond_to do |format| + format.html # new.html.erb + end + end + + # POST /suggestions + def create + @suggestion = Suggestion.new(params[:suggestion]) + + respond_to do |format| + if @suggestion.save + format.html { redirect_to suggestions_path, notice: 'Suggestion was successfully created.' } + else + format.html { render action: "new" } + end + end + end +end diff --git a/app/models/suggestion.rb b/app/models/suggestion.rb new file mode 100644 index 0000000..05463a4 --- /dev/null +++ b/app/models/suggestion.rb @@ -0,0 +1,3 @@ +class Suggestion < ActiveRecord::Base + validates :title, :presence => true +end diff --git a/app/views/suggestions/_form.html.erb b/app/views/suggestions/_form.html.erb new file mode 100644 index 0000000..6e177e4 --- /dev/null +++ b/app/views/suggestions/_form.html.erb @@ -0,0 +1,21 @@ +<%= form_for(@suggestion) do |f| %> + <% if @suggestion.errors.any? %> +
+

<%= pluralize(@suggestion.errors.count, "error") %> prohibited this suggestion from being saved:

+ + +
+ <% end %> + +
+ <%= f.label :topic %>
+ <%= f.text_field :title %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/suggestions/index.html.erb b/app/views/suggestions/index.html.erb new file mode 100644 index 0000000..e5b7a41 --- /dev/null +++ b/app/views/suggestions/index.html.erb @@ -0,0 +1,19 @@ +

Talk Topic Suggestions

+This is a list of topics and questions that people in Seattle.rb would like to have addressed at our monthly talk meetings. +
+
+ + + + + +<% @suggestions.each do |suggestion| %> + + + +<% end %> +
Topic
<%= suggestion.title %>
+ +
+ +<%= link_to 'New Suggestion', new_suggestion_path, {:style => 'margin-left: 10px'}%> diff --git a/app/views/suggestions/new.html.erb b/app/views/suggestions/new.html.erb new file mode 100644 index 0000000..e27e598 --- /dev/null +++ b/app/views/suggestions/new.html.erb @@ -0,0 +1,5 @@ +

New suggestion

+ +<%= render 'form' %> + +<%= link_to 'Back', suggestions_path %> diff --git a/app/views/talks/index.html.erb b/app/views/talks/index.html.erb index 2f7e727..4c7827c 100644 --- a/app/views/talks/index.html.erb +++ b/app/views/talks/index.html.erb @@ -39,3 +39,5 @@ <% end %> <% end %> + +<%= link_to 'Suggest a Topic For a Talk', suggestions_path, {:style => 'font-size 16px; font-weight: bold'} -%> diff --git a/config/routes.rb b/config/routes.rb index 84a06d7..a44038c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,8 @@ SeattlerbOrg::Application.routes.draw do + resources :suggestions, :only => [:index, :new, :create] + + resources :helps + mount RailsAdmin::Engine => '/adminsrb', :as => 'rails_admin' devise_for :users diff --git a/db/migrate/20130124033130_create_suggestions.rb b/db/migrate/20130124033130_create_suggestions.rb new file mode 100644 index 0000000..286eaf1 --- /dev/null +++ b/db/migrate/20130124033130_create_suggestions.rb @@ -0,0 +1,9 @@ +class CreateSuggestions < ActiveRecord::Migration + def change + create_table :suggestions do |t| + t.string :title + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 7156330..9c47a84 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,50 +11,56 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130110050659) do +ActiveRecord::Schema.define(:version => 20130124033130) do create_table "affiliations", :force => true do |t| - t.integer "dude_id" - t.integer "project_id" - t.timestamp "created_at" - t.timestamp "updated_at" + t.integer "dude_id" + t.integer "project_id" + t.datetime "created_at" + t.datetime "updated_at" end create_table "dudes", :force => true do |t| - t.string "name" - t.string "email" - t.text "bio" - t.string "website" - t.timestamp "created_at" - t.timestamp "updated_at" - t.string "ruby_gems_id" - t.boolean "featured", :default => false - t.string "twitter" - t.string "github" - t.string "image_url" + t.string "name" + t.string "email" + t.text "bio", :limit => 255 + t.string "website" + t.datetime "created_at" + t.datetime "updated_at" + t.string "ruby_gems_id" + t.boolean "featured", :default => false + t.string "twitter" + t.string "github" + t.string "image_url" end create_table "projects", :force => true do |t| - t.string "name" - t.string "url" - t.text "description" - t.timestamp "created_at" - t.timestamp "updated_at" + t.string "name" + t.string "url" + t.text "description" + t.datetime "created_at" + t.datetime "updated_at" end create_table "rails_admin_histories", :force => true do |t| - t.text "message" - t.string "username" - t.integer "item" - t.string "table" - t.integer "month" - t.integer "year" - t.timestamp "created_at" - t.timestamp "updated_at" + t.text "message" + t.string "username" + t.integer "item" + t.string "table" + t.integer "month", :limit => 2 + t.integer "year", :limit => 5 + t.datetime "created_at" + t.datetime "updated_at" end add_index "rails_admin_histories", ["item", "table", "month", "year"], :name => "index_rails_admin_histories" + create_table "suggestions", :force => true do |t| + t.string "title" + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "talks", :force => true do |t| t.string "title" t.text "description" @@ -66,21 +72,21 @@ end create_table "users", :force => true do |t| - t.string "email", :default => "", :null => false - t.string "encrypted_password", :default => "", :null => false - t.string "reset_password_token" - t.timestamp "reset_password_sent_at" - t.timestamp "remember_created_at" - t.integer "sign_in_count", :default => 0 - t.timestamp "current_sign_in_at" - t.timestamp "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" - t.timestamp "created_at" - t.timestamp "updated_at" - t.string "confirmation_token" - t.timestamp "confirmed_at" - t.timestamp "confirmation_sent_at" + t.string "email", :default => "", :null => false + t.string "encrypted_password", :default => "", :null => false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.integer "sign_in_count", :default => 0 + t.datetime "current_sign_in_at" + t.datetime "last_sign_in_at" + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" + t.datetime "created_at" + t.datetime "updated_at" + t.string "confirmation_token" + t.datetime "confirmed_at" + t.datetime "confirmation_sent_at" end add_index "users", ["email"], :name => "index_users_on_email", :unique => true diff --git a/test/controllers/suggestions_controller_test.rb b/test/controllers/suggestions_controller_test.rb new file mode 100644 index 0000000..f51cd71 --- /dev/null +++ b/test/controllers/suggestions_controller_test.rb @@ -0,0 +1,26 @@ +require "minitest_helper" + +class SuggestionsControllerTest < MiniTest::Rails::ActionController::TestCase + + before do + @suggestion = suggestions(:one) + end + + def test_index + get :index + assert_response :success + assert_not_nil assigns(:suggestions) + end + + def test_new + get :new + assert_response :success + end + + def test_create + assert_difference('Suggestion.count', 1) do + post :create, suggestion: {:title => "My title" } + end + assert_redirected_to suggestions_path + end +end diff --git a/test/fixtures/suggestions.yml b/test/fixtures/suggestions.yml new file mode 100644 index 0000000..545bd0b --- /dev/null +++ b/test/fixtures/suggestions.yml @@ -0,0 +1,8 @@ +# Read about fixtures at +# http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +one: + title: MyString + +two: + title: MyString diff --git a/test/models/suggestion_test.rb b/test/models/suggestion_test.rb new file mode 100644 index 0000000..2334258 --- /dev/null +++ b/test/models/suggestion_test.rb @@ -0,0 +1,13 @@ +require "minitest_helper" + +class SuggestionTest < MiniTest::Rails::ActiveSupport::TestCase + def test_valid + suggestion = Suggestion.new(:title => "WOOT") + assert suggestion.valid? + end + + def test_invalid + suggestion = Suggestion.new() + refute suggestion.valid? + end +end