[23762] users/jberry/mpwa

source_changes at macosforge.org source_changes at macosforge.org
Sun Apr 8 21:30:24 PDT 2007


Revision: 23762
          http://trac.macosforge.org/projects/macports/changeset/23762
Author:   jberry at macports.org
Date:     2007-04-08 21:30:24 -0700 (Sun, 08 Apr 2007)

Log Message:
-----------
Re-add port_pkg_file with proper rails naming

Modified Paths:
--------------
    users/jberry/mpwa/app/models/port_pkg.rb

Added Paths:
-----------
    users/jberry/mpwa/app/controllers/port_pkg_file_controller.rb
    users/jberry/mpwa/app/helpers/port_pkg_file_helper.rb
    users/jberry/mpwa/app/models/port_pkg_file.rb
    users/jberry/mpwa/app/views/layouts/port_pkg_file.rhtml
    users/jberry/mpwa/app/views/port_pkg_file/
    users/jberry/mpwa/app/views/port_pkg_file/_form.rhtml
    users/jberry/mpwa/app/views/port_pkg_file/edit.rhtml
    users/jberry/mpwa/app/views/port_pkg_file/list.rhtml
    users/jberry/mpwa/app/views/port_pkg_file/new.rhtml
    users/jberry/mpwa/app/views/port_pkg_file/show.rhtml
    users/jberry/mpwa/test/fixtures/port_pkg_files.yml
    users/jberry/mpwa/test/functional/port_pkg_file_controller_test.rb
    users/jberry/mpwa/test/unit/port_pkg_file_test.rb

Added: users/jberry/mpwa/app/controllers/port_pkg_file_controller.rb
===================================================================
--- users/jberry/mpwa/app/controllers/port_pkg_file_controller.rb	                        (rev 0)
+++ users/jberry/mpwa/app/controllers/port_pkg_file_controller.rb	2007-04-09 04:30:24 UTC (rev 23762)
@@ -0,0 +1,51 @@
+class PortPkgFileController < 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
+    @port_pkg_file_pages, @port_pkg_files = paginate :port_pkg_files, :per_page => 10
+  end
+
+  def show
+    @port_pkg_file = PortPkgFile.find(params[:id])
+  end
+
+  def new
+    @port_pkg_file = PortPkgFile.new
+  end
+
+  def create
+    @port_pkg_file = PortPkgFile.new(params[:port_pkg_file])
+    if @port_pkg_file.save
+      flash[:notice] = 'PortPkgFile was successfully created.'
+      redirect_to :action => 'list'
+    else
+      render :action => 'new'
+    end
+  end
+
+  def edit
+    @port_pkg_file = PortPkgFile.find(params[:id])
+  end
+
+  def update
+    @port_pkg_file = PortPkgFile.find(params[:id])
+    if @port_pkg_file.update_attributes(params[:port_pkg_file])
+      flash[:notice] = 'PortPkgFile was successfully updated.'
+      redirect_to :action => 'show', :id => @port_pkg_file
+    else
+      render :action => 'edit'
+    end
+  end
+
+  def destroy
+    PortPkgFile.find(params[:id]).destroy
+    redirect_to :action => 'list'
+  end
+end

Added: users/jberry/mpwa/app/helpers/port_pkg_file_helper.rb
===================================================================
--- users/jberry/mpwa/app/helpers/port_pkg_file_helper.rb	                        (rev 0)
+++ users/jberry/mpwa/app/helpers/port_pkg_file_helper.rb	2007-04-09 04:30:24 UTC (rev 23762)
@@ -0,0 +1,2 @@
+module PortPkgFileHelper
+end

Modified: users/jberry/mpwa/app/models/port_pkg.rb
===================================================================
--- users/jberry/mpwa/app/models/port_pkg.rb	2007-04-09 04:21:51 UTC (rev 23761)
+++ users/jberry/mpwa/app/models/port_pkg.rb	2007-04-09 04:30:24 UTC (rev 23762)
@@ -8,7 +8,7 @@
 
     belongs_to :port
     belongs_to :submitter, :class_name => 'Person', :foreign_key => 'submitter_id'
-    has_many :files, :class_name => 'PortPkgFiles'
+    has_many :files, :class_name => 'PortPkgFile'
     has_and_belongs_to_many :tags
     
     def PortPkg.import_from_file(file)
@@ -77,7 +77,7 @@
         port_pkg.revision = info['revision']
 
         # Save unpacked data into a file
-        portPkgFile = PortPkgFiles.new
+        portPkgFile = PortPkgFile.new
         portPkgFile.name = 'portpkg.xar'
         file.rewind
         portPkgFile.data = file.read

Added: users/jberry/mpwa/app/models/port_pkg_file.rb
===================================================================
--- users/jberry/mpwa/app/models/port_pkg_file.rb	                        (rev 0)
+++ users/jberry/mpwa/app/models/port_pkg_file.rb	2007-04-09 04:30:24 UTC (rev 23762)
@@ -0,0 +1,3 @@
+class PortPkgFile < ActiveRecord::Base
+    belongs_to :port_pkg
+end

Added: users/jberry/mpwa/app/views/layouts/port_pkg_file.rhtml
===================================================================
--- users/jberry/mpwa/app/views/layouts/port_pkg_file.rhtml	                        (rev 0)
+++ users/jberry/mpwa/app/views/layouts/port_pkg_file.rhtml	2007-04-09 04:30:24 UTC (rev 23762)
@@ -0,0 +1,17 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+  <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
+  <title>PortPkgFile: <%= controller.action_name %></title>
+  <%= stylesheet_link_tag 'scaffold' %>
+</head>
+<body>
+
+<p style="color: green"><%= flash[:notice] %></p>
+
+<%= yield  %>
+
+</body>
+</html>

Added: users/jberry/mpwa/app/views/port_pkg_file/_form.rhtml
===================================================================
--- users/jberry/mpwa/app/views/port_pkg_file/_form.rhtml	                        (rev 0)
+++ users/jberry/mpwa/app/views/port_pkg_file/_form.rhtml	2007-04-09 04:30:24 UTC (rev 23762)
@@ -0,0 +1,10 @@
+<%= error_messages_for 'port_pkg_file' %>
+
+<!--[form:port_pkg_file]-->
+<p><label for="port_pkg_file_name">Name</label><br/>
+<%= text_field 'port_pkg_file', 'name'  %></p>
+
+<p><label for="port_pkg_file_data">Data</label><br/>
+</p>
+<!--[eoform:port_pkg_file]-->
+

Added: users/jberry/mpwa/app/views/port_pkg_file/edit.rhtml
===================================================================
--- users/jberry/mpwa/app/views/port_pkg_file/edit.rhtml	                        (rev 0)
+++ users/jberry/mpwa/app/views/port_pkg_file/edit.rhtml	2007-04-09 04:30:24 UTC (rev 23762)
@@ -0,0 +1,9 @@
+<h1>Editing port_pkg_file</h1>
+
+<% form_tag :action => 'update', :id => @port_pkg_file do %>
+  <%= render :partial => 'form' %>
+  <%= submit_tag 'Edit' %>
+<% end %>
+
+<%= link_to 'Show', :action => 'show', :id => @port_pkg_file %> |
+<%= link_to 'Back', :action => 'list' %>

Added: users/jberry/mpwa/app/views/port_pkg_file/list.rhtml
===================================================================
--- users/jberry/mpwa/app/views/port_pkg_file/list.rhtml	                        (rev 0)
+++ users/jberry/mpwa/app/views/port_pkg_file/list.rhtml	2007-04-09 04:30:24 UTC (rev 23762)
@@ -0,0 +1,27 @@
+<h1>Listing port_pkg_files</h1>
+
+<table>
+  <tr>
+  <% for column in PortPkgFile.content_columns %>
+    <th><%= column.human_name %></th>
+  <% end %>
+  </tr>
+  
+<% for port_pkg_file in @port_pkg_files %>
+  <tr>
+  <% for column in PortPkgFile.content_columns %>
+    <td><%=h port_pkg_file.send(column.name) %></td>
+  <% end %>
+    <td><%= link_to 'Show', :action => 'show', :id => port_pkg_file %></td>
+    <td><%= link_to 'Edit', :action => 'edit', :id => port_pkg_file %></td>
+    <td><%= link_to 'Destroy', { :action => 'destroy', :id => port_pkg_file }, :confirm => 'Are you sure?', :method => :post %></td>
+  </tr>
+<% end %>
+</table>
+
+<%= link_to 'Previous page', { :page => @port_pkg_file_pages.current.previous } if @port_pkg_file_pages.current.previous %>
+<%= link_to 'Next page', { :page => @port_pkg_file_pages.current.next } if @port_pkg_file_pages.current.next %> 
+
+<br />
+
+<%= link_to 'New port_pkg_file', :action => 'new' %>

Added: users/jberry/mpwa/app/views/port_pkg_file/new.rhtml
===================================================================
--- users/jberry/mpwa/app/views/port_pkg_file/new.rhtml	                        (rev 0)
+++ users/jberry/mpwa/app/views/port_pkg_file/new.rhtml	2007-04-09 04:30:24 UTC (rev 23762)
@@ -0,0 +1,8 @@
+<h1>New port_pkg_file</h1>
+
+<% form_tag :action => 'create' do %>
+  <%= render :partial => 'form' %>
+  <%= submit_tag "Create" %>
+<% end %>
+
+<%= link_to 'Back', :action => 'list' %>

Added: users/jberry/mpwa/app/views/port_pkg_file/show.rhtml
===================================================================
--- users/jberry/mpwa/app/views/port_pkg_file/show.rhtml	                        (rev 0)
+++ users/jberry/mpwa/app/views/port_pkg_file/show.rhtml	2007-04-09 04:30:24 UTC (rev 23762)
@@ -0,0 +1,8 @@
+<% for column in PortPkgFile.content_columns %>
+<p>
+  <b><%= column.human_name %>:</b> <%=h @port_pkg_file.send(column.name) %>
+</p>
+<% end %>
+
+<%= link_to 'Edit', :action => 'edit', :id => @port_pkg_file %> |
+<%= link_to 'Back', :action => 'list' %>

Added: users/jberry/mpwa/test/fixtures/port_pkg_files.yml
===================================================================
--- users/jberry/mpwa/test/fixtures/port_pkg_files.yml	                        (rev 0)
+++ users/jberry/mpwa/test/fixtures/port_pkg_files.yml	2007-04-09 04:30:24 UTC (rev 23762)
@@ -0,0 +1,5 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+one:
+  id: 1
+two:
+  id: 2

Added: users/jberry/mpwa/test/functional/port_pkg_file_controller_test.rb
===================================================================
--- users/jberry/mpwa/test/functional/port_pkg_file_controller_test.rb	                        (rev 0)
+++ users/jberry/mpwa/test/functional/port_pkg_file_controller_test.rb	2007-04-09 04:30:24 UTC (rev 23762)
@@ -0,0 +1,92 @@
+require File.dirname(__FILE__) + '/../test_helper'
+require 'port_pkg_file_controller'
+
+# Re-raise errors caught by the controller.
+class PortPkgFileController; def rescue_action(e) raise e end; end
+
+class PortPkgFileControllerTest < Test::Unit::TestCase
+  fixtures :port_pkg_files
+
+  def setup
+    @controller = PortPkgFileController.new
+    @request    = ActionController::TestRequest.new
+    @response   = ActionController::TestResponse.new
+
+    @first_id = port_pkg_files(:first).id
+  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(:port_pkg_files)
+  end
+
+  def test_show
+    get :show, :id => @first_id
+
+    assert_response :success
+    assert_template 'show'
+
+    assert_not_nil assigns(:port_pkg_file)
+    assert assigns(:port_pkg_file).valid?
+  end
+
+  def test_new
+    get :new
+
+    assert_response :success
+    assert_template 'new'
+
+    assert_not_nil assigns(:port_pkg_file)
+  end
+
+  def test_create
+    num_port_pkg_files = PortPkgFile.count
+
+    post :create, :port_pkg_file => {}
+
+    assert_response :redirect
+    assert_redirected_to :action => 'list'
+
+    assert_equal num_port_pkg_files + 1, PortPkgFile.count
+  end
+
+  def test_edit
+    get :edit, :id => @first_id
+
+    assert_response :success
+    assert_template 'edit'
+
+    assert_not_nil assigns(:port_pkg_file)
+    assert assigns(:port_pkg_file).valid?
+  end
+
+  def test_update
+    post :update, :id => @first_id
+    assert_response :redirect
+    assert_redirected_to :action => 'show', :id => @first_id
+  end
+
+  def test_destroy
+    assert_nothing_raised {
+      PortPkgFile.find(@first_id)
+    }
+
+    post :destroy, :id => @first_id
+    assert_response :redirect
+    assert_redirected_to :action => 'list'
+
+    assert_raise(ActiveRecord::RecordNotFound) {
+      PortPkgFile.find(@first_id)
+    }
+  end
+end

Added: users/jberry/mpwa/test/unit/port_pkg_file_test.rb
===================================================================
--- users/jberry/mpwa/test/unit/port_pkg_file_test.rb	                        (rev 0)
+++ users/jberry/mpwa/test/unit/port_pkg_file_test.rb	2007-04-09 04:30:24 UTC (rev 23762)
@@ -0,0 +1,10 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class PortPkgFileTest < Test::Unit::TestCase
+  fixtures :port_pkg_files
+
+  # Replace this with your real tests.
+  def test_truth
+    assert true
+  end
+end

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20070408/9ca23a55/attachment.html


More information about the macports-changes mailing list