diff --git a/app/controllers/admin/sponsorship_levels_controller.rb b/app/controllers/admin/sponsorship_levels_controller.rb
new file mode 100644
index 00000000..1d0a61bc
--- /dev/null
+++ b/app/controllers/admin/sponsorship_levels_controller.rb
@@ -0,0 +1,17 @@
+module Admin
+ class SponsorshipLevelsController < ApplicationController
+ before_filter :verify_organizer
+
+ def update
+ if @conference.update_attributes(params[:conference])
+ redirect_to(admin_conference_sponsorship_levels_path(
+ conference_id: @conference.short_title),
+ notice: 'Sponsorship levels were successfully updated.')
+ else
+ redirect_to(admin_conference_sponsorship_levels_path(
+ conference_id: @conference.short_title),
+ alert: 'Sponsorship levels update failed')
+ end
+ end
+ end
+end
diff --git a/app/models/conference.rb b/app/models/conference.rb
index 8ba0e73e..dae723cd 100644
--- a/app/models/conference.rb
+++ b/app/models/conference.rb
@@ -10,7 +10,8 @@ class Conference < ActiveRecord::Base
:difficulty_levels_attributes, :use_difficulty_levels,
:use_vpositions, :use_vdays, :vdays_attributes, :vpositions_attributes, :use_volunteers,
:media_id, :media_type, :color, :description,
- :registration_description, :ticket_description
+ :registration_description, :ticket_description,
+ :sponsorship_levels_attributes
has_paper_trail
@@ -31,6 +32,7 @@ class Conference < ActiveRecord::Base
has_many :vdays, :dependent => :destroy
has_many :vpositions, :dependent => :destroy
has_many :vchoices, :dependent => :destroy
+ has_many :sponsorship_levels, dependent: :destroy
belongs_to :venue
@@ -41,6 +43,7 @@ class Conference < ActiveRecord::Base
accepts_nested_attributes_for :venue
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 :event_types, :allow_destroy => true
accepts_nested_attributes_for :email_settings
accepts_nested_attributes_for :questions, :allow_destroy => true
diff --git a/app/models/sponsorship_level.rb b/app/models/sponsorship_level.rb
new file mode 100644
index 00000000..8fc25f88
--- /dev/null
+++ b/app/models/sponsorship_level.rb
@@ -0,0 +1,5 @@
+class SponsorshipLevel < ActiveRecord::Base
+ attr_accessible :title
+ validates_presence_of :title
+ belongs_to :conference
+end
diff --git a/app/views/admin/sponsorship_levels/_sponsorship_level_fields.html.erb b/app/views/admin/sponsorship_levels/_sponsorship_level_fields.html.erb
new file mode 100644
index 00000000..ec4b6220
--- /dev/null
+++ b/app/views/admin/sponsorship_levels/_sponsorship_level_fields.html.erb
@@ -0,0 +1,6 @@
+
+ <%= f.inputs do %>
+ <%= f.input :title %>
+ <%= remove_association_link :sponsorship_level, f %>
+ <% end %>
+
diff --git a/app/views/admin/sponsorship_levels/index.html.haml b/app/views/admin/sponsorship_levels/index.html.haml
new file mode 100644
index 00000000..53bda41b
--- /dev/null
+++ b/app/views/admin/sponsorship_levels/index.html.haml
@@ -0,0 +1,4 @@
+.col-md-9
+ = semantic_form_for(@conference, :url => admin_conference_sponsorship_level_path(@conference.short_title, @conference.sponsorship_levels)) do |f|
+ = dynamic_association :sponsorship_levels, "Sponsorship Levels", f
+ = f.action :submit, :as => :button, :button_html => {:class => "btn btn-primary"}
diff --git a/app/views/layouts/_admin_sidebar.html.haml b/app/views/layouts/_admin_sidebar.html.haml
index 7e7c238d..37a35dcf 100644
--- a/app/views/layouts/_admin_sidebar.html.haml
+++ b/app/views/layouts/_admin_sidebar.html.haml
@@ -45,6 +45,10 @@
%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))}
+ = link_to(admin_conference_sponsorship_levels_path(@conference.short_title)) do
+ %span.glyphicon.glyphicon-star
+ Sponsorship Levels
%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
diff --git a/config/routes.rb b/config/routes.rb
index e34d7e52..cf95118a 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -28,6 +28,8 @@ Osem::Application.routes.draw do
resources :tracks, only: [:show, :update, :index]
+ resources :sponsorship_levels, only: [:show, :update, :index]
+
resources :eventtypes, only: [:show, :index] do
collection do
patch :update
diff --git a/db/migrate/20140605055802_create_sponsorship_levels.rb b/db/migrate/20140605055802_create_sponsorship_levels.rb
new file mode 100644
index 00000000..1a93980b
--- /dev/null
+++ b/db/migrate/20140605055802_create_sponsorship_levels.rb
@@ -0,0 +1,9 @@
+class CreateSponsorshipLevels < ActiveRecord::Migration
+ def change
+ create_table :sponsorship_levels do |t|
+ t.string :title
+ t.belongs_to :conference
+ t.timestamps
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 2ef5c751..b110fc36 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -50,15 +50,15 @@ ActiveRecord::Schema.define(version: 20140605125153) do
add_index "comments", ["user_id"], name: "index_comments_on_user_id"
create_table "conferences", force: true do |t|
- t.string "guid", null: false
- t.string "title", null: false
- t.string "short_title", null: false
+ t.string "guid", null: false
+ t.string "title", null: false
+ t.string "short_title", null: false
t.string "social_tag"
- t.string "contact_email", null: false
- t.string "timezone", null: false
+ t.string "contact_email", null: false
+ t.string "timezone", null: false
t.string "html_export_path"
- t.date "start_date", null: false
- t.date "end_date", null: false
+ t.date "start_date", null: false
+ t.date "end_date", null: false
t.integer "venue_id"
t.datetime "created_at"
t.datetime "updated_at"
@@ -288,6 +288,27 @@ ActiveRecord::Schema.define(version: 20140605125153) do
t.date "date"
end
+ create_table "sponsors", force: true 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.integer "sponsorship_level_id"
+ t.integer "conference_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "sponsorship_levels", force: true do |t|
+ t.string "title"
+ t.integer "conference_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
create_table "supporter_levels", force: true do |t|
t.integer "conference_id"
t.string "title", null: false
@@ -308,9 +329,9 @@ ActiveRecord::Schema.define(version: 20140605125153) do
end
create_table "tracks", force: true do |t|
- t.string "guid", null: false
+ t.string "guid", null: false
t.integer "conference_id"
- t.string "name", null: false
+ t.string "name", null: false
t.text "description"
t.string "color"
t.datetime "created_at"
diff --git a/spec/factories/sponsorship_levels.rb b/spec/factories/sponsorship_levels.rb
new file mode 100644
index 00000000..d13ea48a
--- /dev/null
+++ b/spec/factories/sponsorship_levels.rb
@@ -0,0 +1,8 @@
+# Read about factories at https://github.com/thoughtbot/factory_girl
+
+FactoryGirl.define do
+ factory :sponsorship_level do
+ title 'Platin'
+ conference
+ end
+end
diff --git a/spec/features/sponsorship_level_spec.rb b/spec/features/sponsorship_level_spec.rb
new file mode 100644
index 00000000..c6f75ce4
--- /dev/null
+++ b/spec/features/sponsorship_level_spec.rb
@@ -0,0 +1,46 @@
+require 'spec_helper'
+
+feature SponsorshipLevel 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 'sponsorship levels' do |user|
+ scenario 'adds and updates sponsorship level', feature: true, js: true do
+ conference = create(:conference)
+ sign_in create(user)
+ visit admin_conference_sponsorship_levels_path(
+ conference_id: conference.short_title)
+ # Add sponsorship level
+ click_link 'Add sponsorship_level'
+ 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 sponsorship level')
+
+ click_button 'Update Conference'
+
+ # Validations
+ expect(flash).to eq('Sponsorship levels were successfully updated.')
+ expect(find('div.nested-fields:nth-of-type(1) div:nth-of-type(1) input').
+ value).to eq('Example sponsorship level')
+
+ # Remove sponsorship level
+ click_link 'Remove sponsorship_level'
+ expect(page.all('div.nested-fields').count == 0).to be true
+ click_button 'Update Conference'
+ expect(flash).to eq('Sponsorship levels were successfully updated.')
+ expect(page.all('div.nested-fields').count == 0).to be true
+ end
+ end
+
+ describe 'admin' do
+ it_behaves_like 'sponsorship levels', :admin
+ end
+
+ describe 'organizer' do
+ it_behaves_like 'sponsorship levels', :organizer
+ end
+end
diff --git a/spec/models/sponsorship_level_spec.rb b/spec/models/sponsorship_level_spec.rb
new file mode 100644
index 00000000..1ca073e1
--- /dev/null
+++ b/spec/models/sponsorship_level_spec.rb
@@ -0,0 +1,14 @@
+require 'spec_helper'
+
+describe SponsorshipLevel do
+ describe 'validations' do
+
+ it 'has a valid factory' do
+ expect(build(:sponsorship_level)).to be_valid
+ end
+
+ it 'is not valid without a title' do
+ should validate_presence_of(:title)
+ end
+ end
+end
diff --git a/spec/views/admin/sponsorship_levels/index.html.haml_spec.rb b/spec/views/admin/sponsorship_levels/index.html.haml_spec.rb
new file mode 100644
index 00000000..29ec4f7e
--- /dev/null
+++ b/spec/views/admin/sponsorship_levels/index.html.haml_spec.rb
@@ -0,0 +1,10 @@
+require 'spec_helper'
+
+describe 'admin/sponsorship_levels/index' do
+ it 'renders sponsorship levels' do
+ @sponsorship_level = create(:sponsorship_level)
+ assign :conference, @sponsorship_level.conference
+ render
+ expect(rendered).to include('Platin')
+ end
+end