diff --git a/app/controllers/admin/organizations_controller.rb b/app/controllers/admin/organizations_controller.rb new file mode 100644 index 00000000..66de3420 --- /dev/null +++ b/app/controllers/admin/organizations_controller.rb @@ -0,0 +1,43 @@ +class Admin::OrganizationsController < ApplicationController + before_filter :verify_organizer + respond_to :html + + def index + @organizations = Organization.all + end + + def new + @organization = Organization.new + end + + def create + @organization = Organization.new(params[:organization]) + flash[:notice] = 'Organization was successfully created.' if @organization.save + respond_with @organization, :location => admin_organizations_path + end + + def show + @organization = Organization.find(params[:id]) + end + + def edit + @organization = Organization.find(params[:id]) + end + + def update + @organization = Organization.find(params[:id]) + flash[:notice] = 'Organization was successfully updated' if @organization.update_attributes(params[:organization]) + respond_with @organization, :location => admin_organizations_path + end + + def delete + @organization = Organization.find(params[:id]) + end + + def destroy + @organization = Organization.find(params[:id]) + @organization.destroy + redirect_to admin_organizations_path, :notice => "Organization got deleted" + + end +end diff --git a/app/controllers/admin/sponsorship_levels_controller.rb b/app/controllers/admin/sponsorship_levels_controller.rb new file mode 100644 index 00000000..947a023c --- /dev/null +++ b/app/controllers/admin/sponsorship_levels_controller.rb @@ -0,0 +1,16 @@ +class Admin::SponsorshipLevelsController < ApplicationController + before_filter :verify_organizer + + def show + render :sponsorship_levels + end + + def update + begin + @conference.update_attributes!(params[:conference]) + redirect_to(admin_conference_sponsorship_levels_path(:conference_id => @conference.short_title), :notice => 'Sponsorship levels were successfully updated.') + rescue Exception => e + redirect_to(admin_conference_sponsorship_levels_path(:conference_id => @conference.short_title), :alert => "Sponsorship levels update failed: #{e.message}") + end + end +end diff --git a/app/controllers/admin/sponsorships_controller.rb b/app/controllers/admin/sponsorships_controller.rb new file mode 100644 index 00000000..9ebc38f9 --- /dev/null +++ b/app/controllers/admin/sponsorships_controller.rb @@ -0,0 +1,17 @@ +class Admin::SponsorshipsController < ApplicationController + before_filter :verify_organizer + + def index + end + + def create + params[:sponsorship_registration][:conference_id] = @conference.id + sponsorship = SponsorshipRegistration.new(params[:sponsorship_registration]) + if sponsorship.save + redirect_to(admin_conference_sponsorships_path(:conference_id => @conference.short_title), :notice => "Sponsorship added") + else + redirect_to(admin_conference_sponsorships_path(:conference_id => @conference.short_title), + :alert => "Sponsorship creation failed.#{sponsorship.errors.full_messages.join('. ')}") + end + end +end diff --git a/app/models/conference.rb b/app/models/conference.rb index c7847610..07a61f7d 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -3,13 +3,16 @@ class Conference < ActiveRecord::Base attr_accessible :title, :short_title, :social_tag, :contact_email, :timezone, :html_export_path, - :start_date, :end_date, :rooms_attributes, :tracks_attributes, :dietary_choices_attributes, - :use_dietary_choices, :use_supporter_levels, :supporter_levels_attributes, :social_events_attributes, + :start_date, :end_date, :rooms_attributes, :tracks_attributes, + :dietary_choices_attributes, + :use_dietary_choices, :use_supporter_levels, :supporter_levels_attributes, + :social_events_attributes, :event_types_attributes, :registration_start_date, :registration_end_date, :logo, :questions_attributes, :question_ids, :answers_attributes, :answer_ids, :difficulty_levels_attributes, :use_difficulty_levels, :use_vpositions, :use_vdays, :vdays_attributes, :vpositions_attributes, :use_volunteers, - :media_id, :media_type + :media_id, :media_type, :sponsorship_levels_attributes, :sponsor_email, + :sponsor_description has_paper_trail @@ -30,6 +33,8 @@ 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 + has_many :sponsorship_registrations, dependent: :destroy belongs_to :venue @@ -40,6 +45,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/organization.rb b/app/models/organization.rb new file mode 100644 index 00000000..28709e4d --- /dev/null +++ b/app/models/organization.rb @@ -0,0 +1,16 @@ +class Organization < ActiveRecord::Base + attr_accessible :title, :photo, :email_id, :description, :website_url + has_many :sponsorship_registrations, dependent: :destroy + 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 } + validates_presence_of :title, + :email_id, + :website_url + validates_uniqueness_of :email_id + + +end diff --git a/app/models/sponsorship_level.rb b/app/models/sponsorship_level.rb new file mode 100644 index 00000000..996e9722 --- /dev/null +++ b/app/models/sponsorship_level.rb @@ -0,0 +1,6 @@ +class SponsorshipLevel < ActiveRecord::Base + attr_accessible :title, :description + belongs_to :conference + has_many :sponsorship_registrations + validates_presence_of :title +end diff --git a/app/models/sponsorship_registration.rb b/app/models/sponsorship_registration.rb new file mode 100644 index 00000000..8da8a5e0 --- /dev/null +++ b/app/models/sponsorship_registration.rb @@ -0,0 +1,11 @@ +class SponsorshipRegistration < ActiveRecord::Base + attr_accessible :name, :email_id, :contact_no, :amount_donated, :method_of_donation, + :sponsorship_level_id, :conference_id, :organization_id + belongs_to :organization + belongs_to :sponsorship_level + belongs_to :conference + validates_presence_of :name, :email_id, :contact_no, :amount_donated, + :method_of_donation, :sponsorship_level, + :conference, :organization + validates_uniqueness_of :email_id +end diff --git a/app/views/admin/conference/show.html.haml b/app/views/admin/conference/show.html.haml index f78d0597..027400a1 100644 --- a/app/views/admin/conference/show.html.haml +++ b/app/views/admin/conference/show.html.haml @@ -1,3 +1,33 @@ .row .col-md-8 - %h1 Dashboard for #{@conference.title} \ No newline at end of file + %h1 Dashboard for #{@conference.title} + .col-md-9 + = semantic_form_for(@conference, :url => admin_conference_path(@conference.short_title),:html => {:multipart => true}) do |f| + = f.input :title, :hint => "The full name of the conference, such as 'OpenSUSE Conference 2013'" + = f.input :short_title, :hint => "A short title, such as 'osc2013', to be used in URLs" + = f.input :social_tag, :hint => "The hashtag you'll use on Twitter and Google+. Don't include the '#' sign!'" + = f.input :contact_email, :hint => "Contact email address for your conference. Will be used as reply-to address in emails sent out by the system." + + = f.inputs :name => "Scheduling" do + = f.input :timezone, :as => :time_zone, :hint => "The conference time zone" + = f.input :start_date, :as => :string, :input_html => { :id => "conference-start-datepicker", :readonly => "readonly" } + = f.input :end_date, :as => :string, :input_html => { :id => "conference-end-datepicker", :readonly => "readonly" } + = f.input :registration_start_date, :as => :string, :input_html => { :id => "conference-reg-start-datepicker", :readonly => "readonly" } + = f.input :registration_end_date, :as => :string, :input_html => { :id => "conference-reg-end-datepicker", :readonly => "readonly" } + + = f.inputs :name => "Media" do + - if !@conference.logo.blank? + = image_tag @conference.logo(:thumb) + = f.input :logo, :label => "Conference Logo", :hint => "This will be displayed on the front page." + = f.input :media_type, :as => :select, :label => "Conference Promo Media Type", :class=>"form-control", :collection => Conference.media_types.values, :include_blank => false, :hint => "This media-item will be used to represent this conference at various places in OSEM." + = f.input :media_id, :label => "Conference Promo Media ID", :as => :string + %p{:class => "help-block media-type", :id => "youtube-help"} Go to your YouTube video, click on "share" and copy everything behind http://youtu.be/" + %p{:class => "help-block media-type", :id => "slideshare-help", :style => "display:none"} Go to your SlideShare, click on "share" -> "embed" and copy the id + %p{:class => "help-block media-type", :id => "flickr-help", :style => "display:none"} Go to your flickr image, click on "Grab the link" -> "Show short url" and copy everything behind https://flic.kr/p/ + %p{:class => "help-block media-type", :id => "vimeo-help", :style => "display:none"} Go to your vimeo video, click on "share" and copy everything behind http://vimeo.com/ + %p{:class => "help-block media-type", :id => "speakerdeck-help", :style => "display:none"} Go to your SpeakerDeck, click on "share" -> "embed" and copy the data-id + %p{:class => "help-block media-type", :id => "instagram-help", :style => "display:none"} Go to your Instagram photo page and copy everything behind instagram.com/p/ (without trailing /# hash symbol) + = f.input :sponsor_email, hint: 'This mail id is used by sponsors to contact organizers' + = f.input :sponsor_description, hint: 'This description will be displayed in sponsor section of splash page' + = f.action :submit, :as => :button, :button_html => {:class => "btn btn-primary"} +>>>>>>> Sponsor dashboard added, with sponsor component for splash page diff --git a/app/views/admin/organizations/_form.html.haml b/app/views/admin/organizations/_form.html.haml new file mode 100644 index 00000000..e28d6204 --- /dev/null +++ b/app/views/admin/organizations/_form.html.haml @@ -0,0 +1,11 @@ += semantic_form_for [:admin, @organization] do |f| + = f.inputs "Basic Information" do + = f.input :title, as: :string + = f.input :email_id, as: :string + = f.input :website_url, as: :string + = f.input :description + - if !@organization.photo.blank? + = image_tag @organization.photo(:thumb) + = f.input :photo + = f.actions do + = f.action :submit, :button_html => {:class => "btn primary"} diff --git a/app/views/admin/organizations/index.html.haml b/app/views/admin/organizations/index.html.haml new file mode 100644 index 00000000..81d61326 --- /dev/null +++ b/app/views/admin/organizations/index.html.haml @@ -0,0 +1,36 @@ +.row + .col-md-12 + .page-header + %h1 + Organizations + - if @organizations + = "(#{@organizations.length})" + = link_to "New Organization", new_admin_organization_path, :class => "btn btn-success pull-right" + +.row + .col-md-12 + .well + %table.table.table-striped.table-bordered.table-hover#organization + %thead + %th + %b Title + %th + %b Email + %th + %th + %th + - @organizations.each do |organization| + %tr + %td= organization.title + %td= organization.email_id + %td= link_to "Edit", edit_admin_organization_path(organization) + %td= link_to "View", admin_organization_path(organization) + %td=link_to 'Delete',admin_organization_path(organization), :method=> :delete , :data=> {:confirm => 'Are you sure ?'},:class => "btn btn-primary btn-danger" + +:javascript + $(document).ready(function() { + $('#organization').dataTable( { + "bPaginate": false, + "bLengthChange": false + } ); + } ); diff --git a/app/views/admin/organizations/show.html.haml b/app/views/admin/organizations/show.html.haml new file mode 100644 index 00000000..c7ce1a2b --- /dev/null +++ b/app/views/admin/organizations/show.html.haml @@ -0,0 +1,26 @@ +%table.table + %tr + %td + %b Title + %td + = @organization.title + %tr + %td + %b Email + %td + = @organization.email_id + %tr + %td + %b Logo + %td + = image_tag(@organization.photo(:thumb), class: 'img-responsive') if @organization.photo? + %tr + %td + %b Description + %td + = @organization.description + %tr + %td + %b Website Url + %td + = @organization.website_url 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..ace26202 --- /dev/null +++ b/app/views/admin/sponsorship_levels/_sponsorship_level_fields.html.erb @@ -0,0 +1,7 @@ +
+ <%= f.inputs do %> + <%= f.input :title %> + <%= f.input :description %> + <%= 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/admin/sponsorships/index.html.haml b/app/views/admin/sponsorships/index.html.haml new file mode 100644 index 00000000..4c1b3a9e --- /dev/null +++ b/app/views/admin/sponsorships/index.html.haml @@ -0,0 +1,45 @@ +#new-sponsorship-dialog + = semantic_form_for :sponsorship_registration, :html => {:id => "sponsorship-add-form"} do |f| + = f.input :name, :label => "Sponsorship Name" + = f.input :email_id, :label => "Sponsorship Email" + = f.input :organization_id, as: :select, collection: Organization.all + = f.input :sponsorship_level_id, :as => :select, :collection => @conference.sponsorship_levels + = f.input :contact_no, :label => "Phone Number" + = f.input :amount_donated + = f.input :method_of_donation + = f.action :submit, :button_html => { :value => "Save", :class => "btn btn-primary" } + +.row + .col-md-12 + .pull-right{:style=>"margin-top:20px; margin-bottom:20px;"} + = link_to "New Sponsorship", "#", :id => "new-sponsorship-button", :class => "btn btn-success" +.row + .col-md-12 + %h2 Sponsorships + .well + %table.table.table-striped#sponsorships + %thead + %th + Name + %th + Email + %th + Level + %th + Organization + %th + Phone Number + %th + Amount Donated + %th + Method of Donation + %tbody + - @conference.sponsorship_registrations.each do |u| + %tr + %td= u.name + %td= u.email_id + %td= u.sponsorship_level.title if u.sponsorship_level + %td= u.organization.title + %td= u.contact_no + %td= u.amount_donated + %td= u.method_of_donation diff --git a/app/views/conference/_sponsor.html.haml b/app/views/conference/_sponsor.html.haml new file mode 100644 index 00000000..9db7eedf --- /dev/null +++ b/app/views/conference/_sponsor.html.haml @@ -0,0 +1,20 @@ +%div.container#sponsors.text-center + %div.row + %div.col-md-12 + %h2 Sponsors + -if !@conference.sponsor_description.blank? + %p #{ @conference.sponsor_description } + -if !@conference.sponsor_email.blank? + %h3= mail_to "#{ @conference.sponsor_email }", 'Become a Sponsor' + - if !@conference.sponsorship_levels.blank? + - @conference.sponsorship_levels.each do |l| + - if !l.sponsorship_registrations.blank? + %div.row.multi-columns-row + %h4 #{l.title} + - l.sponsorship_registrations.each_with_index do |r,index| + %div.col-md-4 + - if !r.organization.photo.blank? + = link_to image_tag(r.organization.photo(:large), class: 'img-responsive', alt: "#{r.organization.title} Logo", title: "#{r.organization.description}"), "http://#{r.organization.website_url}" + - unless index == 0 + - if index%2 == 0 + %div.clearfix.visible-md.visible-lg diff --git a/app/views/conference/show.html.haml b/app/views/conference/show.html.haml index 021d213f..cbf01b10 100644 --- a/app/views/conference/show.html.haml +++ b/app/views/conference/show.html.haml @@ -1,3 +1,7 @@ = content_for :splash_logo do = link_to @conference.title, "#", :class => 'navbar-brand' -= render :partial => "home/conference_details", :locals => {:conference => @conference} \ No newline at end of file += content_for :splash_header do + %ul.nav.navbar-nav + %li + %a{ href: '#sponsors' } Sponsors += render 'sponsor' diff --git a/app/views/layouts/_admin_sidebar.html.haml b/app/views/layouts/_admin_sidebar.html.haml index 1cc73dae..321aff95 100644 --- a/app/views/layouts/_admin_sidebar.html.haml +++ b/app/views/layouts/_admin_sidebar.html.haml @@ -24,6 +24,10 @@ = link_to(admin_conference_registrations_path(@conference.short_title)) do %span.glyphicon.glyphicon-user Registrations + %li{:class=> active_nav_li(admin_conference_sponsorships_path(@conference.short_title))} + = link_to(admin_conference_sponsorships_path(@conference.short_title)) do + %span.glyphicon.glyphicon-usd + Sponsorships %li{:class=> active_nav_li(admin_conference_events_path(@conference.short_title))} = link_to(admin_conference_events_path(@conference.short_title)) do %span.glyphicon.glyphicon-comment @@ -31,7 +35,7 @@ %li{class: active_nav_li(admin_conference_schedule_path(@conference.short_title))} = link_to(admin_conference_schedule_path(@conference.short_title), target: '_blank') do %span.glyphicon.glyphicon-calendar - Shedule + Schedule %hr %li.nav-header %a @@ -49,6 +53,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_emails_path(@conference.short_title))} = link_to(admin_conference_emails_path(@conference.short_title)) do %span.glyphicon.glyphicon-envelope diff --git a/app/views/layouts/_admin_sidebar_index.html.haml b/app/views/layouts/_admin_sidebar_index.html.haml index 6d18d7c5..4d546985 100644 --- a/app/views/layouts/_admin_sidebar_index.html.haml +++ b/app/views/layouts/_admin_sidebar_index.html.haml @@ -28,3 +28,8 @@ = link_to(admin_people_path) do %span.glyphicon.glyphicon-star-empty People + %li + = link_to(admin_organizations_path) do + %span.glyphicon.glyphicon-th + Organization + diff --git a/app/views/layouts/_user_menu.html.haml b/app/views/layouts/_user_menu.html.haml index bfcbfa6f..1930072d 100644 --- a/app/views/layouts/_user_menu.html.haml +++ b/app/views/layouts/_user_menu.html.haml @@ -14,6 +14,7 @@ -if has_role?(current_user, "admin") || has_role?(current_user, "organizer") %li.divider %li + = link_to(admin_conference_index_path()) do %span.glyphicon.glyphicon-home Administration diff --git a/config/routes.rb b/config/routes.rb index 606b9569..34820839 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,12 +1,11 @@ Osem::Application.routes.draw do - get 'conference/show' - devise_for :users, :controllers => { :registrations => :registrations }, :path => 'accounts' namespace :admin do resources :users resources :people + resources :organizations resources :conference do get "/schedule" => "schedule#show" patch "/schedule" => "schedule#update" @@ -38,6 +37,8 @@ Osem::Application.routes.draw do resources :supporter_levels, only: [:show, :update, :index] + resources :sponsorship_levels, only: [:show, :update, :index] + resources :emails, only: [:show, :update, :index] resources :callforpapers, only: [:create] do @@ -59,7 +60,7 @@ Osem::Application.routes.draw do end resource :speaker, :only => [:edit, :update] end - + resources :sponsorships resources :supporters end end diff --git a/db/migrate/20140524121219_create_sponsorship_levels.rb b/db/migrate/20140524121219_create_sponsorship_levels.rb new file mode 100644 index 00000000..30737d88 --- /dev/null +++ b/db/migrate/20140524121219_create_sponsorship_levels.rb @@ -0,0 +1,10 @@ +class CreateSponsorshipLevels < ActiveRecord::Migration + def change + create_table :sponsorship_levels do |t| + t.string :title + t.text :description + t.belongs_to :conference + t.timestamps + end + end +end diff --git a/db/migrate/20140524122022_create_sponsorship_registrations.rb b/db/migrate/20140524122022_create_sponsorship_registrations.rb new file mode 100644 index 00000000..789df5c1 --- /dev/null +++ b/db/migrate/20140524122022_create_sponsorship_registrations.rb @@ -0,0 +1,15 @@ +class CreateSponsorshipRegistrations < ActiveRecord::Migration + def change + create_table :sponsorship_registrations do |t| + t.string :name + t.string :email_id + t.string :contact_no + t.float :amount_donated + t.string :method_of_donation + t.belongs_to :organization + t.belongs_to :sponsorship_level + t.belongs_to :conference + t.timestamps + end + end +end diff --git a/db/migrate/20140524122046_create_organizations.rb b/db/migrate/20140524122046_create_organizations.rb new file mode 100644 index 00000000..710acd66 --- /dev/null +++ b/db/migrate/20140524122046_create_organizations.rb @@ -0,0 +1,14 @@ +class CreateOrganizations < ActiveRecord::Migration + def change + create_table :organizations do |t| + t.string :title + t.string :email_id + t.text :description + t.string :photo_file_name + t.string :photo_content_type + t.integer :photo_file_size + t.datetime :photo_updated_at + t.timestamps + end + end +end diff --git a/db/migrate/20140525155624_add_sponsor_email_to_conferences.rb b/db/migrate/20140525155624_add_sponsor_email_to_conferences.rb new file mode 100644 index 00000000..9fe6e930 --- /dev/null +++ b/db/migrate/20140525155624_add_sponsor_email_to_conferences.rb @@ -0,0 +1,5 @@ +class AddSponsorEmailToConferences < ActiveRecord::Migration + def change + add_column :conferences, :sponsor_email, :string + end +end diff --git a/db/migrate/20140525155644_add_sponsor_description_to_conferences.rb b/db/migrate/20140525155644_add_sponsor_description_to_conferences.rb new file mode 100644 index 00000000..793033f4 --- /dev/null +++ b/db/migrate/20140525155644_add_sponsor_description_to_conferences.rb @@ -0,0 +1,5 @@ +class AddSponsorDescriptionToConferences < ActiveRecord::Migration + def change + add_column :conferences, :sponsor_description, :text + end +end diff --git a/db/migrate/20140526064508_add_website_url_to_organization.rb b/db/migrate/20140526064508_add_website_url_to_organization.rb new file mode 100644 index 00000000..cc2fd4ae --- /dev/null +++ b/db/migrate/20140526064508_add_website_url_to_organization.rb @@ -0,0 +1,5 @@ +class AddWebsiteUrlToOrganization < ActiveRecord::Migration + def change + add_column :organizations, :website_url, :string + end +end diff --git a/spec/factories/conferences.rb b/spec/factories/conferences.rb index 8fdbe34d..3acd4103 100644 --- a/spec/factories/conferences.rb +++ b/spec/factories/conferences.rb @@ -9,5 +9,10 @@ FactoryGirl.define do contact_email 'admin@example.com' start_date Date.today end_date Date.tomorrow + factory :conference_with_sponsorship_level do + after(:build) do |conference| + conference.sponsorship_levels << build(:sponsorship_level, conference: conference) + end + end end end diff --git a/spec/factories/organizations.rb b/spec/factories/organizations.rb new file mode 100644 index 00000000..d63c9958 --- /dev/null +++ b/spec/factories/organizations.rb @@ -0,0 +1,9 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :organization do + title 'Example Organization' + sequence(:email_id) { |n| "example#{n}@example.com" } + website_url 'www.example.com' + end +end diff --git a/spec/factories/sponsorship_levels.rb b/spec/factories/sponsorship_levels.rb new file mode 100644 index 00000000..73161153 --- /dev/null +++ b/spec/factories/sponsorship_levels.rb @@ -0,0 +1,9 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :sponsorship_level do + title 'Platin' + description 'Lorem Ipsum' + conference + end +end diff --git a/spec/factories/sponsorship_registrations.rb b/spec/factories/sponsorship_registrations.rb new file mode 100644 index 00000000..b613cc5b --- /dev/null +++ b/spec/factories/sponsorship_registrations.rb @@ -0,0 +1,19 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :sponsorship_registration do + name 'Example Person' + sequence(:email_id) { |n| "example#{n}@example.com" } + contact_no '90000000000' + amount_donated '$1,00,000' + method_of_donation 'Cheque' + conference + sponsorship_level + organization + after(:build) do |sponsorship_registration| + sponsorship_registration.sponsorship_level = + build(:sponsorship_level, + conference: sponsorship_registration.conference) + end + end +end diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 5fe55ab8..c04fd3a7 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -2,7 +2,7 @@ FactoryGirl.define do factory :user do - email 'example@example.com' + sequence(:email) { |n| "example#{n}@example.com" } password 'changeme' password_confirmation 'changeme' confirmed_at Time.now diff --git a/spec/features/sponsorship_levels_spec.rb b/spec/features/sponsorship_levels_spec.rb new file mode 100644 index 00000000..dd54d201 --- /dev/null +++ b/spec/features/sponsorship_levels_spec.rb @@ -0,0 +1,52 @@ +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') + + page. + find('div.nested-fields:nth-of-type(1) div:nth-of-type(2) textarea'). + set('Lorem Ipsum Dolsum') + + 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') + expect(find('div.nested-fields:nth-of-type(1) div:nth-of-type(2) textarea'). + value).to eq('Lorem Ipsum Dolsum') + + # 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/organization_spec.rb b/spec/models/organization_spec.rb new file mode 100644 index 00000000..df10b482 --- /dev/null +++ b/spec/models/organization_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe Organization do + describe 'validations' do + it 'has a valid factory' do + expect(build(:organization)).to be_valid + end + + it 'is not valid without a title' do + should validate_presence_of(:title) + end + + it 'is not valid without a email id' do + should validate_presence_of(:email_id) + end + + it 'is not valid with a duplicate email_id' do + should validate_uniqueness_of(:email_id) + end + end +end diff --git a/spec/models/sponsorship_level_spec.rb b/spec/models/sponsorship_level_spec.rb new file mode 100644 index 00000000..0c4f3f2a --- /dev/null +++ b/spec/models/sponsorship_level_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +describe SponsorshipLevel do + describe 'validations' do + it 'it has 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/models/sponsorship_registration_spec.rb b/spec/models/sponsorship_registration_spec.rb new file mode 100644 index 00000000..6367dc36 --- /dev/null +++ b/spec/models/sponsorship_registration_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +describe SponsorshipRegistration do + describe 'validations' do + it 'has a valid factory' do + expect(build(:sponsorship_registration)).to be_valid + end + + it 'is not valid without a name' do + should validate_presence_of(:name) + end + + it 'is not valid without a email_id' do + should validate_presence_of(:email_id) + end + + it 'is not valid without a contact number' do + should validate_presence_of(:contact_no) + end + + it 'is not valid without a amount donated' do + should validate_presence_of(:amount_donated) + end + + it 'is not valid without a method of donation' do + should validate_presence_of(:method_of_donation) + end + + it 'is not valid without a sponsorship level' do + should validate_presence_of(:sponsorship_level) + end + + it 'is not valid without a organization' do + should validate_presence_of(:organization) + end + + it 'is not valid without a conference' do + should validate_presence_of(:conference) + end + end +end diff --git a/spec/views/conference/show.html.haml_spec.rb b/spec/views/conference/show.html.haml_spec.rb index b822a73e..20bf0e3a 100644 --- a/spec/views/conference/show.html.haml_spec.rb +++ b/spec/views/conference/show.html.haml_spec.rb @@ -1,10 +1,12 @@ require 'spec_helper' describe 'conference/show.html.haml' do it 'renders conference details' do - @conference = create(:conference) + @sponsorship_registration = create(:sponsorship_registration) + @conference = @sponsorship_registration.conference assign :conference, @conference render - expect(render).to include("#{@conference.title}") + expect(view).to render_template(:partial => "conference/_sponsor") + expect(rendered).to include("#{@sponsorship_registration.sponsorship_level.title}") end end