forked from bofh/fetsite
calendar feature generiert
This commit is contained in:
3
app/assets/javascripts/calendars.js.coffee
Normal file
3
app/assets/javascripts/calendars.js.coffee
Normal file
@@ -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/
|
||||
3
app/assets/javascripts/calentries.js.coffee
Normal file
3
app/assets/javascripts/calentries.js.coffee
Normal file
@@ -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/
|
||||
3
app/assets/stylesheets/calendars.css.scss
Normal file
3
app/assets/stylesheets/calendars.css.scss
Normal file
@@ -0,0 +1,3 @@
|
||||
// Place all the styles related to the calendars controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
3
app/assets/stylesheets/calentries.css.scss
Normal file
3
app/assets/stylesheets/calentries.css.scss
Normal file
@@ -0,0 +1,3 @@
|
||||
// Place all the styles related to the calentries controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
83
app/controllers/calendars_controller.rb
Normal file
83
app/controllers/calendars_controller.rb
Normal file
@@ -0,0 +1,83 @@
|
||||
class CalendarsController < ApplicationController
|
||||
# GET /calendars
|
||||
# GET /calendars.json
|
||||
def index
|
||||
@calendars = Calendar.all
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.json { render json: @calendars }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /calendars/1
|
||||
# GET /calendars/1.json
|
||||
def show
|
||||
@calendar = Calendar.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
format.json { render json: @calendar }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /calendars/new
|
||||
# GET /calendars/new.json
|
||||
def new
|
||||
@calendar = Calendar.new
|
||||
|
||||
respond_to do |format|
|
||||
format.html # new.html.erb
|
||||
format.json { render json: @calendar }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /calendars/1/edit
|
||||
def edit
|
||||
@calendar = Calendar.find(params[:id])
|
||||
end
|
||||
|
||||
# POST /calendars
|
||||
# POST /calendars.json
|
||||
def create
|
||||
@calendar = Calendar.new(params[:calendar])
|
||||
|
||||
respond_to do |format|
|
||||
if @calendar.save
|
||||
format.html { redirect_to @calendar, notice: 'Calendar was successfully created.' }
|
||||
format.json { render json: @calendar, status: :created, location: @calendar }
|
||||
else
|
||||
format.html { render action: "new" }
|
||||
format.json { render json: @calendar.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PUT /calendars/1
|
||||
# PUT /calendars/1.json
|
||||
def update
|
||||
@calendar = Calendar.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
if @calendar.update_attributes(params[:calendar])
|
||||
format.html { redirect_to @calendar, notice: 'Calendar was successfully updated.' }
|
||||
format.json { head :no_content }
|
||||
else
|
||||
format.html { render action: "edit" }
|
||||
format.json { render json: @calendar.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /calendars/1
|
||||
# DELETE /calendars/1.json
|
||||
def destroy
|
||||
@calendar = Calendar.find(params[:id])
|
||||
@calendar.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to calendars_url }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
end
|
||||
84
app/controllers/calentries_controller.rb
Normal file
84
app/controllers/calentries_controller.rb
Normal file
@@ -0,0 +1,84 @@
|
||||
class CalentriesController < ApplicationController
|
||||
# GET /calentries
|
||||
# GET /calentries.json
|
||||
def index
|
||||
@calentries = Calentry.all
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.json { render json: @calentries }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /calentries/1
|
||||
# GET /calentries/1.json
|
||||
def show
|
||||
@calentry = Calentry.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
format.json { render json: @calentry }
|
||||
format.ics { render 'show.ics.erb',}
|
||||
end
|
||||
end
|
||||
|
||||
# GET /calentries/new
|
||||
# GET /calentries/new.json
|
||||
def new
|
||||
@calentry = Calentry.new
|
||||
|
||||
respond_to do |format|
|
||||
format.html # new.html.erb
|
||||
format.json { render json: @calentry }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /calentries/1/edit
|
||||
def edit
|
||||
@calentry = Calentry.find(params[:id])
|
||||
end
|
||||
|
||||
# POST /calentries
|
||||
# POST /calentries.json
|
||||
def create
|
||||
@calentry = Calentry.new(params[:calentry])
|
||||
|
||||
respond_to do |format|
|
||||
if @calentry.save
|
||||
format.html { redirect_to @calentry, notice: 'Calentry was successfully created.' }
|
||||
format.json { render json: @calentry, status: :created, location: @calentry }
|
||||
else
|
||||
format.html { render action: "new" }
|
||||
format.json { render json: @calentry.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PUT /calentries/1
|
||||
# PUT /calentries/1.json
|
||||
def update
|
||||
@calentry = Calentry.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
if @calentry.update_attributes(params[:calentry])
|
||||
format.html { redirect_to @calentry, notice: 'Calentry was successfully updated.' }
|
||||
format.json { head :no_content }
|
||||
else
|
||||
format.html { render action: "edit" }
|
||||
format.json { render json: @calentry.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /calentries/1
|
||||
# DELETE /calentries/1.json
|
||||
def destroy
|
||||
@calentry = Calentry.find(params[:id])
|
||||
@calentry.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to calentries_url }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
end
|
||||
2
app/helpers/calendars_helper.rb
Normal file
2
app/helpers/calendars_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module CalendarsHelper
|
||||
end
|
||||
2
app/helpers/calentries_helper.rb
Normal file
2
app/helpers/calentries_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module CalentriesHelper
|
||||
end
|
||||
3
app/models/calendar.rb
Normal file
3
app/models/calendar.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class Calendar < ActiveRecord::Base
|
||||
attr_accessible :name, :public
|
||||
end
|
||||
4
app/models/calentry.rb
Normal file
4
app/models/calentry.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
class Calentry < ActiveRecord::Base
|
||||
attr_accessible :ende, :start, :summary, :typ
|
||||
|
||||
end
|
||||
10
app/views/calendars/_form.html.erb
Normal file
10
app/views/calendars/_form.html.erb
Normal file
@@ -0,0 +1,10 @@
|
||||
<%= semantic_form_for @calendar do |f| %>
|
||||
<%= f.inputs do %>
|
||||
<%= f.input :name %>
|
||||
<%= f.input :public %>
|
||||
<% end %>
|
||||
|
||||
<%= f.actions do %>
|
||||
<%= f.action :submit, :as => :input %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
6
app/views/calendars/edit.html.erb
Normal file
6
app/views/calendars/edit.html.erb
Normal file
@@ -0,0 +1,6 @@
|
||||
<h1>Editing calendar</h1>
|
||||
|
||||
<%= render 'form' %>
|
||||
|
||||
<%= link_to 'Show', @calendar %> |
|
||||
<%= link_to 'Back', calendars_path %>
|
||||
25
app/views/calendars/index.html.erb
Normal file
25
app/views/calendars/index.html.erb
Normal file
@@ -0,0 +1,25 @@
|
||||
<h1>Listing calendars</h1>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Public</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
|
||||
<% @calendars.each do |calendar| %>
|
||||
<tr>
|
||||
<td><%= calendar.name %></td>
|
||||
<td><%= calendar.public %></td>
|
||||
<td><%= link_to 'Show', calendar %></td>
|
||||
<td><%= link_to 'Edit', edit_calendar_path(calendar) %></td>
|
||||
<td><%= link_to 'Destroy', calendar, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<br />
|
||||
|
||||
<%= link_to 'New Calendar', new_calendar_path %>
|
||||
5
app/views/calendars/new.html.erb
Normal file
5
app/views/calendars/new.html.erb
Normal file
@@ -0,0 +1,5 @@
|
||||
<h1>New calendar</h1>
|
||||
|
||||
<%= render 'form' %>
|
||||
|
||||
<%= link_to 'Back', calendars_path %>
|
||||
15
app/views/calendars/show.html.erb
Normal file
15
app/views/calendars/show.html.erb
Normal file
@@ -0,0 +1,15 @@
|
||||
<p id="notice"><%= notice %></p>
|
||||
|
||||
<p>
|
||||
<b>Name:</b>
|
||||
<%= @calendar.name %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Public:</b>
|
||||
<%= @calendar.public %>
|
||||
</p>
|
||||
|
||||
|
||||
<%= link_to 'Edit', edit_calendar_path(@calendar) %> |
|
||||
<%= link_to 'Back', calendars_path %>
|
||||
12
app/views/calentries/_form.html.erb
Normal file
12
app/views/calentries/_form.html.erb
Normal file
@@ -0,0 +1,12 @@
|
||||
<%= semantic_form_for @calentry do |f| %>
|
||||
<%= f.inputs do %>
|
||||
<%= f.input :start %>
|
||||
<%= f.input :ende %>
|
||||
<%= f.input :summary %>
|
||||
<%= f.input :typ %>
|
||||
<% end %>
|
||||
|
||||
<%= f.actions do %>
|
||||
<%= f.action :submit, :as => :input %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
6
app/views/calentries/edit.html.erb
Normal file
6
app/views/calentries/edit.html.erb
Normal file
@@ -0,0 +1,6 @@
|
||||
<h1>Editing calentry</h1>
|
||||
|
||||
<%= render 'form' %>
|
||||
|
||||
<%= link_to 'Show', @calentry %> |
|
||||
<%= link_to 'Back', calentries_path %>
|
||||
29
app/views/calentries/index.html.erb
Normal file
29
app/views/calentries/index.html.erb
Normal file
@@ -0,0 +1,29 @@
|
||||
<h1>Listing calentries</h1>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>Start</th>
|
||||
<th>Ende</th>
|
||||
<th>Summary</th>
|
||||
<th>Typ</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
|
||||
<% @calentries.each do |calentry| %>
|
||||
<tr>
|
||||
<td><%= calentry.start %></td>
|
||||
<td><%= calentry.ende %></td>
|
||||
<td><%= calentry.summary %></td>
|
||||
<td><%= calentry.typ %></td>
|
||||
<td><%= link_to 'Show', calentry %></td>
|
||||
<td><%= link_to 'Edit', edit_calentry_path(calentry) %></td>
|
||||
<td><%= link_to 'Destroy', calentry, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<br />
|
||||
|
||||
<%= link_to 'New Calentry', new_calentry_path %>
|
||||
5
app/views/calentries/new.html.erb
Normal file
5
app/views/calentries/new.html.erb
Normal file
@@ -0,0 +1,5 @@
|
||||
<h1>New calentry</h1>
|
||||
|
||||
<%= render 'form' %>
|
||||
|
||||
<%= link_to 'Back', calentries_path %>
|
||||
25
app/views/calentries/show.html.erb
Normal file
25
app/views/calentries/show.html.erb
Normal file
@@ -0,0 +1,25 @@
|
||||
<p id="notice"><%= notice %></p>
|
||||
|
||||
<p>
|
||||
<b>Start:</b>
|
||||
<%= @calentry.start %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Ende:</b>
|
||||
<%= @calentry.ende %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Summary:</b>
|
||||
<%= @calentry.summary %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Typ:</b>
|
||||
<%= @calentry.typ %>
|
||||
</p>
|
||||
|
||||
|
||||
<%= link_to 'Edit', edit_calentry_path(@calentry) %> |
|
||||
<%= link_to 'Back', calentries_path %>
|
||||
25
app/views/calentries/show.ics.erb
Normal file
25
app/views/calentries/show.ics.erb
Normal file
@@ -0,0 +1,25 @@
|
||||
<p id="notice"><%= notice %></p>
|
||||
|
||||
<p>
|
||||
<b>Start:</b>
|
||||
<%= @calentry.start %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Ende:</b>
|
||||
<%= @calentry.ende %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Summary:</b>
|
||||
<%= @calentry.summary %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Typ:</b>
|
||||
<%= @calentry.typ %>
|
||||
</p>
|
||||
|
||||
|
||||
<%= link_to 'Edit', edit_calentry_path(@calentry) %> |
|
||||
<%= link_to 'Back', calentries_path %>
|
||||
@@ -1,5 +1,11 @@
|
||||
Fetsite::Application.routes.draw do
|
||||
|
||||
resources :calendars
|
||||
|
||||
|
||||
resources :calentries
|
||||
|
||||
|
||||
devise_for :users
|
||||
resources :home, :only=>[:index]
|
||||
#get 'home',:controller=>home,:action=>:index,:as=>"home_index"
|
||||
|
||||
12
db/migrate/20130805191709_create_calentries.rb
Normal file
12
db/migrate/20130805191709_create_calentries.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
class CreateCalentries < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :calentries do |t|
|
||||
t.timestamp :start
|
||||
t.timestamp :ende
|
||||
t.string :summary
|
||||
t.integer :typ
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
10
db/migrate/20130805191817_create_calendars.rb
Normal file
10
db/migrate/20130805191817_create_calendars.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
class CreateCalendars < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :calendars do |t|
|
||||
t.string :name
|
||||
t.boolean :public
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
160
spec/controllers/calendars_controller_spec.rb
Normal file
160
spec/controllers/calendars_controller_spec.rb
Normal file
@@ -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 CalendarsController do
|
||||
|
||||
# This should return the minimal set of attributes required to create a valid
|
||||
# Calendar. As you add validations to Calendar, be sure to
|
||||
# adjust the attributes here as well.
|
||||
let(:valid_attributes) { { "name" => "MyString" } }
|
||||
|
||||
# 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
|
||||
# CalendarsController. Be sure to keep this updated too.
|
||||
let(:valid_session) { {} }
|
||||
|
||||
describe "GET index" do
|
||||
it "assigns all calendars as @calendars" do
|
||||
calendar = Calendar.create! valid_attributes
|
||||
get :index, {}, valid_session
|
||||
assigns(:calendars).should eq([calendar])
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET show" do
|
||||
it "assigns the requested calendar as @calendar" do
|
||||
calendar = Calendar.create! valid_attributes
|
||||
get :show, {:id => calendar.to_param}, valid_session
|
||||
assigns(:calendar).should eq(calendar)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET new" do
|
||||
it "assigns a new calendar as @calendar" do
|
||||
get :new, {}, valid_session
|
||||
assigns(:calendar).should be_a_new(Calendar)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET edit" do
|
||||
it "assigns the requested calendar as @calendar" do
|
||||
calendar = Calendar.create! valid_attributes
|
||||
get :edit, {:id => calendar.to_param}, valid_session
|
||||
assigns(:calendar).should eq(calendar)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST create" do
|
||||
describe "with valid params" do
|
||||
it "creates a new Calendar" do
|
||||
expect {
|
||||
post :create, {:calendar => valid_attributes}, valid_session
|
||||
}.to change(Calendar, :count).by(1)
|
||||
end
|
||||
|
||||
it "assigns a newly created calendar as @calendar" do
|
||||
post :create, {:calendar => valid_attributes}, valid_session
|
||||
assigns(:calendar).should be_a(Calendar)
|
||||
assigns(:calendar).should be_persisted
|
||||
end
|
||||
|
||||
it "redirects to the created calendar" do
|
||||
post :create, {:calendar => valid_attributes}, valid_session
|
||||
response.should redirect_to(Calendar.last)
|
||||
end
|
||||
end
|
||||
|
||||
describe "with invalid params" do
|
||||
it "assigns a newly created but unsaved calendar as @calendar" do
|
||||
# Trigger the behavior that occurs when invalid params are submitted
|
||||
Calendar.any_instance.stub(:save).and_return(false)
|
||||
post :create, {:calendar => { "name" => "invalid value" }}, valid_session
|
||||
assigns(:calendar).should be_a_new(Calendar)
|
||||
end
|
||||
|
||||
it "re-renders the 'new' template" do
|
||||
# Trigger the behavior that occurs when invalid params are submitted
|
||||
Calendar.any_instance.stub(:save).and_return(false)
|
||||
post :create, {:calendar => { "name" => "invalid value" }}, valid_session
|
||||
response.should render_template("new")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "PUT update" do
|
||||
describe "with valid params" do
|
||||
it "updates the requested calendar" do
|
||||
calendar = Calendar.create! valid_attributes
|
||||
# Assuming there are no other calendars in the database, this
|
||||
# specifies that the Calendar created on the previous line
|
||||
# receives the :update_attributes message with whatever params are
|
||||
# submitted in the request.
|
||||
Calendar.any_instance.should_receive(:update_attributes).with({ "name" => "MyString" })
|
||||
put :update, {:id => calendar.to_param, :calendar => { "name" => "MyString" }}, valid_session
|
||||
end
|
||||
|
||||
it "assigns the requested calendar as @calendar" do
|
||||
calendar = Calendar.create! valid_attributes
|
||||
put :update, {:id => calendar.to_param, :calendar => valid_attributes}, valid_session
|
||||
assigns(:calendar).should eq(calendar)
|
||||
end
|
||||
|
||||
it "redirects to the calendar" do
|
||||
calendar = Calendar.create! valid_attributes
|
||||
put :update, {:id => calendar.to_param, :calendar => valid_attributes}, valid_session
|
||||
response.should redirect_to(calendar)
|
||||
end
|
||||
end
|
||||
|
||||
describe "with invalid params" do
|
||||
it "assigns the calendar as @calendar" do
|
||||
calendar = Calendar.create! valid_attributes
|
||||
# Trigger the behavior that occurs when invalid params are submitted
|
||||
Calendar.any_instance.stub(:save).and_return(false)
|
||||
put :update, {:id => calendar.to_param, :calendar => { "name" => "invalid value" }}, valid_session
|
||||
assigns(:calendar).should eq(calendar)
|
||||
end
|
||||
|
||||
it "re-renders the 'edit' template" do
|
||||
calendar = Calendar.create! valid_attributes
|
||||
# Trigger the behavior that occurs when invalid params are submitted
|
||||
Calendar.any_instance.stub(:save).and_return(false)
|
||||
put :update, {:id => calendar.to_param, :calendar => { "name" => "invalid value" }}, valid_session
|
||||
response.should render_template("edit")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE destroy" do
|
||||
it "destroys the requested calendar" do
|
||||
calendar = Calendar.create! valid_attributes
|
||||
expect {
|
||||
delete :destroy, {:id => calendar.to_param}, valid_session
|
||||
}.to change(Calendar, :count).by(-1)
|
||||
end
|
||||
|
||||
it "redirects to the calendars list" do
|
||||
calendar = Calendar.create! valid_attributes
|
||||
delete :destroy, {:id => calendar.to_param}, valid_session
|
||||
response.should redirect_to(calendars_url)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
160
spec/controllers/calentries_controller_spec.rb
Normal file
160
spec/controllers/calentries_controller_spec.rb
Normal file
@@ -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 CalentriesController do
|
||||
|
||||
# This should return the minimal set of attributes required to create a valid
|
||||
# Calentry. As you add validations to Calentry, be sure to
|
||||
# adjust the attributes here as well.
|
||||
let(:valid_attributes) { { "start" => "2013-08-05 21:17:10" } }
|
||||
|
||||
# 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
|
||||
# CalentriesController. Be sure to keep this updated too.
|
||||
let(:valid_session) { {} }
|
||||
|
||||
describe "GET index" do
|
||||
it "assigns all calentries as @calentries" do
|
||||
calentry = Calentry.create! valid_attributes
|
||||
get :index, {}, valid_session
|
||||
assigns(:calentries).should eq([calentry])
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET show" do
|
||||
it "assigns the requested calentry as @calentry" do
|
||||
calentry = Calentry.create! valid_attributes
|
||||
get :show, {:id => calentry.to_param}, valid_session
|
||||
assigns(:calentry).should eq(calentry)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET new" do
|
||||
it "assigns a new calentry as @calentry" do
|
||||
get :new, {}, valid_session
|
||||
assigns(:calentry).should be_a_new(Calentry)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET edit" do
|
||||
it "assigns the requested calentry as @calentry" do
|
||||
calentry = Calentry.create! valid_attributes
|
||||
get :edit, {:id => calentry.to_param}, valid_session
|
||||
assigns(:calentry).should eq(calentry)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST create" do
|
||||
describe "with valid params" do
|
||||
it "creates a new Calentry" do
|
||||
expect {
|
||||
post :create, {:calentry => valid_attributes}, valid_session
|
||||
}.to change(Calentry, :count).by(1)
|
||||
end
|
||||
|
||||
it "assigns a newly created calentry as @calentry" do
|
||||
post :create, {:calentry => valid_attributes}, valid_session
|
||||
assigns(:calentry).should be_a(Calentry)
|
||||
assigns(:calentry).should be_persisted
|
||||
end
|
||||
|
||||
it "redirects to the created calentry" do
|
||||
post :create, {:calentry => valid_attributes}, valid_session
|
||||
response.should redirect_to(Calentry.last)
|
||||
end
|
||||
end
|
||||
|
||||
describe "with invalid params" do
|
||||
it "assigns a newly created but unsaved calentry as @calentry" do
|
||||
# Trigger the behavior that occurs when invalid params are submitted
|
||||
Calentry.any_instance.stub(:save).and_return(false)
|
||||
post :create, {:calentry => { "start" => "invalid value" }}, valid_session
|
||||
assigns(:calentry).should be_a_new(Calentry)
|
||||
end
|
||||
|
||||
it "re-renders the 'new' template" do
|
||||
# Trigger the behavior that occurs when invalid params are submitted
|
||||
Calentry.any_instance.stub(:save).and_return(false)
|
||||
post :create, {:calentry => { "start" => "invalid value" }}, valid_session
|
||||
response.should render_template("new")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "PUT update" do
|
||||
describe "with valid params" do
|
||||
it "updates the requested calentry" do
|
||||
calentry = Calentry.create! valid_attributes
|
||||
# Assuming there are no other calentries in the database, this
|
||||
# specifies that the Calentry created on the previous line
|
||||
# receives the :update_attributes message with whatever params are
|
||||
# submitted in the request.
|
||||
Calentry.any_instance.should_receive(:update_attributes).with({ "start" => "2013-08-05 21:17:10" })
|
||||
put :update, {:id => calentry.to_param, :calentry => { "start" => "2013-08-05 21:17:10" }}, valid_session
|
||||
end
|
||||
|
||||
it "assigns the requested calentry as @calentry" do
|
||||
calentry = Calentry.create! valid_attributes
|
||||
put :update, {:id => calentry.to_param, :calentry => valid_attributes}, valid_session
|
||||
assigns(:calentry).should eq(calentry)
|
||||
end
|
||||
|
||||
it "redirects to the calentry" do
|
||||
calentry = Calentry.create! valid_attributes
|
||||
put :update, {:id => calentry.to_param, :calentry => valid_attributes}, valid_session
|
||||
response.should redirect_to(calentry)
|
||||
end
|
||||
end
|
||||
|
||||
describe "with invalid params" do
|
||||
it "assigns the calentry as @calentry" do
|
||||
calentry = Calentry.create! valid_attributes
|
||||
# Trigger the behavior that occurs when invalid params are submitted
|
||||
Calentry.any_instance.stub(:save).and_return(false)
|
||||
put :update, {:id => calentry.to_param, :calentry => { "start" => "invalid value" }}, valid_session
|
||||
assigns(:calentry).should eq(calentry)
|
||||
end
|
||||
|
||||
it "re-renders the 'edit' template" do
|
||||
calentry = Calentry.create! valid_attributes
|
||||
# Trigger the behavior that occurs when invalid params are submitted
|
||||
Calentry.any_instance.stub(:save).and_return(false)
|
||||
put :update, {:id => calentry.to_param, :calentry => { "start" => "invalid value" }}, valid_session
|
||||
response.should render_template("edit")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE destroy" do
|
||||
it "destroys the requested calentry" do
|
||||
calentry = Calentry.create! valid_attributes
|
||||
expect {
|
||||
delete :destroy, {:id => calentry.to_param}, valid_session
|
||||
}.to change(Calentry, :count).by(-1)
|
||||
end
|
||||
|
||||
it "redirects to the calentries list" do
|
||||
calentry = Calentry.create! valid_attributes
|
||||
delete :destroy, {:id => calentry.to_param}, valid_session
|
||||
response.should redirect_to(calentries_url)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
8
spec/factories/calendars.rb
Normal file
8
spec/factories/calendars.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
# Read about factories at https://github.com/thoughtbot/factory_girl
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :calendar do
|
||||
name "MyString"
|
||||
public false
|
||||
end
|
||||
end
|
||||
10
spec/factories/calentries.rb
Normal file
10
spec/factories/calentries.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
# Read about factories at https://github.com/thoughtbot/factory_girl
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :calentry do
|
||||
start "2013-08-05 21:17:10"
|
||||
ende "2013-08-05 21:17:10"
|
||||
summary "MyString"
|
||||
typ 1
|
||||
end
|
||||
end
|
||||
15
spec/helpers/calendars_helper_spec.rb
Normal file
15
spec/helpers/calendars_helper_spec.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
require 'spec_helper'
|
||||
|
||||
# Specs in this file have access to a helper object that includes
|
||||
# the CalendarsHelper. For example:
|
||||
#
|
||||
# describe CalendarsHelper 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 CalendarsHelper do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
15
spec/helpers/calentries_helper_spec.rb
Normal file
15
spec/helpers/calentries_helper_spec.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
require 'spec_helper'
|
||||
|
||||
# Specs in this file have access to a helper object that includes
|
||||
# the CalentriesHelper. For example:
|
||||
#
|
||||
# describe CalentriesHelper 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 CalentriesHelper do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
5
spec/models/calendar_spec.rb
Normal file
5
spec/models/calendar_spec.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Calendar do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
5
spec/models/calentry_spec.rb
Normal file
5
spec/models/calentry_spec.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Calentry do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
11
spec/requests/calendars_spec.rb
Normal file
11
spec/requests/calendars_spec.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Calendars" do
|
||||
describe "GET /calendars" 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 calendars_path
|
||||
response.status.should be(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
11
spec/requests/calentries_spec.rb
Normal file
11
spec/requests/calentries_spec.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Calentries" do
|
||||
describe "GET /calentries" 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 calentries_path
|
||||
response.status.should be(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
35
spec/routing/calendars_routing_spec.rb
Normal file
35
spec/routing/calendars_routing_spec.rb
Normal file
@@ -0,0 +1,35 @@
|
||||
require "spec_helper"
|
||||
|
||||
describe CalendarsController do
|
||||
describe "routing" do
|
||||
|
||||
it "routes to #index" do
|
||||
get("/calendars").should route_to("calendars#index")
|
||||
end
|
||||
|
||||
it "routes to #new" do
|
||||
get("/calendars/new").should route_to("calendars#new")
|
||||
end
|
||||
|
||||
it "routes to #show" do
|
||||
get("/calendars/1").should route_to("calendars#show", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #edit" do
|
||||
get("/calendars/1/edit").should route_to("calendars#edit", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #create" do
|
||||
post("/calendars").should route_to("calendars#create")
|
||||
end
|
||||
|
||||
it "routes to #update" do
|
||||
put("/calendars/1").should route_to("calendars#update", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #destroy" do
|
||||
delete("/calendars/1").should route_to("calendars#destroy", :id => "1")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
35
spec/routing/calentries_routing_spec.rb
Normal file
35
spec/routing/calentries_routing_spec.rb
Normal file
@@ -0,0 +1,35 @@
|
||||
require "spec_helper"
|
||||
|
||||
describe CalentriesController do
|
||||
describe "routing" do
|
||||
|
||||
it "routes to #index" do
|
||||
get("/calentries").should route_to("calentries#index")
|
||||
end
|
||||
|
||||
it "routes to #new" do
|
||||
get("/calentries/new").should route_to("calentries#new")
|
||||
end
|
||||
|
||||
it "routes to #show" do
|
||||
get("/calentries/1").should route_to("calentries#show", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #edit" do
|
||||
get("/calentries/1/edit").should route_to("calentries#edit", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #create" do
|
||||
post("/calentries").should route_to("calentries#create")
|
||||
end
|
||||
|
||||
it "routes to #update" do
|
||||
put("/calentries/1").should route_to("calentries#update", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #destroy" do
|
||||
delete("/calentries/1").should route_to("calentries#destroy", :id => "1")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
20
spec/views/calendars/edit.html.erb_spec.rb
Normal file
20
spec/views/calendars/edit.html.erb_spec.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "calendars/edit" do
|
||||
before(:each) do
|
||||
@calendar = assign(:calendar, stub_model(Calendar,
|
||||
:name => "MyString",
|
||||
:public => false
|
||||
))
|
||||
end
|
||||
|
||||
it "renders the edit calendar form" do
|
||||
render
|
||||
|
||||
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
||||
assert_select "form[action=?][method=?]", calendar_path(@calendar), "post" do
|
||||
assert_select "input#calendar_name[name=?]", "calendar[name]"
|
||||
assert_select "input#calendar_public[name=?]", "calendar[public]"
|
||||
end
|
||||
end
|
||||
end
|
||||
23
spec/views/calendars/index.html.erb_spec.rb
Normal file
23
spec/views/calendars/index.html.erb_spec.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "calendars/index" do
|
||||
before(:each) do
|
||||
assign(:calendars, [
|
||||
stub_model(Calendar,
|
||||
:name => "Name",
|
||||
:public => false
|
||||
),
|
||||
stub_model(Calendar,
|
||||
:name => "Name",
|
||||
:public => false
|
||||
)
|
||||
])
|
||||
end
|
||||
|
||||
it "renders a list of calendars" do
|
||||
render
|
||||
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
||||
assert_select "tr>td", :text => "Name".to_s, :count => 2
|
||||
assert_select "tr>td", :text => false.to_s, :count => 2
|
||||
end
|
||||
end
|
||||
20
spec/views/calendars/new.html.erb_spec.rb
Normal file
20
spec/views/calendars/new.html.erb_spec.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "calendars/new" do
|
||||
before(:each) do
|
||||
assign(:calendar, stub_model(Calendar,
|
||||
:name => "MyString",
|
||||
:public => false
|
||||
).as_new_record)
|
||||
end
|
||||
|
||||
it "renders new calendar form" do
|
||||
render
|
||||
|
||||
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
||||
assert_select "form[action=?][method=?]", calendars_path, "post" do
|
||||
assert_select "input#calendar_name[name=?]", "calendar[name]"
|
||||
assert_select "input#calendar_public[name=?]", "calendar[public]"
|
||||
end
|
||||
end
|
||||
end
|
||||
17
spec/views/calendars/show.html.erb_spec.rb
Normal file
17
spec/views/calendars/show.html.erb_spec.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "calendars/show" do
|
||||
before(:each) do
|
||||
@calendar = assign(:calendar, stub_model(Calendar,
|
||||
:name => "Name",
|
||||
:public => false
|
||||
))
|
||||
end
|
||||
|
||||
it "renders attributes in <p>" do
|
||||
render
|
||||
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
||||
rendered.should match(/Name/)
|
||||
rendered.should match(/false/)
|
||||
end
|
||||
end
|
||||
20
spec/views/calentries/edit.html.erb_spec.rb
Normal file
20
spec/views/calentries/edit.html.erb_spec.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "calentries/edit" do
|
||||
before(:each) do
|
||||
@calentry = assign(:calentry, stub_model(Calentry,
|
||||
:summary => "MyString",
|
||||
:typ => 1
|
||||
))
|
||||
end
|
||||
|
||||
it "renders the edit calentry form" do
|
||||
render
|
||||
|
||||
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
||||
assert_select "form[action=?][method=?]", calentry_path(@calentry), "post" do
|
||||
assert_select "input#calentry_summary[name=?]", "calentry[summary]"
|
||||
assert_select "input#calentry_typ[name=?]", "calentry[typ]"
|
||||
end
|
||||
end
|
||||
end
|
||||
23
spec/views/calentries/index.html.erb_spec.rb
Normal file
23
spec/views/calentries/index.html.erb_spec.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "calentries/index" do
|
||||
before(:each) do
|
||||
assign(:calentries, [
|
||||
stub_model(Calentry,
|
||||
:summary => "Summary",
|
||||
:typ => 1
|
||||
),
|
||||
stub_model(Calentry,
|
||||
:summary => "Summary",
|
||||
:typ => 1
|
||||
)
|
||||
])
|
||||
end
|
||||
|
||||
it "renders a list of calentries" do
|
||||
render
|
||||
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
||||
assert_select "tr>td", :text => "Summary".to_s, :count => 2
|
||||
assert_select "tr>td", :text => 1.to_s, :count => 2
|
||||
end
|
||||
end
|
||||
20
spec/views/calentries/new.html.erb_spec.rb
Normal file
20
spec/views/calentries/new.html.erb_spec.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "calentries/new" do
|
||||
before(:each) do
|
||||
assign(:calentry, stub_model(Calentry,
|
||||
:summary => "MyString",
|
||||
:typ => 1
|
||||
).as_new_record)
|
||||
end
|
||||
|
||||
it "renders new calentry form" do
|
||||
render
|
||||
|
||||
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
||||
assert_select "form[action=?][method=?]", calentries_path, "post" do
|
||||
assert_select "input#calentry_summary[name=?]", "calentry[summary]"
|
||||
assert_select "input#calentry_typ[name=?]", "calentry[typ]"
|
||||
end
|
||||
end
|
||||
end
|
||||
17
spec/views/calentries/show.html.erb_spec.rb
Normal file
17
spec/views/calentries/show.html.erb_spec.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "calentries/show" do
|
||||
before(:each) do
|
||||
@calentry = assign(:calentry, stub_model(Calentry,
|
||||
:summary => "Summary",
|
||||
:typ => 1
|
||||
))
|
||||
end
|
||||
|
||||
it "renders attributes in <p>" do
|
||||
render
|
||||
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
||||
rendered.should match(/Summary/)
|
||||
rendered.should match(/1/)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user