Revision 76b2f1b7
Added by Ohad Levy about 14 years ago
- ID 76b2f1b7b5f4febe79752a3d1f7d1524b5c06feb
app/controllers/medias_controller.rb | ||
---|---|---|
class MediasController < ApplicationController
|
||
active_scaffold :media do |config|
|
||
config.columns = [:name, :path, :operatingsystem ]
|
||
config.label = "Installation medias"
|
||
config.columns[:name].description = "Media's name, for example CentOS 5 mirror"
|
||
config.columns[:path].description = "the path to the media, can be a url or an NFS server, must not include the archetecture, for example http://mirror.averse.net/centos/5.3/os/$arch where <b>$arch</b> will be subsituded for the host actual OS"
|
||
config.columns[:operatingsystem].form_ui = :select
|
||
config.columns[:operatingsystem].label = "Operating system"
|
||
|
||
config.nested.add_link "Hosts", [:hosts]
|
||
def index
|
||
@medias = Media.all
|
||
end
|
||
|
||
def show
|
||
@media = Media.find(params[:id])
|
||
end
|
||
|
||
def new
|
||
@media = Media.new
|
||
end
|
||
|
||
def create
|
||
@media = Media.new(params[:media])
|
||
if @media.save
|
||
flash[:notice] = "Successfully created media."
|
||
redirect_to @media
|
||
else
|
||
render :action => 'new'
|
||
end
|
||
end
|
||
|
||
def edit
|
||
@media = Media.find(params[:id])
|
||
end
|
||
|
||
def update
|
||
@media = Media.find(params[:id])
|
||
if @media.update_attributes(params[:media])
|
||
flash[:notice] = "Successfully updated media."
|
||
redirect_to @media
|
||
else
|
||
render :action => 'edit'
|
||
end
|
||
end
|
||
|
||
def destroy
|
||
@media = Media.find(params[:id])
|
||
@media.destroy
|
||
flash[:notice] = "Successfully destroyed media."
|
||
redirect_to medias_url
|
||
end
|
||
end
|
app/helpers/medias_helper.rb | ||
---|---|---|
module MediasHelper
|
||
end
|
app/views/medias/_form.html.erb | ||
---|---|---|
<% form_for @media do |f| %>
|
||
<%= f.error_messages %>
|
||
<p>
|
||
<%= f.label :name %><br />
|
||
<%= f.text_field :name %>
|
||
</p>
|
||
<p>
|
||
<%= f.label :path %><br />
|
||
<%= f.text_field :path %>
|
||
</p >
|
||
<small>
|
||
The path to the media, can be a URL or a valid NFS server(exclusive of the architecture).<br />
|
||
for example http://mirror.averse.net/centos/6.0/os/$arch where <b>$arch</b> will be substituted for the host actual OS architecture.
|
||
</small>
|
||
<p>
|
||
<%= f.label :operatingsystem_id %><br />
|
||
<%= f.collection_select :operatingsystem_id, Operatingsystem.all, :id, :to_label %>
|
||
</p>
|
||
<p><%= f.submit "Submit" %></p>
|
||
<% end %>
|
app/views/medias/edit.html.erb | ||
---|---|---|
<% title "Edit Media" %>
|
||
|
||
<%= render :partial => 'form' %>
|
||
|
||
<p>
|
||
<%= link_to "Show", @media %> |
|
||
<%= link_to "View All", medias_path %>
|
||
</p>
|
app/views/medias/index.html.erb | ||
---|---|---|
<% title "Medias" %>
|
||
|
||
<table class="list">
|
||
<tr>
|
||
<th>Name</th>
|
||
<th>Path</th>
|
||
<th>Operatingsystem</th>
|
||
</tr>
|
||
<% for media in @medias %>
|
||
<tr>
|
||
<td><%=h media.name %></td>
|
||
<td><%=h media.path %></td>
|
||
<td><%=h media.operatingsystem %></td>
|
||
<td><%= link_to "Show", media %></td>
|
||
<td><%= link_to "Edit", edit_media_path(media) %></td>
|
||
<td><%= link_to "Destroy", media, :confirm => 'Are you sure?', :method => :delete %></td>
|
||
</tr>
|
||
<% end %>
|
||
</table>
|
||
|
||
<p><%= link_to "New Media", new_media_path %></p>
|
app/views/medias/new.html.erb | ||
---|---|---|
<% title "New Media" %>
|
||
|
||
<%= render :partial => 'form' %>
|
||
|
||
<p><%= link_to "Back to List", medias_path %></p>
|
app/views/medias/show.html.erb | ||
---|---|---|
<% title "Media #{h @media.name}" %>
|
||
<p>
|
||
<strong>Path:</strong>
|
||
<%=h @media.path %>
|
||
</p>
|
||
<p>
|
||
<strong>Operatingsystem:</strong>
|
||
<%=h @media.operatingsystem %>
|
||
</p>
|
||
|
||
<p>
|
||
Currently used by <%= @media.hosts.count %> hosts
|
||
</p>
|
||
|
||
<p>
|
||
<%= link_to "Edit", edit_media_path(@media) %> |
|
||
<%= link_to "Destroy", @media, :confirm => 'Are you sure?', :method => :delete %> |
|
||
<%= link_to "View All", medias_path %>
|
||
</p>
|
config/routes.rb | ||
---|---|---|
map.connect "/lookup", :controller => "lookup_keys", :action => "q"
|
||
map.resources :domains
|
||
map.resources :operatingsystems
|
||
map.resources :medias, :active_scaffold => true
|
||
map.resources :medias
|
||
map.resources :models, :active_scaffold => true
|
||
map.resources :architectures
|
||
map.resources :puppetclasses, :active_scaffold => true, :collection => {:import_classes_and_environments => :get}
|
test/fixtures/medias.yml | ||
---|---|---|
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||
|
||
# one:
|
||
# column: value
|
||
#
|
||
# two:
|
||
# column: value
|
||
one:
|
||
name: CentOS 5.4
|
||
path: http://mirror.averse.net/centos/6.0/os/$arch
|
||
operatingsystem_id: 1
|
test/functional/medias_controller_test.rb | ||
---|---|---|
require 'test_helper'
|
||
|
||
class MediasControllerTest < ActionController::TestCase
|
||
test "ActiveScaffold should look for Media model" do
|
||
assert_not_nil MediasController.active_scaffold_config
|
||
assert MediasController.active_scaffold_config.model == Media
|
||
def test_index
|
||
get :index
|
||
assert_template 'index'
|
||
end
|
||
|
||
test "should get index" do
|
||
get :index
|
||
assert_response :success
|
||
assert_not_nil assigns(:records)
|
||
def test_show
|
||
get :show, :id => Media.first
|
||
assert_template 'show'
|
||
end
|
||
|
||
test "shuold get new" do
|
||
def test_new
|
||
get :new
|
||
assert_response :success
|
||
assert_template 'new'
|
||
end
|
||
|
||
test "should create new media" do
|
||
assert_difference 'Media.count' do
|
||
post :create, { :commit => "Create", :record => {:name => "some_arch", :path => "http://www.google.com"} }
|
||
end
|
||
|
||
assert_redirected_to medias_path
|
||
def test_create_invalid
|
||
Media.any_instance.stubs(:valid?).returns(false)
|
||
post :create
|
||
assert_template 'new'
|
||
end
|
||
|
||
test "should get edit" do
|
||
media = Media.new :name => "some_media", :path => "http://www.google.com"
|
||
assert media.save!
|
||
|
||
get :edit, :id => media.id
|
||
assert_response :success
|
||
def test_create_valid
|
||
Media.any_instance.stubs(:valid?).returns(true)
|
||
post :create
|
||
assert_redirected_to media_url(assigns(:media))
|
||
end
|
||
|
||
test "should update media" do
|
||
media = Media.new :name => "some_media", :path => "http://www.google.com"
|
||
assert media.save!
|
||
|
||
put :update, { :commit => "Update", :id => media.id, :record => {:name => "other_media", :path => "http://www.vurbia.com"} }
|
||
media = Media.find_by_id(media.id)
|
||
assert media.name == "other_media"
|
||
assert media.path == "http://www.vurbia.com"
|
||
|
||
assert_redirected_to medias_path
|
||
def test_edit
|
||
get :edit, :id => Media.first
|
||
assert_template 'edit'
|
||
end
|
||
|
||
test "should destroy media" do
|
||
media = Media.new :name => "some_media", :path => "http://www.google.com"
|
||
assert media.save!
|
||
def test_update_invalid
|
||
Media.any_instance.stubs(:valid?).returns(false)
|
||
put :update, :id => Media.first
|
||
assert_template 'edit'
|
||
end
|
||
|
||
assert_difference('Media.count', -1) do
|
||
delete :destroy, :id => media.id
|
||
end
|
||
def test_update_valid
|
||
Media.any_instance.stubs(:valid?).returns(true)
|
||
put :update, :id => Media.first
|
||
assert_redirected_to media_url(assigns(:media))
|
||
end
|
||
|
||
assert_redirected_to medias_path
|
||
def test_destroy
|
||
media = Media.first
|
||
delete :destroy, :id => media
|
||
assert_redirected_to medias_url
|
||
assert !Media.exists?(media.id)
|
||
end
|
||
end
|
Also available in: Unified diff
fixes #202 - Remove activescaffold from the medias page