diff options
| -rw-r--r-- | app/assets/javascripts/downloads.coffee | 3 | ||||
| -rw-r--r-- | app/assets/stylesheets/downloads.scss | 3 | ||||
| -rw-r--r-- | app/assets/stylesheets/scaffolds.scss | 69 | ||||
| -rw-r--r-- | app/controllers/downloads_controller.rb | 74 | ||||
| -rw-r--r-- | app/helpers/downloads_helper.rb | 2 | ||||
| -rw-r--r-- | app/models/download.rb | 2 | ||||
| -rw-r--r-- | app/views/downloads/_form.html.erb | 37 | ||||
| -rw-r--r-- | app/views/downloads/edit.html.erb | 6 | ||||
| -rw-r--r-- | app/views/downloads/index.html.erb | 35 | ||||
| -rw-r--r-- | app/views/downloads/index.json.jbuilder | 4 | ||||
| -rw-r--r-- | app/views/downloads/new.html.erb | 5 | ||||
| -rw-r--r-- | app/views/downloads/show.html.erb | 29 | ||||
| -rw-r--r-- | app/views/downloads/show.json.jbuilder | 1 | ||||
| -rw-r--r-- | config/routes.rb | 2 | ||||
| -rw-r--r-- | db/migrate/20150226024550_create_downloads.rb | 15 | ||||
| -rw-r--r-- | test/controllers/downloads_controller_test.rb | 49 | ||||
| -rw-r--r-- | test/fixtures/downloads.yml | 15 | ||||
| -rw-r--r-- | test/models/download_test.rb | 7 | 
18 files changed, 358 insertions, 0 deletions
| diff --git a/app/assets/javascripts/downloads.coffee b/app/assets/javascripts/downloads.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/downloads.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/ diff --git a/app/assets/stylesheets/downloads.scss b/app/assets/stylesheets/downloads.scss new file mode 100644 index 0000000..e2d0260 --- /dev/null +++ b/app/assets/stylesheets/downloads.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Downloads controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/scaffolds.scss b/app/assets/stylesheets/scaffolds.scss new file mode 100644 index 0000000..6ec6a8f --- /dev/null +++ b/app/assets/stylesheets/scaffolds.scss @@ -0,0 +1,69 @@ +body { +  background-color: #fff; +  color: #333; +  font-family: verdana, arial, helvetica, sans-serif; +  font-size: 13px; +  line-height: 18px; +} + +p, ol, ul, td { +  font-family: verdana, arial, helvetica, sans-serif; +  font-size: 13px; +  line-height: 18px; +} + +pre { +  background-color: #eee; +  padding: 10px; +  font-size: 11px; +} + +a { +  color: #000; +  &:visited { +    color: #666; +  } +  &:hover { +    color: #fff; +    background-color: #000; +  } +} + +div { +  &.field, &.actions { +    margin-bottom: 10px; +  } +} + +#notice { +  color: green; +} + +.field_with_errors { +  padding: 2px; +  background-color: red; +  display: table; +} + +#error_explanation { +  width: 450px; +  border: 2px solid red; +  padding: 7px; +  padding-bottom: 0; +  margin-bottom: 20px; +  background-color: #f0f0f0; +  h2 { +    text-align: left; +    font-weight: bold; +    padding: 5px 5px 5px 15px; +    font-size: 12px; +    margin: -7px; +    margin-bottom: 0px; +    background-color: #c00; +    color: #fff; +  } +  ul li { +    font-size: 12px; +    list-style: square; +  } +} diff --git a/app/controllers/downloads_controller.rb b/app/controllers/downloads_controller.rb new file mode 100644 index 0000000..300d0b1 --- /dev/null +++ b/app/controllers/downloads_controller.rb @@ -0,0 +1,74 @@ +class DownloadsController < ApplicationController +  before_action :set_download, only: [:show, :edit, :update, :destroy] + +  # GET /downloads +  # GET /downloads.json +  def index +    @downloads = Download.all +  end + +  # GET /downloads/1 +  # GET /downloads/1.json +  def show +  end + +  # GET /downloads/new +  def new +    @download = Download.new +  end + +  # GET /downloads/1/edit +  def edit +  end + +  # POST /downloads +  # POST /downloads.json +  def create +    @download = Download.new(download_params) + +    respond_to do |format| +      if @download.save +        format.html { redirect_to @download, notice: 'Download was successfully created.' } +        format.json { render :show, status: :created, location: @download } +      else +        format.html { render :new } +        format.json { render json: @download.errors, status: :unprocessable_entity } +      end +    end +  end + +  # PATCH/PUT /downloads/1 +  # PATCH/PUT /downloads/1.json +  def update +    respond_to do |format| +      if @download.update(download_params) +        format.html { redirect_to @download, notice: 'Download was successfully updated.' } +        format.json { render :show, status: :ok, location: @download } +      else +        format.html { render :edit } +        format.json { render json: @download.errors, status: :unprocessable_entity } +      end +    end +  end + +  # DELETE /downloads/1 +  # DELETE /downloads/1.json +  def destroy +    @download.destroy +    respond_to do |format| +      format.html { redirect_to downloads_url, notice: 'Download was successfully destroyed.' } +      format.json { head :no_content } +    end +  end + +  private +    # Use callbacks to share common setup or constraints between actions. +    def set_download +      @download = Download.find(params[:id]) +    end + +    # Never trust parameters from the scary internet, only allow the white list through. +    def download_params +      params.require(:download).permit(:name, :filename, :type, :description, :hits) +    end +end diff --git a/app/helpers/downloads_helper.rb b/app/helpers/downloads_helper.rb new file mode 100644 index 0000000..c8cd007 --- /dev/null +++ b/app/helpers/downloads_helper.rb @@ -0,0 +1,2 @@ +module DownloadsHelper +end diff --git a/app/models/download.rb b/app/models/download.rb new file mode 100644 index 0000000..aa8d53f --- /dev/null +++ b/app/models/download.rb @@ -0,0 +1,2 @@ +class Download < ActiveRecord::Base +end diff --git a/app/views/downloads/_form.html.erb b/app/views/downloads/_form.html.erb new file mode 100644 index 0000000..1ab1879 --- /dev/null +++ b/app/views/downloads/_form.html.erb @@ -0,0 +1,37 @@ +<%= form_for(@download) do |f| %> +  <% if @download.errors.any? %> +    <div id="error_explanation"> +      <h2><%= pluralize(@download.errors.count, "error") %> prohibited this download from being saved:</h2> + +      <ul> +      <% @download.errors.full_messages.each do |message| %> +        <li><%= message %></li> +      <% end %> +      </ul> +    </div> +  <% end %> + +  <div class="field"> +    <%= f.label :name %><br> +    <%= f.text_field :name %> +  </div> +  <div class="field"> +    <%= f.label :filename %><br> +    <%= f.text_field :filename %> +  </div> +  <div class="field"> +    <%= f.label :type %><br> +    <%= f.text_field :type %> +  </div> +  <div class="field"> +    <%= f.label :description %><br> +    <%= f.text_area :description %> +  </div> +  <div class="field"> +    <%= f.label :hits %><br> +    <%= f.number_field :hits %> +  </div> +  <div class="actions"> +    <%= f.submit %> +  </div> +<% end %> diff --git a/app/views/downloads/edit.html.erb b/app/views/downloads/edit.html.erb new file mode 100644 index 0000000..3b57a65 --- /dev/null +++ b/app/views/downloads/edit.html.erb @@ -0,0 +1,6 @@ +<h1>Editing Download</h1> + +<%= render 'form' %> + +<%= link_to 'Show', @download %> | +<%= link_to 'Back', downloads_path %> diff --git a/app/views/downloads/index.html.erb b/app/views/downloads/index.html.erb new file mode 100644 index 0000000..c017aab --- /dev/null +++ b/app/views/downloads/index.html.erb @@ -0,0 +1,35 @@ +<p id="notice"><%= notice %></p> + +<h1>Listing Downloads</h1> + +<table> +  <thead> +    <tr> +      <th>Name</th> +      <th>Filename</th> +      <th>Type</th> +      <th>Description</th> +      <th>Hits</th> +      <th colspan="3"></th> +    </tr> +  </thead> + +  <tbody> +    <% @downloads.each do |download| %> +      <tr> +        <td><%= download.name %></td> +        <td><%= download.filename %></td> +        <td><%= download.type %></td> +        <td><%= download.description %></td> +        <td><%= download.hits %></td> +        <td><%= link_to 'Show', download %></td> +        <td><%= link_to 'Edit', edit_download_path(download) %></td> +        <td><%= link_to 'Destroy', download, method: :delete, data: { confirm: 'Are you sure?' } %></td> +      </tr> +    <% end %> +  </tbody> +</table> + +<br> + +<%= link_to 'New Download', new_download_path %> diff --git a/app/views/downloads/index.json.jbuilder b/app/views/downloads/index.json.jbuilder new file mode 100644 index 0000000..3323b04 --- /dev/null +++ b/app/views/downloads/index.json.jbuilder @@ -0,0 +1,4 @@ +json.array!(@downloads) do |download| +  json.extract! download, :id, :name, :filename, :type, :description, :hits +  json.url download_url(download, format: :json) +end diff --git a/app/views/downloads/new.html.erb b/app/views/downloads/new.html.erb new file mode 100644 index 0000000..ac31df5 --- /dev/null +++ b/app/views/downloads/new.html.erb @@ -0,0 +1,5 @@ +<h1>New Download</h1> + +<%= render 'form' %> + +<%= link_to 'Back', downloads_path %> diff --git a/app/views/downloads/show.html.erb b/app/views/downloads/show.html.erb new file mode 100644 index 0000000..276888a --- /dev/null +++ b/app/views/downloads/show.html.erb @@ -0,0 +1,29 @@ +<p id="notice"><%= notice %></p> + +<p> +  <strong>Name:</strong> +  <%= @download.name %> +</p> + +<p> +  <strong>Filename:</strong> +  <%= @download.filename %> +</p> + +<p> +  <strong>Type:</strong> +  <%= @download.type %> +</p> + +<p> +  <strong>Description:</strong> +  <%= @download.description %> +</p> + +<p> +  <strong>Hits:</strong> +  <%= @download.hits %> +</p> + +<%= link_to 'Edit', edit_download_path(@download) %> | +<%= link_to 'Back', downloads_path %> diff --git a/app/views/downloads/show.json.jbuilder b/app/views/downloads/show.json.jbuilder new file mode 100644 index 0000000..6bab62c --- /dev/null +++ b/app/views/downloads/show.json.jbuilder @@ -0,0 +1 @@ +json.extract! @download, :id, :name, :filename, :type, :description, :hits, :created_at, :updated_at diff --git a/config/routes.rb b/config/routes.rb index 3f66539..1486509 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@  Rails.application.routes.draw do +  resources :downloads +    # The priority is based upon order of creation: first created -> highest priority.    # See how all your routes lay out with "rake routes". diff --git a/db/migrate/20150226024550_create_downloads.rb b/db/migrate/20150226024550_create_downloads.rb new file mode 100644 index 0000000..4033e0c --- /dev/null +++ b/db/migrate/20150226024550_create_downloads.rb @@ -0,0 +1,15 @@ +class CreateDownloads < ActiveRecord::Migration +  def change +    create_table :downloads do |t| +      t.string :name +      t.string :filename +      t.string :type +      t.text :description +      t.integer :hits + +      t.timestamps null: false +    end +    add_index :downloads, :filename, unique: true +    add_index :downloads, :hits +  end +end diff --git a/test/controllers/downloads_controller_test.rb b/test/controllers/downloads_controller_test.rb new file mode 100644 index 0000000..f2c4719 --- /dev/null +++ b/test/controllers/downloads_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class DownloadsControllerTest < ActionController::TestCase +  setup do +    @download = downloads(:one) +  end + +  test "should get index" do +    get :index +    assert_response :success +    assert_not_nil assigns(:downloads) +  end + +  test "should get new" do +    get :new +    assert_response :success +  end + +  test "should create download" do +    assert_difference('Download.count') do +      post :create, download: { description: @download.description, filename: @download.filename, hits: @download.hits, name: @download.name, type: @download.type } +    end + +    assert_redirected_to download_path(assigns(:download)) +  end + +  test "should show download" do +    get :show, id: @download +    assert_response :success +  end + +  test "should get edit" do +    get :edit, id: @download +    assert_response :success +  end + +  test "should update download" do +    patch :update, id: @download, download: { description: @download.description, filename: @download.filename, hits: @download.hits, name: @download.name, type: @download.type } +    assert_redirected_to download_path(assigns(:download)) +  end + +  test "should destroy download" do +    assert_difference('Download.count', -1) do +      delete :destroy, id: @download +    end + +    assert_redirected_to downloads_path +  end +end diff --git a/test/fixtures/downloads.yml b/test/fixtures/downloads.yml new file mode 100644 index 0000000..cfcc392 --- /dev/null +++ b/test/fixtures/downloads.yml @@ -0,0 +1,15 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: +  name: MyString +  filename: MyString +  type:  +  description: MyText +  hits: 1 + +two: +  name: MyString +  filename: MyString +  type:  +  description: MyText +  hits: 1 diff --git a/test/models/download_test.rb b/test/models/download_test.rb new file mode 100644 index 0000000..471c300 --- /dev/null +++ b/test/models/download_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class DownloadTest < ActiveSupport::TestCase +  # test "the truth" do +  #   assert true +  # end +end | 
