diff --git a/app/controllers/citations_controller.rb b/app/controllers/citations_controller.rb new file mode 100644 index 0000000..65f6657 --- /dev/null +++ b/app/controllers/citations_controller.rb @@ -0,0 +1,85 @@ +class CitationsController < ApplicationController + # GET /citations + # GET /citations.xml + def index + @citations = Citation.all + + respond_to do |format| + format.html # index.html.erb + format.xml { render :xml => @citations } + end + end + + # GET /citations/1 + # GET /citations/1.xml + def show + @citation = Citation.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.xml { render :xml => @citation } + end + end + + # GET /citations/new + # GET /citations/new.xml + def new + @citation = Citation.new + + respond_to do |format| + format.html # new.html.erb + format.xml { render :xml => @citation } + end + end + + # GET /citations/1/edit + def edit + @citation = Citation.find(params[:id]) + end + + # POST /citations + # POST /citations.xml + def create + @citation = Citation.new(params[:citation]) + + respond_to do |format| + if @citation.save + flash[:notice] = 'Citation was successfully created.' + format.html { redirect_to(@citation) } + format.xml { render :xml => @citation, :status => :created, :location => @citation } + else + format.html { render :action => "new" } + format.xml { render :xml => @citation.errors, :status => :unprocessable_entity } + end + end + end + + # PUT /citations/1 + # PUT /citations/1.xml + def update + @citation = Citation.find(params[:id]) + + respond_to do |format| + if @citation.update_attributes(params[:citation]) + flash[:notice] = 'Citation was successfully updated.' + format.html { redirect_to(@citation) } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @citation.errors, :status => :unprocessable_entity } + end + end + end + + # DELETE /citations/1 + # DELETE /citations/1.xml + def destroy + @citation = Citation.find(params[:id]) + @citation.destroy + + respond_to do |format| + format.html { redirect_to(citations_url) } + format.xml { head :ok } + end + end +end diff --git a/app/helpers/citations_helper.rb b/app/helpers/citations_helper.rb new file mode 100644 index 0000000..936ad0c --- /dev/null +++ b/app/helpers/citations_helper.rb @@ -0,0 +1,2 @@ +module CitationsHelper +end diff --git a/app/models/citation.rb b/app/models/citation.rb new file mode 100644 index 0000000..7b6c54f --- /dev/null +++ b/app/models/citation.rb @@ -0,0 +1,2 @@ +class Citation < ActiveRecord::Base +end diff --git a/app/views/citations/edit.html.erb b/app/views/citations/edit.html.erb new file mode 100644 index 0000000..de52cdc --- /dev/null +++ b/app/views/citations/edit.html.erb @@ -0,0 +1,16 @@ +

Editing citation

+ +<% form_for(@citation) do |f| %> + <%= f.error_messages %> + +

+ <%= f.label :citation %>
+ <%= f.text_area :citation %> +

+

+ <%= f.submit 'Update' %> +

+<% end %> + +<%= link_to 'Show', @citation %> | +<%= link_to 'Back', citations_path %> \ No newline at end of file diff --git a/app/views/citations/index.html.erb b/app/views/citations/index.html.erb new file mode 100644 index 0000000..0443d21 --- /dev/null +++ b/app/views/citations/index.html.erb @@ -0,0 +1,20 @@ +

Listing citations

+ + + + + + +<% @citations.each do |citation| %> + + + + + + +<% end %> +
Citation
<%=h citation.citation %><%= link_to 'Show', citation %><%= link_to 'Edit', edit_citation_path(citation) %><%= link_to 'Destroy', citation, :confirm => 'Are you sure?', :method => :delete %>
+ +
+ +<%= link_to 'New citation', new_citation_path %> \ No newline at end of file diff --git a/app/views/citations/new.html.erb b/app/views/citations/new.html.erb new file mode 100644 index 0000000..392cc45 --- /dev/null +++ b/app/views/citations/new.html.erb @@ -0,0 +1,15 @@ +

New citation

+ +<% form_for(@citation) do |f| %> + <%= f.error_messages %> + +

+ <%= f.label :citation %>
+ <%= f.text_area :citation %> +

+

+ <%= f.submit 'Create' %> +

+<% end %> + +<%= link_to 'Back', citations_path %> \ No newline at end of file diff --git a/app/views/citations/show.html.erb b/app/views/citations/show.html.erb new file mode 100644 index 0000000..dbd6dee --- /dev/null +++ b/app/views/citations/show.html.erb @@ -0,0 +1,8 @@ +

+ Citation: + <%=h @citation.citation %> +

+ + +<%= link_to 'Edit', edit_citation_path(@citation) %> | +<%= link_to 'Back', citations_path %> \ No newline at end of file diff --git a/app/views/layouts/citations.html.erb b/app/views/layouts/citations.html.erb new file mode 100644 index 0000000..ff73797 --- /dev/null +++ b/app/views/layouts/citations.html.erb @@ -0,0 +1,17 @@ + + + + + + Citations: <%= controller.action_name %> + <%= stylesheet_link_tag 'scaffold' %> + + + +

<%= flash[:notice] %>

+ +<%= yield %> + + + diff --git a/config/routes.rb b/config/routes.rb index c79c451..ccb3936 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@ ActionController::Routing::Routes.draw do |map| + map.resources :citations + map.resources :evaluations map.resources :evaluation_citations diff --git a/db/migrate/20100506192212_create_citations.rb b/db/migrate/20100506192212_create_citations.rb new file mode 100644 index 0000000..fd6dcab --- /dev/null +++ b/db/migrate/20100506192212_create_citations.rb @@ -0,0 +1,13 @@ +class CreateCitations < ActiveRecord::Migration + def self.up + create_table :citations do |t| + t.text :citation + + t.timestamps + end + end + + def self.down + drop_table :citations + end +end diff --git a/test/fixtures/citations.yml b/test/fixtures/citations.yml new file mode 100644 index 0000000..e3711ad --- /dev/null +++ b/test/fixtures/citations.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +one: + citation: MyText + +two: + citation: MyText diff --git a/test/functional/citations_controller_test.rb b/test/functional/citations_controller_test.rb new file mode 100644 index 0000000..f588d76 --- /dev/null +++ b/test/functional/citations_controller_test.rb @@ -0,0 +1,45 @@ +require 'test_helper' + +class CitationsControllerTest < ActionController::TestCase + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:citations) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create citation" do + assert_difference('Citation.count') do + post :create, :citation => { } + end + + assert_redirected_to citation_path(assigns(:citation)) + end + + test "should show citation" do + get :show, :id => citations(:one).to_param + assert_response :success + end + + test "should get edit" do + get :edit, :id => citations(:one).to_param + assert_response :success + end + + test "should update citation" do + put :update, :id => citations(:one).to_param, :citation => { } + assert_redirected_to citation_path(assigns(:citation)) + end + + test "should destroy citation" do + assert_difference('Citation.count', -1) do + delete :destroy, :id => citations(:one).to_param + end + + assert_redirected_to citations_path + end +end diff --git a/test/unit/citation_test.rb b/test/unit/citation_test.rb new file mode 100644 index 0000000..dda36eb --- /dev/null +++ b/test/unit/citation_test.rb @@ -0,0 +1,8 @@ +require 'test_helper' + +class CitationTest < ActiveSupport::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end +end diff --git a/test/unit/helpers/citations_helper_test.rb b/test/unit/helpers/citations_helper_test.rb new file mode 100644 index 0000000..6f25875 --- /dev/null +++ b/test/unit/helpers/citations_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class CitationsHelperTest < ActionView::TestCase +end