Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
407 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module PublicContentsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1>Editing public_content</h1> | ||
|
||
<%= render 'form' %> | ||
<%= link_to 'Show', @public_content %> | | ||
<%= link_to 'Back', public_contents_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<h1>New public_content</h1> | ||
|
||
<%= render 'form' %> | ||
<%= link_to 'Back', public_contents_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<p id="notice"><%= notice %></p> | ||
|
||
<%= link_to 'Edit', edit_public_content_path(@public_content) %> | | ||
<%= link_to 'Back', public_contents_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.extract! @public_content, :id, :created_at, :updated_at |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.