From 2f05885c4a13da7298c869115c0fb3bd04907774 Mon Sep 17 00:00:00 2001 From: Rueshyna Date: Wed, 28 Nov 2012 11:45:23 +0800 Subject: [PATCH] add journal list template --- .../desktop/journal_lists_controller.rb | 83 +++++++++ app/helpers/desktop/journal_lists_helper.rb | 2 + .../desktop/journal_lists/_form.html.erb | 17 ++ app/views/desktop/journal_lists/edit.html.erb | 6 + .../desktop/journal_lists/index.html.erb | 21 +++ app/views/desktop/journal_lists/new.html.erb | 5 + app/views/desktop/journal_lists/show.html.erb | 5 + .../desktop/journal_lists_controller_spec.rb | 164 ++++++++++++++++++ .../desktop/journal_lists_helper_spec.rb | 15 ++ .../desktop/desktop_journal_lists_spec.rb | 11 ++ .../desktop/journal_lists_routing_spec.rb | 35 ++++ .../journal_lists/edit.html.erb_spec.rb | 15 ++ .../journal_lists/index.html.erb_spec.rb | 15 ++ .../journal_lists/new.html.erb_spec.rb | 15 ++ .../journal_lists/show.html.erb_spec.rb | 12 ++ 15 files changed, 421 insertions(+) create mode 100644 app/controllers/desktop/journal_lists_controller.rb create mode 100644 app/helpers/desktop/journal_lists_helper.rb create mode 100644 app/views/desktop/journal_lists/_form.html.erb create mode 100644 app/views/desktop/journal_lists/edit.html.erb create mode 100644 app/views/desktop/journal_lists/index.html.erb create mode 100644 app/views/desktop/journal_lists/new.html.erb create mode 100644 app/views/desktop/journal_lists/show.html.erb create mode 100644 spec/controllers/desktop/journal_lists_controller_spec.rb create mode 100644 spec/helpers/desktop/journal_lists_helper_spec.rb create mode 100644 spec/requests/desktop/desktop_journal_lists_spec.rb create mode 100644 spec/routing/desktop/journal_lists_routing_spec.rb create mode 100644 spec/views/desktop/journal_lists/edit.html.erb_spec.rb create mode 100644 spec/views/desktop/journal_lists/index.html.erb_spec.rb create mode 100644 spec/views/desktop/journal_lists/new.html.erb_spec.rb create mode 100644 spec/views/desktop/journal_lists/show.html.erb_spec.rb diff --git a/app/controllers/desktop/journal_lists_controller.rb b/app/controllers/desktop/journal_lists_controller.rb new file mode 100644 index 00000000..f4a0d980 --- /dev/null +++ b/app/controllers/desktop/journal_lists_controller.rb @@ -0,0 +1,83 @@ +class Desktop::JournalListsController < ApplicationController + # GET /desktop/journal_lists + # GET /desktop/journal_lists.json + def index + @desktop_journal_lists = Desktop::JournalList.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @desktop_journal_lists } + end + end + + # GET /desktop/journal_lists/1 + # GET /desktop/journal_lists/1.json + def show + @desktop_journal_list = Desktop::JournalList.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @desktop_journal_list } + end + end + + # GET /desktop/journal_lists/new + # GET /desktop/journal_lists/new.json + def new + @desktop_journal_list = Desktop::JournalList.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @desktop_journal_list } + end + end + + # GET /desktop/journal_lists/1/edit + def edit + @desktop_journal_list = Desktop::JournalList.find(params[:id]) + end + + # POST /desktop/journal_lists + # POST /desktop/journal_lists.json + def create + @desktop_journal_list = Desktop::JournalList.new(params[:desktop_journal_list]) + + respond_to do |format| + if @desktop_journal_list.save + format.html { redirect_to @desktop_journal_list, notice: 'Journal list was successfully created.' } + format.json { render json: @desktop_journal_list, status: :created, location: @desktop_journal_list } + else + format.html { render action: "new" } + format.json { render json: @desktop_journal_list.errors, status: :unprocessable_entity } + end + end + end + + # PUT /desktop/journal_lists/1 + # PUT /desktop/journal_lists/1.json + def update + @desktop_journal_list = Desktop::JournalList.find(params[:id]) + + respond_to do |format| + if @desktop_journal_list.update_attributes(params[:desktop_journal_list]) + format.html { redirect_to @desktop_journal_list, notice: 'Journal list was successfully updated.' } + format.json { head :ok } + else + format.html { render action: "edit" } + format.json { render json: @desktop_journal_list.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /desktop/journal_lists/1 + # DELETE /desktop/journal_lists/1.json + def destroy + @desktop_journal_list = Desktop::JournalList.find(params[:id]) + @desktop_journal_list.destroy + + respond_to do |format| + format.html { redirect_to desktop_journal_lists_url } + format.json { head :ok } + end + end +end diff --git a/app/helpers/desktop/journal_lists_helper.rb b/app/helpers/desktop/journal_lists_helper.rb new file mode 100644 index 00000000..e21dc09f --- /dev/null +++ b/app/helpers/desktop/journal_lists_helper.rb @@ -0,0 +1,2 @@ +module Desktop::JournalListsHelper +end diff --git a/app/views/desktop/journal_lists/_form.html.erb b/app/views/desktop/journal_lists/_form.html.erb new file mode 100644 index 00000000..ac7f7ac6 --- /dev/null +++ b/app/views/desktop/journal_lists/_form.html.erb @@ -0,0 +1,17 @@ +<%= form_for(@desktop_journal_list) do |f| %> + <% if @desktop_journal_list.errors.any? %> +
+

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

+ + +
+ <% end %> + +
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/desktop/journal_lists/edit.html.erb b/app/views/desktop/journal_lists/edit.html.erb new file mode 100644 index 00000000..d628e895 --- /dev/null +++ b/app/views/desktop/journal_lists/edit.html.erb @@ -0,0 +1,6 @@ +

Editing desktop_journal_list

+ +<%= render 'form' %> + +<%= link_to 'Show', @desktop_journal_list %> | +<%= link_to 'Back', desktop_journal_lists_path %> diff --git a/app/views/desktop/journal_lists/index.html.erb b/app/views/desktop/journal_lists/index.html.erb new file mode 100644 index 00000000..618d2ae1 --- /dev/null +++ b/app/views/desktop/journal_lists/index.html.erb @@ -0,0 +1,21 @@ +

Listing desktop_journal_lists

+ + + + + + + + +<% @desktop_journal_lists.each do |desktop_journal_list| %> + + + + + +<% end %> +
<%= link_to 'Show', desktop_journal_list %><%= link_to 'Edit', edit_desktop_journal_list_path(desktop_journal_list) %><%= link_to 'Destroy', desktop_journal_list, confirm: 'Are you sure?', method: :delete %>
+ +
+ +<%= link_to 'New Journal list', new_desktop_journal_list_path %> diff --git a/app/views/desktop/journal_lists/new.html.erb b/app/views/desktop/journal_lists/new.html.erb new file mode 100644 index 00000000..95017361 --- /dev/null +++ b/app/views/desktop/journal_lists/new.html.erb @@ -0,0 +1,5 @@ +

New desktop_journal_list

+ +<%= render 'form' %> + +<%= link_to 'Back', desktop_journal_lists_path %> diff --git a/app/views/desktop/journal_lists/show.html.erb b/app/views/desktop/journal_lists/show.html.erb new file mode 100644 index 00000000..d454b78f --- /dev/null +++ b/app/views/desktop/journal_lists/show.html.erb @@ -0,0 +1,5 @@ +

<%= notice %>

+ + +<%= link_to 'Edit', edit_desktop_journal_list_path(@desktop_journal_list) %> | +<%= link_to 'Back', desktop_journal_lists_path %> diff --git a/spec/controllers/desktop/journal_lists_controller_spec.rb b/spec/controllers/desktop/journal_lists_controller_spec.rb new file mode 100644 index 00000000..99d2e2dc --- /dev/null +++ b/spec/controllers/desktop/journal_lists_controller_spec.rb @@ -0,0 +1,164 @@ +require 'spec_helper' + +# This spec was generated by rspec-rails when you ran the scaffold generator. +# It demonstrates how one might use RSpec to specify the controller code that +# was generated by Rails when you ran the scaffold generator. +# +# It assumes that the implementation code is generated by the rails scaffold +# generator. If you are using any extension libraries to generate different +# controller code, this generated spec may or may not pass. +# +# It only uses APIs available in rails and/or rspec-rails. There are a number +# of tools you can use to make these specs even more expressive, but we're +# sticking to rails and rspec-rails APIs to keep things simple and stable. +# +# Compared to earlier versions of this generator, there is very limited use of +# stubs and message expectations in this spec. Stubs are only used when there +# is no simpler way to get a handle on the object needed for the example. +# Message expectations are only used when there is no simpler way to specify +# that an instance is receiving a specific message. + +describe Desktop::JournalListsController do + + # This should return the minimal set of attributes required to create a valid + # Desktop::JournalList. As you add validations to Desktop::JournalList, be sure to + # update the return value of this method accordingly. + def valid_attributes + {} + end + + # This should return the minimal set of values that should be in the session + # in order to pass any filters (e.g. authentication) defined in + # Desktop::JournalListsController. Be sure to keep this updated too. + def valid_session + {} + end + + describe "GET index" do + it "assigns all desktop_journal_lists as @desktop_journal_lists" do + journal_list = Desktop::JournalList.create! valid_attributes + get :index, {}, valid_session + assigns(:desktop_journal_lists).should eq([journal_list]) + end + end + + describe "GET show" do + it "assigns the requested desktop_journal_list as @desktop_journal_list" do + journal_list = Desktop::JournalList.create! valid_attributes + get :show, {:id => journal_list.to_param}, valid_session + assigns(:desktop_journal_list).should eq(journal_list) + end + end + + describe "GET new" do + it "assigns a new desktop_journal_list as @desktop_journal_list" do + get :new, {}, valid_session + assigns(:desktop_journal_list).should be_a_new(Desktop::JournalList) + end + end + + describe "GET edit" do + it "assigns the requested desktop_journal_list as @desktop_journal_list" do + journal_list = Desktop::JournalList.create! valid_attributes + get :edit, {:id => journal_list.to_param}, valid_session + assigns(:desktop_journal_list).should eq(journal_list) + end + end + + describe "POST create" do + describe "with valid params" do + it "creates a new Desktop::JournalList" do + expect { + post :create, {:desktop_journal_list => valid_attributes}, valid_session + }.to change(Desktop::JournalList, :count).by(1) + end + + it "assigns a newly created desktop_journal_list as @desktop_journal_list" do + post :create, {:desktop_journal_list => valid_attributes}, valid_session + assigns(:desktop_journal_list).should be_a(Desktop::JournalList) + assigns(:desktop_journal_list).should be_persisted + end + + it "redirects to the created desktop_journal_list" do + post :create, {:desktop_journal_list => valid_attributes}, valid_session + response.should redirect_to(Desktop::JournalList.last) + end + end + + describe "with invalid params" do + it "assigns a newly created but unsaved desktop_journal_list as @desktop_journal_list" do + # Trigger the behavior that occurs when invalid params are submitted + Desktop::JournalList.any_instance.stub(:save).and_return(false) + post :create, {:desktop_journal_list => {}}, valid_session + assigns(:desktop_journal_list).should be_a_new(Desktop::JournalList) + end + + it "re-renders the 'new' template" do + # Trigger the behavior that occurs when invalid params are submitted + Desktop::JournalList.any_instance.stub(:save).and_return(false) + post :create, {:desktop_journal_list => {}}, valid_session + response.should render_template("new") + end + end + end + + describe "PUT update" do + describe "with valid params" do + it "updates the requested desktop_journal_list" do + journal_list = Desktop::JournalList.create! valid_attributes + # Assuming there are no other desktop_journal_lists in the database, this + # specifies that the Desktop::JournalList created on the previous line + # receives the :update_attributes message with whatever params are + # submitted in the request. + Desktop::JournalList.any_instance.should_receive(:update_attributes).with({'these' => 'params'}) + put :update, {:id => journal_list.to_param, :desktop_journal_list => {'these' => 'params'}}, valid_session + end + + it "assigns the requested desktop_journal_list as @desktop_journal_list" do + journal_list = Desktop::JournalList.create! valid_attributes + put :update, {:id => journal_list.to_param, :desktop_journal_list => valid_attributes}, valid_session + assigns(:desktop_journal_list).should eq(journal_list) + end + + it "redirects to the desktop_journal_list" do + journal_list = Desktop::JournalList.create! valid_attributes + put :update, {:id => journal_list.to_param, :desktop_journal_list => valid_attributes}, valid_session + response.should redirect_to(journal_list) + end + end + + describe "with invalid params" do + it "assigns the desktop_journal_list as @desktop_journal_list" do + journal_list = Desktop::JournalList.create! valid_attributes + # Trigger the behavior that occurs when invalid params are submitted + Desktop::JournalList.any_instance.stub(:save).and_return(false) + put :update, {:id => journal_list.to_param, :desktop_journal_list => {}}, valid_session + assigns(:desktop_journal_list).should eq(journal_list) + end + + it "re-renders the 'edit' template" do + journal_list = Desktop::JournalList.create! valid_attributes + # Trigger the behavior that occurs when invalid params are submitted + Desktop::JournalList.any_instance.stub(:save).and_return(false) + put :update, {:id => journal_list.to_param, :desktop_journal_list => {}}, valid_session + response.should render_template("edit") + end + end + end + + describe "DELETE destroy" do + it "destroys the requested desktop_journal_list" do + journal_list = Desktop::JournalList.create! valid_attributes + expect { + delete :destroy, {:id => journal_list.to_param}, valid_session + }.to change(Desktop::JournalList, :count).by(-1) + end + + it "redirects to the desktop_journal_lists list" do + journal_list = Desktop::JournalList.create! valid_attributes + delete :destroy, {:id => journal_list.to_param}, valid_session + response.should redirect_to(desktop_journal_lists_url) + end + end + +end diff --git a/spec/helpers/desktop/journal_lists_helper_spec.rb b/spec/helpers/desktop/journal_lists_helper_spec.rb new file mode 100644 index 00000000..47b911a9 --- /dev/null +++ b/spec/helpers/desktop/journal_lists_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the Desktop::JournalListsHelper. For example: +# +# describe Desktop::JournalListsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# helper.concat_strings("this","that").should == "this that" +# end +# end +# end +describe Desktop::JournalListsHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/requests/desktop/desktop_journal_lists_spec.rb b/spec/requests/desktop/desktop_journal_lists_spec.rb new file mode 100644 index 00000000..c1ac52e3 --- /dev/null +++ b/spec/requests/desktop/desktop_journal_lists_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe "Desktop::JournalLists" do + describe "GET /desktop_journal_lists" do + it "works! (now write some real specs)" do + # Run the generator again with the --webrat flag if you want to use webrat methods/matchers + get desktop_journal_lists_path + response.status.should be(200) + end + end +end diff --git a/spec/routing/desktop/journal_lists_routing_spec.rb b/spec/routing/desktop/journal_lists_routing_spec.rb new file mode 100644 index 00000000..79eac59e --- /dev/null +++ b/spec/routing/desktop/journal_lists_routing_spec.rb @@ -0,0 +1,35 @@ +require "spec_helper" + +describe Desktop::JournalListsController do + describe "routing" do + + it "routes to #index" do + get("/desktop/journal_lists").should route_to("desktop/journal_lists#index") + end + + it "routes to #new" do + get("/desktop/journal_lists/new").should route_to("desktop/journal_lists#new") + end + + it "routes to #show" do + get("/desktop/journal_lists/1").should route_to("desktop/journal_lists#show", :id => "1") + end + + it "routes to #edit" do + get("/desktop/journal_lists/1/edit").should route_to("desktop/journal_lists#edit", :id => "1") + end + + it "routes to #create" do + post("/desktop/journal_lists").should route_to("desktop/journal_lists#create") + end + + it "routes to #update" do + put("/desktop/journal_lists/1").should route_to("desktop/journal_lists#update", :id => "1") + end + + it "routes to #destroy" do + delete("/desktop/journal_lists/1").should route_to("desktop/journal_lists#destroy", :id => "1") + end + + end +end diff --git a/spec/views/desktop/journal_lists/edit.html.erb_spec.rb b/spec/views/desktop/journal_lists/edit.html.erb_spec.rb new file mode 100644 index 00000000..92a7ab73 --- /dev/null +++ b/spec/views/desktop/journal_lists/edit.html.erb_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +describe "desktop/journal_lists/edit" do + before(:each) do + @desktop_journal_list = assign(:desktop_journal_list, stub_model(Desktop::JournalList)) + end + + it "renders the edit desktop_journal_list form" do + render + + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "form", :action => desktop_journal_lists_path(@desktop_journal_list), :method => "post" do + end + end +end diff --git a/spec/views/desktop/journal_lists/index.html.erb_spec.rb b/spec/views/desktop/journal_lists/index.html.erb_spec.rb new file mode 100644 index 00000000..93bfc83b --- /dev/null +++ b/spec/views/desktop/journal_lists/index.html.erb_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +describe "desktop/journal_lists/index" do + before(:each) do + assign(:desktop_journal_lists, [ + stub_model(Desktop::JournalList), + stub_model(Desktop::JournalList) + ]) + end + + it "renders a list of desktop/journal_lists" do + render + # Run the generator again with the --webrat flag if you want to use webrat matchers + end +end diff --git a/spec/views/desktop/journal_lists/new.html.erb_spec.rb b/spec/views/desktop/journal_lists/new.html.erb_spec.rb new file mode 100644 index 00000000..b9751d44 --- /dev/null +++ b/spec/views/desktop/journal_lists/new.html.erb_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +describe "desktop/journal_lists/new" do + before(:each) do + assign(:desktop_journal_list, stub_model(Desktop::JournalList).as_new_record) + end + + it "renders new desktop_journal_list form" do + render + + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "form", :action => desktop_journal_lists_path, :method => "post" do + end + end +end diff --git a/spec/views/desktop/journal_lists/show.html.erb_spec.rb b/spec/views/desktop/journal_lists/show.html.erb_spec.rb new file mode 100644 index 00000000..d18b4ece --- /dev/null +++ b/spec/views/desktop/journal_lists/show.html.erb_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +describe "desktop/journal_lists/show" do + before(:each) do + @desktop_journal_list = assign(:desktop_journal_list, stub_model(Desktop::JournalList)) + end + + it "renders attributes in

" do + render + # Run the generator again with the --webrat flag if you want to use webrat matchers + end +end