mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
commit
4e7dd5a8a7
13 changed files with 195 additions and 2 deletions
17
app/controllers/admin/sponsors_controller.rb
Normal file
17
app/controllers/admin/sponsors_controller.rb
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
module Admin
|
||||
class SponsorsController < ApplicationController
|
||||
before_filter :verify_organizer
|
||||
|
||||
def update
|
||||
if @conference.update_attributes(params[:conference])
|
||||
redirect_to(admin_conference_sponsors_path(
|
||||
conference_id: @conference.short_title),
|
||||
notice: 'Sponsorships were successfully updated.')
|
||||
else
|
||||
redirect_to(admin_conference_sponsors_path(
|
||||
conference_id: @conference.short_title),
|
||||
alert: 'Sponsorships updation failed')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -11,7 +11,8 @@ class Conference < ActiveRecord::Base
|
|||
:use_vpositions, :use_vdays, :vdays_attributes, :vpositions_attributes, :use_volunteers,
|
||||
:media_id, :media_type, :color, :description,
|
||||
:registration_description, :ticket_description,
|
||||
:sponsorship_levels_attributes
|
||||
:sponsorship_levels_attributes,
|
||||
:sponsors_attributes
|
||||
|
||||
has_paper_trail
|
||||
|
||||
|
|
@ -33,6 +34,7 @@ class Conference < ActiveRecord::Base
|
|||
has_many :vpositions, :dependent => :destroy
|
||||
has_many :vchoices, :dependent => :destroy
|
||||
has_many :sponsorship_levels, dependent: :destroy
|
||||
has_many :sponsors, dependent: :destroy
|
||||
|
||||
belongs_to :venue
|
||||
|
||||
|
|
@ -44,6 +46,7 @@ class Conference < ActiveRecord::Base
|
|||
accepts_nested_attributes_for :dietary_choices, :allow_destroy => true
|
||||
accepts_nested_attributes_for :supporter_levels, :allow_destroy => true
|
||||
accepts_nested_attributes_for :sponsorship_levels, allow_destroy: true
|
||||
accepts_nested_attributes_for :sponsors, allow_destroy: true
|
||||
accepts_nested_attributes_for :event_types, :allow_destroy => true
|
||||
accepts_nested_attributes_for :email_settings
|
||||
accepts_nested_attributes_for :questions, :allow_destroy => true
|
||||
|
|
|
|||
13
app/models/sponsor.rb
Normal file
13
app/models/sponsor.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
class Sponsor < ActiveRecord::Base
|
||||
attr_accessible :name, :description, :website_url, :logo,
|
||||
:sponsorship_level_id
|
||||
belongs_to :sponsorship_level
|
||||
belongs_to :conference
|
||||
has_attached_file :logo,
|
||||
styles: { thumb: '100x100>', large: '300x300>' }
|
||||
|
||||
validates_attachment_content_type :logo,
|
||||
content_type: [/jpg/, /jpeg/, /png/, /gif/],
|
||||
size: { in: 0..500.kilobytes }
|
||||
validates_presence_of :name, :website_url, :sponsorship_level
|
||||
end
|
||||
|
|
@ -2,4 +2,5 @@ class SponsorshipLevel < ActiveRecord::Base
|
|||
attr_accessible :title
|
||||
validates_presence_of :title
|
||||
belongs_to :conference
|
||||
has_many :sponsors
|
||||
end
|
||||
|
|
|
|||
11
app/views/admin/sponsors/_sponsor_fields.html.erb
Normal file
11
app/views/admin/sponsors/_sponsor_fields.html.erb
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<div class="nested-fields">
|
||||
<%= f.inputs do %>
|
||||
<%= f.input :name %>
|
||||
<%= f.input :description %>
|
||||
<%= image_tag f.object.logo(:thumb) if !f.object.logo.blank? %>
|
||||
<%= f.input :logo %>
|
||||
<%= f.input :website_url %>
|
||||
<%= f.input :sponsorship_level, collection: @conference.sponsorship_levels %>
|
||||
<%= remove_association_link :sponsor, f %>
|
||||
<% end %>
|
||||
</div>
|
||||
5
app/views/admin/sponsors/index.html.haml
Normal file
5
app/views/admin/sponsors/index.html.haml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
.row
|
||||
.col-md-8
|
||||
= semantic_form_for(@conference, :url => admin_conference_sponsor_path(@conference.short_title, @conference.sponsors)) do |f|
|
||||
= dynamic_association :sponsors, "Sponsors", f
|
||||
= f.action :submit, :as => :button, :button_html => {:class => "btn btn-primary"}
|
||||
|
|
@ -45,10 +45,13 @@
|
|||
%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_sponsorship_levels_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
|
||||
Sponsorship Levels
|
||||
%ul.nav.nav-stacked.nav-pills.small.collapse.subNav
|
||||
%li{:class=> active_nav_li(admin_conference_sponsors_path(@conference.short_title))}
|
||||
= link_to 'Sponsors', admin_conference_sponsors_path(@conference.short_title)
|
||||
%li{ class: active_nav_li(admin_conference_supporter_levels_path(@conference.short_title)) }
|
||||
= link_to(admin_conference_supporter_levels_path(@conference.short_title)) do
|
||||
Supporter Levels
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ Osem::Application.routes.draw do
|
|||
|
||||
resources :sponsorship_levels, only: [:show, :update, :index]
|
||||
|
||||
resources :sponsors, only: [:show, :update, :index]
|
||||
|
||||
resources :eventtypes, only: [:show, :index] do
|
||||
collection do
|
||||
patch :update
|
||||
|
|
|
|||
16
db/migrate/20140605115251_create_sponsors.rb
Normal file
16
db/migrate/20140605115251_create_sponsors.rb
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
class CreateSponsors < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :sponsors do |t|
|
||||
t.string :name
|
||||
t.text :description
|
||||
t.string :website_url
|
||||
t.string :logo_file_name
|
||||
t.string :logo_content_type
|
||||
t.integer :logo_file_size
|
||||
t.datetime :logo_updated_at
|
||||
t.belongs_to :sponsorship_level
|
||||
t.belongs_to :conference
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
11
spec/factories/sponsors.rb
Normal file
11
spec/factories/sponsors.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# Read about factories at https://github.com/thoughtbot/factory_girl
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :sponsor do
|
||||
name 'Example sponsor'
|
||||
website_url 'http://www.example.com'
|
||||
description 'Lorem Ipsum Dolor'
|
||||
sponsorship_level
|
||||
conference
|
||||
end
|
||||
end
|
||||
77
spec/features/sponsor_spec.rb
Normal file
77
spec/features/sponsor_spec.rb
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
require 'spec_helper'
|
||||
|
||||
feature Sponsor 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 'sponsors' do |user|
|
||||
scenario 'adds and updates sponsors', feature: true, js: true do
|
||||
path = "#{Rails.root}/app/assets/images/rails.png"
|
||||
conference = create(:conference)
|
||||
conference.sponsorship_levels << create(:sponsorship_level, conference: conference)
|
||||
sign_in create(user)
|
||||
visit admin_conference_sponsors_path(
|
||||
conference_id: conference.short_title)
|
||||
# Add sponsors
|
||||
click_link 'Add sponsor'
|
||||
|
||||
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 sponsor')
|
||||
|
||||
page.
|
||||
find('div.nested-fields:nth-of-type(1) div:nth-of-type(2) textarea').
|
||||
set('Lorem Ipsum')
|
||||
|
||||
attach_file 'Logo', path
|
||||
|
||||
page.
|
||||
find('div.nested-fields:nth-of-type(1) div:nth-of-type(4) input').
|
||||
set('http://www.example.com')
|
||||
|
||||
find(:css, "select[id^='conference_sponsors_attributes_']"\
|
||||
"[id$='_sponsorship_level_id']").
|
||||
find(:option, 'Platin').select_option
|
||||
click_button 'Update Conference'
|
||||
|
||||
expect(flash).to eq('Sponsorships were successfully updated.')
|
||||
|
||||
expect(find('div.nested-fields:nth-of-type(1)'\
|
||||
' div:nth-of-type(1) input').
|
||||
value).to eq('Example sponsor')
|
||||
|
||||
expect(find('div.nested-fields:nth-of-type(1)'\
|
||||
' div:nth-of-type(2) textarea').
|
||||
value).to eq('Lorem Ipsum')
|
||||
|
||||
expect(page).to have_selector("img[src*='rails.png']")
|
||||
|
||||
expect(find('div.nested-fields:nth-of-type(1)'\
|
||||
' div:nth-of-type(4) input').
|
||||
value).to eq('http://www.example.com')
|
||||
|
||||
expect(find('div.nested-fields:nth-of-type(1)'\
|
||||
' div:nth-of-type(5) select:nth-of-type(1)').
|
||||
text).to eq('Platin')
|
||||
|
||||
# Remove sponsor
|
||||
click_link 'Remove sponsor'
|
||||
expect(page.all('div.nested-fields').count == 0).to be true
|
||||
click_button 'Update Conference'
|
||||
expect(flash).to eq('Sponsorships were successfully updated.')
|
||||
expect(page.all('div.nested-fields').count == 0).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'admin' do
|
||||
it_behaves_like 'sponsors', :admin
|
||||
end
|
||||
|
||||
describe 'organizer' do
|
||||
it_behaves_like 'sponsors', :organizer
|
||||
end
|
||||
end
|
||||
17
spec/models/sponsor_spec.rb
Normal file
17
spec/models/sponsor_spec.rb
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Sponsor do
|
||||
describe 'validations' do
|
||||
it 'has a valid factory' do
|
||||
expect(build(:sponsor)).to be_valid
|
||||
end
|
||||
|
||||
it 'is not valid without a name' do
|
||||
should validate_presence_of(:name)
|
||||
end
|
||||
|
||||
it 'is not valid without a website url' do
|
||||
should validate_presence_of(:website_url)
|
||||
end
|
||||
end
|
||||
end
|
||||
17
spec/views/admin/sponsors/index.html.haml_spec.rb
Normal file
17
spec/views/admin/sponsors/index.html.haml_spec.rb
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'admin/sponsors/index' do
|
||||
it 'renders sponsorships' do
|
||||
@conference = create(:conference)
|
||||
@conference.sponsorship_levels << create(:sponsorship_level, conference: @conference)
|
||||
@conference.sponsors << create(:sponsor, conference: @conference,
|
||||
sponsorship_level: @conference.sponsorship_levels.first
|
||||
)
|
||||
assign :conference, @conference
|
||||
render
|
||||
expect(rendered).to include('Example sponsor')
|
||||
expect(rendered).to include('http://www.example.com')
|
||||
expect(rendered).to include('Lorem Ipsum Dolor')
|
||||
expect(rendered).to include('Platin')
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue