Skip to content

Commit

Permalink
Adding 'PublicContent'
Browse files Browse the repository at this point in the history
  • Loading branch information
TuckerJD committed Jun 5, 2014
1 parent df0f822 commit c5973ea
Show file tree
Hide file tree
Showing 20 changed files with 407 additions and 6 deletions.
3 changes: 3 additions & 0 deletions app/assets/javascripts/public_contents.js.coffee
@@ -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://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/public_contents.css.scss
@@ -0,0 +1,3 @@
// Place all the styles related to the PublicContents controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
74 changes: 74 additions & 0 deletions app/controllers/public_contents_controller.rb
@@ -0,0 +1,74 @@
class PublicContentsController < ApplicationController
before_action :set_public_content, only: [:show, :edit, :update, :destroy]

# GET /public_contents
# GET /public_contents.json
def index
@public_contents = PublicContent.all
end

# GET /public_contents/1
# GET /public_contents/1.json
def show
end

# GET /public_contents/new
def new
@public_content = PublicContent.new
end

# GET /public_contents/1/edit
def edit
end

# POST /public_contents
# POST /public_contents.json
def create
@public_content = PublicContent.new(public_content_params)

respond_to do |format|
if @public_content.save
format.html { redirect_to @public_content, notice: 'Public content was successfully created.' }
format.json { render :show, status: :created, location: @public_content }
else
format.html { render :new }
format.json { render json: @public_content.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /public_contents/1
# PATCH/PUT /public_contents/1.json
def update
respond_to do |format|
if @public_content.update(public_content_params)
format.html { redirect_to @public_content, notice: 'Public content was successfully updated.' }
format.json { render :show, status: :ok, location: @public_content }
else
format.html { render :edit }
format.json { render json: @public_content.errors, status: :unprocessable_entity }
end
end
end

# DELETE /public_contents/1
# DELETE /public_contents/1.json
def destroy
@public_content.destroy
respond_to do |format|
format.html { redirect_to public_contents_url }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_public_content
@public_content = PublicContent.find(params[:id])
end

# Never trust parameters from the scary internet, only allow the white list through.
def public_content_params
params[:public_content]
end
end
2 changes: 2 additions & 0 deletions app/helpers/public_contents_helper.rb
@@ -0,0 +1,2 @@
module PublicContentsHelper
end
6 changes: 6 additions & 0 deletions app/views/public_contents/edit.html.erb
@@ -0,0 +1,6 @@
<h1>Editing public_content</h1>

<%= render 'form' %>
<%= link_to 'Show', @public_content %> |
<%= link_to 'Back', public_contents_path %>
25 changes: 25 additions & 0 deletions app/views/public_contents/index.html.erb
@@ -0,0 +1,25 @@
<h1>Listing public_contents</h1>

<table>
<thead>
<tr>
<th></th>
<th></th>
<th></th>
</tr>
</thead>

<tbody>
<% @public_contents.each do |public_content| %>
<tr>
<td><%= link_to 'Show', public_content %></td>
<td><%= link_to 'Edit', edit_public_content_path(public_content) %></td>
<td><%= link_to 'Destroy', public_content, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>

<br>

<%= link_to 'New Public content', new_public_content_path %>
4 changes: 4 additions & 0 deletions app/views/public_contents/index.json.jbuilder
@@ -0,0 +1,4 @@
json.array!(@public_contents) do |public_content|
json.extract! public_content, :id
json.url public_content_url(public_content, format: :json)
end
5 changes: 5 additions & 0 deletions app/views/public_contents/new.html.erb
@@ -0,0 +1,5 @@
<h1>New public_content</h1>

<%= render 'form' %>
<%= link_to 'Back', public_contents_path %>
4 changes: 4 additions & 0 deletions app/views/public_contents/show.html.erb
@@ -0,0 +1,4 @@
<p id="notice"><%= notice %></p>

<%= link_to 'Edit', edit_public_content_path(@public_content) %> |
<%= link_to 'Back', public_contents_path %>
1 change: 1 addition & 0 deletions app/views/public_contents/show.json.jbuilder
@@ -0,0 +1 @@
json.extract! @public_content, :id, :created_at, :updated_at
2 changes: 2 additions & 0 deletions config/routes.rb
@@ -1,4 +1,6 @@
TaxonWorks::Application.routes.draw do
resources :public_contents

resources :contents

# The priority is based upon order of creation: first created -> highest priority.
Expand Down
160 changes: 160 additions & 0 deletions spec/controllers/public_contents_controller_spec.rb
@@ -0,0 +1,160 @@
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 PublicContentsController do

# This should return the minimal set of attributes required to create a valid
# PublicContent. As you add validations to PublicContent, be sure to
# adjust the attributes here as well.
let(:valid_attributes) { { } }

# 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
# PublicContentsController. Be sure to keep this updated too.
let(:valid_session) { {} }

describe "GET index" do
it "assigns all public_contents as @public_contents" do
public_content = PublicContent.create! valid_attributes
get :index, {}, valid_session
assigns(:public_contents).should eq([public_content])
end
end

describe "GET show" do
it "assigns the requested public_content as @public_content" do
public_content = PublicContent.create! valid_attributes
get :show, {:id => public_content.to_param}, valid_session
assigns(:public_content).should eq(public_content)
end
end

describe "GET new" do
it "assigns a new public_content as @public_content" do
get :new, {}, valid_session
assigns(:public_content).should be_a_new(PublicContent)
end
end

describe "GET edit" do
it "assigns the requested public_content as @public_content" do
public_content = PublicContent.create! valid_attributes
get :edit, {:id => public_content.to_param}, valid_session
assigns(:public_content).should eq(public_content)
end
end

describe "POST create" do
describe "with valid params" do
it "creates a new PublicContent" do
expect {
post :create, {:public_content => valid_attributes}, valid_session
}.to change(PublicContent, :count).by(1)
end

it "assigns a newly created public_content as @public_content" do
post :create, {:public_content => valid_attributes}, valid_session
assigns(:public_content).should be_a(PublicContent)
assigns(:public_content).should be_persisted
end

it "redirects to the created public_content" do
post :create, {:public_content => valid_attributes}, valid_session
response.should redirect_to(PublicContent.last)
end
end

describe "with invalid params" do
it "assigns a newly created but unsaved public_content as @public_content" do
# Trigger the behavior that occurs when invalid params are submitted
PublicContent.any_instance.stub(:save).and_return(false)
post :create, {:public_content => { }}, valid_session
assigns(:public_content).should be_a_new(PublicContent)
end

it "re-renders the 'new' template" do
# Trigger the behavior that occurs when invalid params are submitted
PublicContent.any_instance.stub(:save).and_return(false)
post :create, {:public_content => { }}, valid_session
response.should render_template("new")
end
end
end

describe "PUT update" do
describe "with valid params" do
it "updates the requested public_content" do
public_content = PublicContent.create! valid_attributes
# Assuming there are no other public_contents in the database, this
# specifies that the PublicContent created on the previous line
# receives the :update_attributes message with whatever params are
# submitted in the request.
PublicContent.any_instance.should_receive(:update).with({ "these" => "params" })
put :update, {:id => public_content.to_param, :public_content => { "these" => "params" }}, valid_session
end

it "assigns the requested public_content as @public_content" do
public_content = PublicContent.create! valid_attributes
put :update, {:id => public_content.to_param, :public_content => valid_attributes}, valid_session
assigns(:public_content).should eq(public_content)
end

it "redirects to the public_content" do
public_content = PublicContent.create! valid_attributes
put :update, {:id => public_content.to_param, :public_content => valid_attributes}, valid_session
response.should redirect_to(public_content)
end
end

describe "with invalid params" do
it "assigns the public_content as @public_content" do
public_content = PublicContent.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
PublicContent.any_instance.stub(:save).and_return(false)
put :update, {:id => public_content.to_param, :public_content => { }}, valid_session
assigns(:public_content).should eq(public_content)
end

it "re-renders the 'edit' template" do
public_content = PublicContent.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
PublicContent.any_instance.stub(:save).and_return(false)
put :update, {:id => public_content.to_param, :public_content => { }}, valid_session
response.should render_template("edit")
end
end
end

describe "DELETE destroy" do
it "destroys the requested public_content" do
public_content = PublicContent.create! valid_attributes
expect {
delete :destroy, {:id => public_content.to_param}, valid_session
}.to change(PublicContent, :count).by(-1)
end

it "redirects to the public_contents list" do
public_content = PublicContent.create! valid_attributes
delete :destroy, {:id => public_content.to_param}, valid_session
response.should redirect_to(public_contents_url)
end
end

end
6 changes: 0 additions & 6 deletions spec/factories/contents_factory.rb

This file was deleted.

11 changes: 11 additions & 0 deletions spec/features/public_contents_spec.rb
@@ -0,0 +1,11 @@
require 'spec_helper'

describe "PublicContents" do
describe "GET /public_contents" 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 public_contents_path
response.status.should be(200)
end
end
end
15 changes: 15 additions & 0 deletions spec/helpers/public_contents_helper_spec.rb
@@ -0,0 +1,15 @@
require 'spec_helper'

# Specs in this file have access to a helper object that includes
# the PublicContentsHelper. For example:
#
# describe PublicContentsHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
describe PublicContentsHelper do
pending "add some examples to (or delete) #{__FILE__}"
end
35 changes: 35 additions & 0 deletions spec/routing/public_contents_routing_spec.rb
@@ -0,0 +1,35 @@
require "spec_helper"

describe PublicContentsController do
describe "routing" do

it "routes to #index" do
get("/public_contents").should route_to("public_contents#index")
end

it "routes to #new" do
get("/public_contents/new").should route_to("public_contents#new")
end

it "routes to #show" do
get("/public_contents/1").should route_to("public_contents#show", :id => "1")
end

it "routes to #edit" do
get("/public_contents/1/edit").should route_to("public_contents#edit", :id => "1")
end

it "routes to #create" do
post("/public_contents").should route_to("public_contents#create")
end

it "routes to #update" do
put("/public_contents/1").should route_to("public_contents#update", :id => "1")
end

it "routes to #destroy" do
delete("/public_contents/1").should route_to("public_contents#destroy", :id => "1")
end

end
end
15 changes: 15 additions & 0 deletions spec/views/public_contents/edit.html.erb_spec.rb
@@ -0,0 +1,15 @@
require 'spec_helper'

describe "public_contents/edit" do
before(:each) do
@public_content = assign(:public_content, stub_model(PublicContent))
end

it "renders the edit public_content form" do
render

# Run the generator again with the --webrat flag if you want to use webrat matchers
assert_select "form[action=?][method=?]", public_content_path(@public_content), "post" do
end
end
end

0 comments on commit c5973ea

Please sign in to comment.