mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-14 04:04:03 +00:00
commit
2a742e6d0a
12 changed files with 158 additions and 1 deletions
23
app/controllers/admin/lodgings_controller.rb
Normal file
23
app/controllers/admin/lodgings_controller.rb
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
module Admin
|
||||
class LodgingsController < ApplicationController
|
||||
before_filter :verify_organizer
|
||||
|
||||
def index
|
||||
@venue = @conference.venue
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def update
|
||||
@venue = @conference.venue
|
||||
if @venue.update_attributes(params[:venue])
|
||||
redirect_to(admin_conference_lodgings_path(conference_id: @conference.short_title),
|
||||
notice: 'Lodgings were successfully updated.')
|
||||
else
|
||||
redirect_to(admin_conference_lodgings_path(conference_id: @conference.short_title),
|
||||
notice: 'Lodgings Updation Failed!')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
10
app/models/lodging.rb
Normal file
10
app/models/lodging.rb
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
class Lodging < ActiveRecord::Base
|
||||
attr_accessible :name, :description, :photo
|
||||
belongs_to :venue
|
||||
has_attached_file :photo,
|
||||
styles: { thumb: '100x100>', large: '300x300>' }
|
||||
|
||||
validates_attachment_content_type :photo,
|
||||
content_type: [/jpg/, /jpeg/, /png/, /gif/],
|
||||
size: { in: 0..500.kilobytes }
|
||||
end
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
class Venue < ActiveRecord::Base
|
||||
attr_accessible :name, :description, :website, :address, :photo
|
||||
attr_accessible :name, :description, :website, :address, :photo, :lodgings_attributes
|
||||
has_many :conferences
|
||||
has_many :lodgings
|
||||
before_create :generate_guid
|
||||
has_attached_file :photo,
|
||||
styles: { thumb: '100x100>', large: '300x300>' }
|
||||
|
|
@ -8,6 +9,7 @@ class Venue < ActiveRecord::Base
|
|||
validates_attachment_content_type :photo,
|
||||
content_type: [/jpg/, /jpeg/, /png/, /gif/],
|
||||
size: { in: 0..500.kilobytes }
|
||||
accepts_nested_attributes_for :lodgings, allow_destroy: true
|
||||
private
|
||||
|
||||
def generate_guid
|
||||
|
|
|
|||
10
app/views/admin/lodgings/_lodging_fields.html.erb
Normal file
10
app/views/admin/lodgings/_lodging_fields.html.erb
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<div class="nested-fields">
|
||||
<%= f.inputs do %>
|
||||
<%= f.input :name %>
|
||||
<%= f.input :description, :input_html => {:rows => 2 }, hint: 'Write about the hotel/place,
|
||||
of what they are offering, about types of rooms, prices and address' %>
|
||||
<%= image_tag f.object.photo(:thumb) if !f.object.photo.blank? %>
|
||||
<%= f.input :photo %>
|
||||
<%= remove_association_link :lodging, f %>
|
||||
<% end %>
|
||||
</div>
|
||||
5
app/views/admin/lodgings/index.html.haml
Normal file
5
app/views/admin/lodgings/index.html.haml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
.row
|
||||
.col-md-8
|
||||
= semantic_form_for(@venue, :url => admin_conference_lodging_path(@conference.short_title, @conference.venue.lodgings), :html => {:multipart => true}) do |f|
|
||||
= dynamic_association :lodgings, "Lodgings", f
|
||||
= f.action :submit, :as => :button, :button_html => {:class => "btn btn-primary"}
|
||||
|
|
@ -45,6 +45,8 @@
|
|||
%ul.nav.nav-stacked.nav-pills.small.collapse.subNav
|
||||
%li{:class=> active_nav_li(admin_conference_rooms_path(@conference.short_title))}
|
||||
= link_to 'Rooms', admin_conference_rooms_path(@conference.short_title)
|
||||
%li{ class: active_nav_li(admin_conference_lodgings_path(@conference.short_title)) }
|
||||
= link_to 'Lodgings', admin_conference_lodgings_path(@conference.short_title)
|
||||
%li{:class=> "#{active_nav_li(admin_conference_sponsorship_levels_path(@conference.short_title))} myAccordion" }
|
||||
= link_to(admin_conference_sponsorship_levels_path(@conference.short_title)) do
|
||||
%span.glyphicon.glyphicon-star
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ Osem::Application.routes.draw do
|
|||
|
||||
resources :sponsors, only: [:show, :update, :index]
|
||||
|
||||
resources :lodgings, only: [:show, :update, :index]
|
||||
|
||||
resources :eventtypes, only: [:show, :index] do
|
||||
collection do
|
||||
patch :update
|
||||
|
|
|
|||
14
db/migrate/20140604061951_create_lodgings.rb
Normal file
14
db/migrate/20140604061951_create_lodgings.rb
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
class CreateLodgings < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :lodgings do |t|
|
||||
t.string :name
|
||||
t.text :description
|
||||
t.string :photo_file_name
|
||||
t.string :photo_content_type
|
||||
t.integer :photo_file_size
|
||||
t.datetime :photo_updated_at
|
||||
t.belongs_to :venue
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
12
db/schema.rb
12
db/schema.rb
|
|
@ -192,6 +192,18 @@ ActiveRecord::Schema.define(version: 20140613083115) do
|
|||
t.integer "event_id"
|
||||
end
|
||||
|
||||
create_table "lodgings", force: true do |t|
|
||||
t.string "name"
|
||||
t.text "description"
|
||||
t.string "photo_file_name"
|
||||
t.string "photo_content_type"
|
||||
t.integer "photo_file_size"
|
||||
t.datetime "photo_updated_at"
|
||||
t.integer "venue_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "people", force: true do |t|
|
||||
t.string "guid", null: false
|
||||
t.string "first_name", default: ""
|
||||
|
|
|
|||
9
spec/factories/lodgings.rb
Normal file
9
spec/factories/lodgings.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# Read about factories at https://github.com/thoughtbot/factory_girl
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :lodging do
|
||||
name 'Example Hotel'
|
||||
description 'Lorem Ipsum Dolor'
|
||||
venue
|
||||
end
|
||||
end
|
||||
55
spec/features/lodgings_spec.rb
Normal file
55
spec/features/lodgings_spec.rb
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
require 'spec_helper'
|
||||
|
||||
feature Lodging do
|
||||
# It is necessary to use bang version of let to build roles before user
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
let!(:participant_role) { create(:participant_role) }
|
||||
let!(:admin_role) { create(:admin_role) }
|
||||
|
||||
shared_examples 'lodgings' do |user|
|
||||
scenario 'adds and updates lodgings', feature: true, js: true do
|
||||
path = "#{Rails.root}/app/assets/images/rails.png"
|
||||
conference = create(:conference)
|
||||
conference.venue = create(:venue)
|
||||
sign_in create(user)
|
||||
visit admin_conference_lodgings_path(
|
||||
conference_id: conference.short_title)
|
||||
# Add lodging
|
||||
click_link 'Add lodging'
|
||||
expect(page.all('div.nested-fields').count == 1).to be true
|
||||
page.
|
||||
find('div.nested-fields:nth-of-type(1) div:nth-of-type(1) input').
|
||||
set('Example Hotel')
|
||||
|
||||
page.
|
||||
find('div.nested-fields:nth-of-type(1) div:nth-of-type(2) textarea').
|
||||
set('Lorem Ipsum Dolor')
|
||||
attach_file 'Photo', path
|
||||
|
||||
click_button 'Update Venue'
|
||||
|
||||
# Validations
|
||||
expect(flash).to eq('Lodgings were successfully updated.')
|
||||
expect(find('div.nested-fields:nth-of-type(1) div:nth-of-type(1) input').
|
||||
value).to eq('Example Hotel')
|
||||
expect(find('div.nested-fields:nth-of-type(1) div:nth-of-type(2) textarea').
|
||||
value).to eq('Lorem Ipsum Dolor')
|
||||
expect(page).to have_selector("img[src*='rails.png']")
|
||||
|
||||
# Remove room
|
||||
click_link 'Remove lodging'
|
||||
expect(page.all('div.nested-fields').count == 0).to be true
|
||||
click_button 'Update Venue'
|
||||
expect(flash).to eq('Lodgings were successfully updated.')
|
||||
expect(page.all('div.nested-fields').count == 0).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'admin' do
|
||||
it_behaves_like 'lodgings', :admin
|
||||
end
|
||||
|
||||
describe 'organizer' do
|
||||
it_behaves_like 'lodgings', :organizer
|
||||
end
|
||||
end
|
||||
13
spec/views/admin/lodgings/index.html.haml_spec.rb
Normal file
13
spec/views/admin/lodgings/index.html.haml_spec.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'admin/lodgings/index' do
|
||||
it 'renders lodgings list' do
|
||||
@conference = create(:conference)
|
||||
@conference.venue = create(:venue)
|
||||
@conference.venue.lodgings << create(:lodging, venue: @conference.venue)
|
||||
assign :venue, @conference.venue
|
||||
render
|
||||
expect(rendered).to include('Example Hotel')
|
||||
expect(rendered).to include('Lorem Ipsum Dolor')
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue