diff --git a/app/controllers/recordings_controller.rb b/app/controllers/recordings_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..b14463b43ee938e3dd7c60743c3f12d9278299b0 --- /dev/null +++ b/app/controllers/recordings_controller.rb @@ -0,0 +1,51 @@ +class RecordingsController < ApplicationController + def index + list + render :action => 'list' + end + + # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) + verify :method => :post, :only => [ :destroy, :create, :update ], + :redirect_to => { :action => :list } + + def list + @recording_pages, @recordings = paginate :recordings, :per_page => 10 + end + + def show + @recording = Recording.find(params[:id]) + end + + def new + @recording = Recording.new + end + + def create + @recording = Recording.new(params[:recording]) + if @recording.save + flash[:notice] = 'Recording was successfully created.' + redirect_to :action => 'list' + else + render :action => 'new' + end + end + + def edit + @recording = Recording.find(params[:id]) + end + + def update + @recording = Recording.find(params[:id]) + if @recording.update_attributes(params[:recording]) + flash[:notice] = 'Recording was successfully updated.' + redirect_to :action => 'show', :id => @recording + else + render :action => 'edit' + end + end + + def destroy + Recording.find(params[:id]).destroy + redirect_to :action => 'list' + end +end diff --git a/app/helpers/recordings_helper.rb b/app/helpers/recordings_helper.rb new file mode 100644 index 0000000000000000000000000000000000000000..79e5fd6f4f52c6bc0f3b6f96e2bbfbcfc1e71d1e --- /dev/null +++ b/app/helpers/recordings_helper.rb @@ -0,0 +1,2 @@ +module RecordingsHelper +end diff --git a/app/models/recording.rb b/app/models/recording.rb new file mode 100644 index 0000000000000000000000000000000000000000..38a23acee91e7c389848edce37bf8e916d990fe3 --- /dev/null +++ b/app/models/recording.rb @@ -0,0 +1,2 @@ +class Recording < ActiveRecord::Base +end diff --git a/app/views/layouts/recordings.rhtml b/app/views/layouts/recordings.rhtml new file mode 100644 index 0000000000000000000000000000000000000000..fd359113c3e2257ce43b6d48687b55597fa2e925 --- /dev/null +++ b/app/views/layouts/recordings.rhtml @@ -0,0 +1,13 @@ +<html> +<head> + <title>Recordings: <%= controller.action_name %></title> + <%= stylesheet_link_tag 'scaffold' %> +</head> +<body> + +<p style="color: green"><%= flash[:notice] %></p> + +<%= @content_for_layout %> + +</body> +</html> diff --git a/app/views/recordings/_form.rhtml b/app/views/recordings/_form.rhtml new file mode 100644 index 0000000000000000000000000000000000000000..91d7548f846b730f6cd1455aa8852a4eca17bf0e --- /dev/null +++ b/app/views/recordings/_form.rhtml @@ -0,0 +1,22 @@ +<%= error_messages_for 'recording' %> + +<!--[form:recording]--> +<p><label for="recording_cid">Cid</label><br/> +<%= text_field 'recording', 'cid' %></p> + +<p><label for="recording_from">From</label><br/> +<%= text_field 'recording', 'from' %></p> + +<p><label for="recording_when">When</label><br/> +<%= datetime_select 'recording', 'when' %></p> + +<p><label for="recording_file">File</label><br/> +<%= text_field 'recording', 'file' %></p> + +<p><label for="recording_seen">Seen</label><br/> +<%= text_field 'recording', 'seen' %></p> + +<p><label for="recording_archived">Archived</label><br/> +<%= text_field 'recording', 'archived' %></p> +<!--[eoform:recording]--> + diff --git a/app/views/recordings/edit.rhtml b/app/views/recordings/edit.rhtml new file mode 100644 index 0000000000000000000000000000000000000000..32de3c192628544baa0a22daf17c0fca0d66a601 --- /dev/null +++ b/app/views/recordings/edit.rhtml @@ -0,0 +1,9 @@ +<h1>Editing recording</h1> + +<%= start_form_tag :action => 'update', :id => @recording %> + <%= render :partial => 'form' %> + <%= submit_tag 'Edit' %> +<%= end_form_tag %> + +<%= link_to 'Show', :action => 'show', :id => @recording %> | +<%= link_to 'Back', :action => 'list' %> diff --git a/app/views/recordings/list.rhtml b/app/views/recordings/list.rhtml new file mode 100644 index 0000000000000000000000000000000000000000..a23123017b810747446887f02ac0ae26323d506e --- /dev/null +++ b/app/views/recordings/list.rhtml @@ -0,0 +1,27 @@ +<h1>Listing recordings</h1> + +<table> + <tr> + <% for column in Recording.content_columns %> + <th><%= column.human_name %></th> + <% end %> + </tr> + +<% for recording in @recordings %> + <tr> + <% for column in Recording.content_columns %> + <td><%=h recording.send(column.name) %></td> + <% end %> + <td><%= link_to 'Show', :action => 'show', :id => recording %></td> + <td><%= link_to 'Edit', :action => 'edit', :id => recording %></td> + <td><%= link_to 'Destroy', { :action => 'destroy', :id => recording }, :confirm => 'Are you sure?', :post => true %></td> + </tr> +<% end %> +</table> + +<%= link_to 'Previous page', { :page => @recording_pages.current.previous } if @recording_pages.current.previous %> +<%= link_to 'Next page', { :page => @recording_pages.current.next } if @recording_pages.current.next %> + +<br /> + +<%= link_to 'New recording', :action => 'new' %> diff --git a/app/views/recordings/new.rhtml b/app/views/recordings/new.rhtml new file mode 100644 index 0000000000000000000000000000000000000000..45b6338cb2e7c1b1cb4d1b2e9833ff936b6d354a --- /dev/null +++ b/app/views/recordings/new.rhtml @@ -0,0 +1,8 @@ +<h1>New recording</h1> + +<%= start_form_tag :action => 'create' %> + <%= render :partial => 'form' %> + <%= submit_tag "Create" %> +<%= end_form_tag %> + +<%= link_to 'Back', :action => 'list' %> diff --git a/app/views/recordings/show.rhtml b/app/views/recordings/show.rhtml new file mode 100644 index 0000000000000000000000000000000000000000..99831a679dc69f6bdebb6746e9dd5f991ecabcb3 --- /dev/null +++ b/app/views/recordings/show.rhtml @@ -0,0 +1,8 @@ +<% for column in Recording.content_columns %> +<p> + <b><%= column.human_name %>:</b> <%=h @recording.send(column.name) %> +</p> +<% end %> + +<%= link_to 'Edit', :action => 'edit', :id => @recording %> | +<%= link_to 'Back', :action => 'list' %> diff --git a/test/fixtures/recordings.yml b/test/fixtures/recordings.yml new file mode 100644 index 0000000000000000000000000000000000000000..8794d28ae419929e241d892341c7429b84e5c74e --- /dev/null +++ b/test/fixtures/recordings.yml @@ -0,0 +1,5 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html +first: + id: 1 +another: + id: 2 diff --git a/test/functional/recordings_controller_test.rb b/test/functional/recordings_controller_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..1df69f194389e01237ccf2bbf4a4ba97959052a8 --- /dev/null +++ b/test/functional/recordings_controller_test.rb @@ -0,0 +1,88 @@ +require File.dirname(__FILE__) + '/../test_helper' +require 'recordings_controller' + +# Re-raise errors caught by the controller. +class RecordingsController; def rescue_action(e) raise e end; end + +class RecordingsControllerTest < Test::Unit::TestCase + fixtures :recordings + + def setup + @controller = RecordingsController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + end + + def test_index + get :index + assert_response :success + assert_template 'list' + end + + def test_list + get :list + + assert_response :success + assert_template 'list' + + assert_not_nil assigns(:recordings) + end + + def test_show + get :show, :id => 1 + + assert_response :success + assert_template 'show' + + assert_not_nil assigns(:recording) + assert assigns(:recording).valid? + end + + def test_new + get :new + + assert_response :success + assert_template 'new' + + assert_not_nil assigns(:recording) + end + + def test_create + num_recordings = Recording.count + + post :create, :recording => {} + + assert_response :redirect + assert_redirected_to :action => 'list' + + assert_equal num_recordings + 1, Recording.count + end + + def test_edit + get :edit, :id => 1 + + assert_response :success + assert_template 'edit' + + assert_not_nil assigns(:recording) + assert assigns(:recording).valid? + end + + def test_update + post :update, :id => 1 + assert_response :redirect + assert_redirected_to :action => 'show', :id => 1 + end + + def test_destroy + assert_not_nil Recording.find(1) + + post :destroy, :id => 1 + assert_response :redirect + assert_redirected_to :action => 'list' + + assert_raise(ActiveRecord::RecordNotFound) { + Recording.find(1) + } + end +end diff --git a/test/unit/recording_test.rb b/test/unit/recording_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..389e702621f495afee32bd3f8ac900d348ebc14b --- /dev/null +++ b/test/unit/recording_test.rb @@ -0,0 +1,10 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class RecordingTest < Test::Unit::TestCase + fixtures :recordings + + # Replace this with your real tests. + def test_truth + assert true + end +end