diff --git a/.codeclimate.yml b/.codeclimate.yml index db3fa14..1028207 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -18,9 +18,13 @@ engines: ratings: enabled: true paths: - - "app/**/*" - - "lib/**/*" + - app/** + - lib/** - "**.rb" + - "**.css" + - "**.scss" + - "**.js" + - "**.coffee" rubocop: enabled: true exclude_paths: @@ -29,6 +33,7 @@ exclude_paths: - bin/** - db/** - config/** + - coverage/** - public/assets/** - spec/** - UI/** diff --git a/Gemfile b/Gemfile index bf2c3f7..3077092 100644 --- a/Gemfile +++ b/Gemfile @@ -19,8 +19,8 @@ gem 'bootstrap-sass', '~> 3.3.3' gem 'font-awesome-rails', '~> 4.6.3.1' gem 'aasm', '~> 4.2.0' -gem 'activevalidators', '~> 4.0.0' gem 'activerecord-humanized_errors', '~> 2.0.1' +gem 'activevalidators', '~> 4.0.0' gem 'awesome_print', '~> 1.6.1' gem 'faker', '~> 1.4.3' gem 'lograge', '~> 0.4.1' @@ -31,6 +31,7 @@ group :development do gem 'dotenv-rails', '~> 2.0.0' gem 'powder', '~> 0.3.0' gem 'rails_best_practices', '~> 1.16.0' + gem 'rubocop', '~> 0.42.0' gem 'spring', '~> 1.7.2' gem 'spring-commands-rspec', '~> 1.0.4' end @@ -38,13 +39,17 @@ end group :development, :test do gem 'capybara', '~> 2.4.4' gem 'capybara-webkit', '~> 1.4.1' - gem 'fabrication', '~> 2.12.2' gem 'guard-rspec', '~> 4.7.3', require: false gem 'pry-byebug', '~> 3.3.0' + gem 'pry-rails', '~> 0.3.4' gem 'rails-controller-testing', '~> 0.1.1' gem 'rspec-rails', '~> 3.5.1', require: false end +group :development, :review, :test do + gem 'fabrication', '~> 2.12.2' +end + group :production do gem 'airbrake', '~> 5.4.3' gem 'newrelic_rpm', '~> 3.16.0.318' diff --git a/Gemfile.lock b/Gemfile.lock index a3cf097..433204d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -52,6 +52,7 @@ GEM airbrake-ruby (~> 1.4) airbrake-ruby (1.4.4) arel (7.1.1) + ast (2.3.0) autoprefixer-rails (6.3.7) execjs awesome_print (1.6.1) @@ -185,6 +186,8 @@ GEM omniauth-oauth2 (1.4.0) oauth2 (~> 1.0) omniauth (~> 1.2) + parser (2.3.1.2) + ast (~> 2.2) pg (0.18.4) phony (2.15.27) pkg-config (1.1.7) @@ -194,6 +197,7 @@ GEM websocket-driver (>= 0.2.0) powder (0.3.0) thor (>= 0.11.5) + powerpack (0.1.1) pry (0.10.4) coderay (~> 1.1.0) method_source (~> 0.8.1) @@ -201,6 +205,8 @@ GEM pry-byebug (3.3.0) byebug (~> 8.0) pry (~> 0.10) + pry-rails (0.3.4) + pry (>= 0.9.10) puma (3.6.0) rack (2.0.1) rack-test (0.6.3) @@ -245,6 +251,7 @@ GEM method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) + rainbow (2.1.0) rake (10.5.0) rb-fsevent (0.9.7) rb-inotify (0.9.7) @@ -271,6 +278,12 @@ GEM rspec-mocks (~> 3.5.0) rspec-support (~> 3.5.0) rspec-support (3.5.0) + rubocop (0.42.0) + parser (>= 2.3.1.1, < 3.0) + powerpack (~> 0.1) + rainbow (>= 1.99.1, < 3.0) + ruby-progressbar (~> 1.7) + unicode-display_width (~> 1.0, >= 1.0.1) ruby-progressbar (1.8.1) ruby_dep (1.3.1) sass (3.4.22) @@ -316,6 +329,7 @@ GEM thread_safe (~> 0.1) uglifier (3.0.1) execjs (>= 0.3.0, < 3) + unicode-display_width (1.1.1) websocket-driver (0.6.4) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.2) @@ -350,6 +364,7 @@ DEPENDENCIES poltergeist (~> 1.10.0) powder (~> 0.3.0) pry-byebug (~> 3.3.0) + pry-rails (~> 0.3.4) puma (~> 3.6.0) rails (~> 5.0.0) rails-controller-testing (~> 0.1.1) @@ -357,6 +372,7 @@ DEPENDENCIES rails_best_practices (~> 1.16.0) rake (~> 10.5.0) rspec-rails (~> 3.5.1) + rubocop (~> 0.42.0) sass-rails (~> 5.0.6) simplecov (~> 0.12.0) slim-rails (~> 3.1.0) diff --git a/app/assets/stylesheets/app/widgets.css.scss b/app/assets/stylesheets/app/widgets.css.scss index 5c8e476..e7803c2 100644 --- a/app/assets/stylesheets/app/widgets.css.scss +++ b/app/assets/stylesheets/app/widgets.css.scss @@ -125,7 +125,6 @@ } .company a { color: #b3b3b3; - text-transform: uppercase; &:hover { color: #666666; } diff --git a/app/controllers/app/home_controller.rb b/app/controllers/app/home_controller.rb index 8f3f8a1..c50e3c7 100644 --- a/app/controllers/app/home_controller.rb +++ b/app/controllers/app/home_controller.rb @@ -2,13 +2,17 @@ class App::HomeController < AppController def show @event = Event.includes(event_associations).current - @sponsors = Sponsor.active_sponsors + @sponsors = Sponsor.active.shuffle end private def event_associations - { accepted_talks: :speaker, confirmed_speakers: :authorization, venue: :location } + { + accepted_talks: :speaker, + confirmed_speakers: :authorization, + venue: :location + } end end diff --git a/app/helpers/app_helper.rb b/app/helpers/app_helper.rb index 7736359..df077ac 100644 --- a/app/helpers/app_helper.rb +++ b/app/helpers/app_helper.rb @@ -1,5 +1,26 @@ module AppHelper + SOCIAL_URLS = { + facebook: 'facebook.com', + googlegroups: 'groups.google.com/forum/#!forum', + twitter: 'twitter.com' + } + + def link_to_social(resource, link, options = {}) + target = resource.respond_to?(link) ? resource.send(link) : resource + + url = SOCIAL_URLS[link] ? "https://#{SOCIAL_URLS[link]}/#{target}" : target + + return unless url.is_a?(String) + + options[:icon] ||= link + options[:title] ||= '' + + link_to(url, target: '_blank') do + content_tag(:i, nil, class: "fa fa-#{options[:icon]}") << options[:title] + end + end + def oauth_providers [ { @@ -30,6 +51,14 @@ def oauth_providers_for_environment oauth_providers.select{|provider| provider[:name].in?(providers) } end + def render_affiliation(title, org, url = nil) + return unless [title, org].reject(&:blank?).any? + + org = org && url ? link_to(org, url, target: '_blank') : org + + [title, org].reject(&:blank?).join(' en ').try(:html_safe) + end + def render_login_links links = [] diff --git a/app/models/speaker.rb b/app/models/speaker.rb index 0397920..1048743 100644 --- a/app/models/speaker.rb +++ b/app/models/speaker.rb @@ -1,5 +1,9 @@ class Speaker < User - default_scope -> { joins(:talks).having('count(*) > 0').group(:id) } + alias_attribute :link, :url + + has_many :talks + + default_scope -> { where('talks_count > 0') } end diff --git a/app/models/sponsor.rb b/app/models/sponsor.rb index 097e18d..ccce3a0 100644 --- a/app/models/sponsor.rb +++ b/app/models/sponsor.rb @@ -1,3 +1,5 @@ class Sponsor < ActiveRecord::Base - scope :active_sponsors, -> { where(active: true).shuffle } + + scope :active, -> { where(active: true) } + end diff --git a/app/models/talk.rb b/app/models/talk.rb index beadfdb..0d82005 100644 --- a/app/models/talk.rb +++ b/app/models/talk.rb @@ -20,11 +20,11 @@ class Talk < ActiveRecord::Base end end - default_scope { order('id DESC') } - belongs_to :event - belongs_to :speaker, class_name: 'User' + belongs_to :speaker, counter_cache: true + + default_scope { order('id DESC') } - validates_presence_of :event, :speaker, :title, :description + validates_presence_of :event, :speaker, :title end diff --git a/app/models/user.rb b/app/models/user.rb index cbef732..74f7f41 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,11 +1,8 @@ class User < ActiveRecord::Base - has_many :talks, foreign_key: 'speaker_id' - has_one :authorization validates :email, email: { strict: true, message: 'is invalid' } - validates_presence_of :authorization, on: :update validates_presence_of :email, :name validates_uniqueness_of :email @@ -15,14 +12,14 @@ def avatar_url private - def full_user_photo_path(nickname) - Dir.glob("app/assets/images/speakers/**/#{nickname}.{jpg,jpeg,png}").first - end - def auth_photo_url authorization.photo_url if authorization end + def full_user_photo_path(nickname) + Dir.glob("app/assets/images/speakers/**/#{nickname}.{jpg,jpeg,png}").first + end + def local_photo_path full_user_photo_path(twitter).try(:sub, %r{.*(speakers)}, 'assets/\1') end diff --git a/app/views/admin/speakers/_form.html.slim b/app/views/admin/speakers/_form.html.slim index 5ccd975..57f258a 100644 --- a/app/views/admin/speakers/_form.html.slim +++ b/app/views/admin/speakers/_form.html.slim @@ -1,20 +1,51 @@ -= form_for [:admin, speaker], html: { class: "form-horizontal" } do |f| += form_for [:admin, speaker], html: { class: 'form-horizontal' } do |f| .form-group - = f.label :name, "Nombre", class: "col-md-2" + = f.label :name, 'Nombre', class: 'col-md-2' .col-md-8 - = f.text_field :name, class: "form-control" + = f.text_field :name, class: 'form-control' .form-group - = f.label :email, "Correo", class: "col-md-2" + = f.label :email, 'Correo', class: 'col-md-2' .col-md-8 - = f.email_field :email, class: "form-control" + = f.email_field :email, class: 'form-control' .form-group - = f.label :twitter, "Twitter", class: "col-md-2" + = f.label :url, 'Sitio Web', class: 'col-md-2' .col-md-8 - = f.text_field :twitter, class: "form-control" + = f.text_field :url, class: 'form-control' + + .form-group + = f.label :facebook, 'Facebook', class: 'col-md-2' + .col-md-8 + = f.text_field :facebook, class: 'form-control' + + .form-group + = f.label :twitter, 'Twitter', class: 'col-md-2' + .col-md-8 + = f.text_field :twitter, class: 'form-control' + + fieldset + legend.col-md-10 Organización + + .clearfix + + .form-group + = f.label :title, 'Rol', class: 'col-md-2' + .col-md-8 + = f.text_field :title, class: 'form-control' + + .form-group + = f.label :organization_name, 'Nombre', class: 'col-md-2' + .col-md-8 + = f.text_field :organization_name, class: 'form-control' + + .form-group + = f.label :organization_url, 'Sitio Web', class: 'col-md-2' + .col-md-8 + = f.text_field :organization_url, class: 'form-control' + .form-group .col-md-offset-2.col-md-2 - = f.submit "#{speaker.new_record? ? "Crear" : "Guardar"} ponente", class: "btn btn-primary" + = f.submit "#{speaker.new_record? ? 'Crear' : 'Guardar'} ponente", class: 'btn btn-primary' diff --git a/app/views/app/home/_speakers.html.slim b/app/views/app/home/_speakers.html.slim index 59be217..1392427 100644 --- a/app/views/app/home/_speakers.html.slim +++ b/app/views/app/home/_speakers.html.slim @@ -1,30 +1,24 @@ -- if event.confirmed_speakers.present? +- if talks.present? #speakers.speakers.widget-content .row .columns.small-12.medium-12.large-12 .center-content h2 Ponentes div - ul.small-block-grid-1.medium-block-grid-2 class="large-block-grid-#{event.confirmed_speakers.size}" - - event.accepted_talks.each do |talk| + ul.small-block-grid-1.medium-block-grid-2 class="large-block-grid-#{talks.size}" + - talks.map{|talk| [talk, talk.speaker] }.each do |talk, speaker| li .avatar - img alt="Imágen de perfil de #{talk.speaker.name}" height='220' src="#{talk.speaker.avatar_url}" width='220' + = image_tag(speaker.avatar_url, height: 220, width: 220) .social - /! Speaker profile / blog url - /a href='#' target='_blank' - /i.fa.fa-user - /! Speaker Twitter URL - a href="https://twitter.com/#{talk.speaker.twitter}" - i.fa.fa-twitter - /! Speaker Facebook URL - /a href='#' - /i.fa.fa-facebook + - %i{ link facebook twitter }.each do |profile| + = link_to_social(speaker, profile) + .title + = talk.title .name - a[href='#' target='_blank'] = talk.speaker.name - .company = talk.title - /a href='http://tauziet.com/' target='_blank' Facebook - /! View all Speakers Button - /.view-all-speakers - /a.btn-default href='speakers.html' VE A TODOS LOS PONENTES - + - if speaker.url.present? + = link_to(speaker.name, speaker.url, target: '_blank') + - else + = speaker.name + .company + = render_affiliation(speaker.title, speaker.organization_name, speaker.organization_url) diff --git a/app/views/app/home/_sponsors.html.slim b/app/views/app/home/_sponsors.html.slim index 8a4aec9..98d47f7 100644 --- a/app/views/app/home/_sponsors.html.slim +++ b/app/views/app/home/_sponsors.html.slim @@ -6,6 +6,5 @@ div ul.small-block-grid-1.medium-block-grid-2.large-block-grid-4 - sponsors.each do |sponsor| - li - = link_to sponsor[:website], target: '_blank' do - = image_tag sponsor[:image], height: 85, width: 200 + li= link_to sponsor.website, target: '_blank' do + = image_tag sponsor.image, height: 85, width: 200 diff --git a/app/views/app/home/_venue.html.slim b/app/views/app/home/_venue.html.slim index cdf500f..21a52a4 100644 --- a/app/views/app/home/_venue.html.slim +++ b/app/views/app/home/_venue.html.slim @@ -2,9 +2,9 @@ .row .columns.small-12.medium-12.large-12 .center-content - h2 Lugar: #{event.venue.name} + h2 Lugar: #{venue.name} .row .columns.small-12.medium-12.large-12 .center-content .map - = render_map(event.venue, width: '100%', height: '365px') + = render_map(venue, width: '100%', height: '365px') diff --git a/app/views/app/home/show.html.slim b/app/views/app/home/show.html.slim index 9a30a31..d89dea6 100644 --- a/app/views/app/home/show.html.slim +++ b/app/views/app/home/show.html.slim @@ -5,7 +5,7 @@ .center-content .logo h1#site-title - img src='assets/logo-curvas.png' alt='Web Dev Talks' + = image_tag('logo-curvas', alt: 'WebDevTalks Logo') .sub-logo h2#site-description Aprendiendo y compartiendo = render partial: 'event', locals: { event: @event } @@ -13,18 +13,12 @@ .large-6.small-centered.columns .event-social ul.small-block-grid-1.medium-block-grid-3.large-block-grid-3 - li - a href='https://twitter.com/webdevtalksmx' - i.fa.fa-twitter Twitter - li - a href='https://www.facebook.com/ColimaWebDevTalks' - i.fa.fa-facebook Facebook - li - a href='https://groups.google.com/forum/#!forum/webdevtalks' - i.fa.fa-google-plus Google Foro + li= link_to_social('webdevtalksmx', :twitter, title: 'Twitter') + li= link_to_social('ColimaWebDevTalks', :facebook, title: 'Facebook') + li= link_to_social('webdevtalks', :googlegroups, icon: 'google-plus', title: 'Foro') -= render partial: 'speakers', locals: { event: @event } -= render partial: 'venue', locals: { event: @event } += render partial: 'speakers', locals: { talks: @event.accepted_talks } += render partial: 'venue', locals: { venue: @event.venue } = render partial: 'sponsors', locals: { sponsors: @sponsors } = render 'about' diff --git a/db/migrate/20160903170837_add_url_to_users.rb b/db/migrate/20160903170837_add_url_to_users.rb new file mode 100644 index 0000000..ebb6821 --- /dev/null +++ b/db/migrate/20160903170837_add_url_to_users.rb @@ -0,0 +1,5 @@ +class AddUrlToUsers < ActiveRecord::Migration[5.0] + def change + add_column :users, :url, :string + end +end diff --git a/db/migrate/20160903172330_add_facebook_to_users.rb b/db/migrate/20160903172330_add_facebook_to_users.rb new file mode 100644 index 0000000..f8ceb06 --- /dev/null +++ b/db/migrate/20160903172330_add_facebook_to_users.rb @@ -0,0 +1,5 @@ +class AddFacebookToUsers < ActiveRecord::Migration[5.0] + def change + add_column :users, :facebook, :string + end +end diff --git a/db/migrate/20160903180657_add_affiliation_to_users.rb b/db/migrate/20160903180657_add_affiliation_to_users.rb new file mode 100644 index 0000000..1558dae --- /dev/null +++ b/db/migrate/20160903180657_add_affiliation_to_users.rb @@ -0,0 +1,9 @@ +class AddAffiliationToUsers < ActiveRecord::Migration[5.0] + def change + change_table :users do |t| + t.string :title + t.string :organization_name + t.string :organization_url + end + end +end diff --git a/db/migrate/20160903213111_add_talks_count_to_users.rb b/db/migrate/20160903213111_add_talks_count_to_users.rb new file mode 100644 index 0000000..27bfc46 --- /dev/null +++ b/db/migrate/20160903213111_add_talks_count_to_users.rb @@ -0,0 +1,5 @@ +class AddTalksCountToUsers < ActiveRecord::Migration[5.0] + def change + add_column :users, :talks_count, :integer, default: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index a51b898..5093dc3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160801001048) do +ActiveRecord::Schema.define(version: 20160903213111) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -81,6 +81,12 @@ t.datetime "updated_at" t.string "twitter" t.string "photo_url" + t.string "url" + t.string "facebook" + t.string "title" + t.string "organization_name" + t.string "organization_url" + t.integer "talks_count", default: 0 end create_table "venues", force: :cascade do |t| diff --git a/db/seeds.rb b/db/seeds.rb index 099849c..f6297b5 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,50 +1,22 @@ unless Rails.env.production? + Faker::Config.locale = 'es' puts 'Creating location' - location = Location.create!( - city: 'Colima', - state: 'Colima', - country: 'México' - ) + location = Location.create(city: 'Colima', state: 'Colima', country: 'México') puts 'Creating venue' - venue = Venue.create!( - name: Faker::Company.name, - description: Faker::Lorem.paragraphs.join, - address: "#{Faker::Address.street_suffix} #{Faker::Address.street_address}, #{location.name}, #{Faker::Address.postcode}", - location: location - ) + venue = Fabricate(:venue, location: location) puts 'Creating event' - event = Event.create!( - venue: venue, - date: 15.days.from_now, - theme: "#{Faker::Hacker.adjective.titleize} #{Faker::Hacker.noun}" - ) + event = Fabricate(:event, date: 15.days.from_now, venue: venue) - puts 'Creating speakers' - speakers = [] + puts 'Creating sponsors' + puts 'Creating sponsors, talks and speakers' 4.times do - speakers << User.create!( - name: Faker::Name.name, - email: Faker::Internet.email, - photo_url: Faker::Avatar.image(nil, '200x200', 'jpg').gsub('http', 'https'), - twitter: Faker::Internet.user_name - ) - end - - puts 'Creating event talk proposals' - speakers.each do |speaker| - speaker.talks.create!( - title: "#{Faker::Hacker.ingverb.titleize} #{Faker::Hacker.adjective} #{Faker::Hacker.noun}", - description: Faker::Lorem.paragraphs.join, - event: event, - status: :proposal - ) + Fabricate(:sponsor, active: true) + Fabricate(:talk, status: :accepted, event: event) end - puts 'Accepting event talks' - event.talks.all.sample(2).each(&:accept!) end diff --git a/spec/fabricators/location_fabricator.rb b/spec/fabricators/location_fabricator.rb index fe01ea0..6bbeca7 100644 --- a/spec/fabricators/location_fabricator.rb +++ b/spec/fabricators/location_fabricator.rb @@ -1,5 +1,5 @@ Fabricator :location do city { Faker::Address.city } - country { Faker::Address.country } + country 'México' state { Faker::Address.state } end diff --git a/spec/fabricators/speaker_fabricator.rb b/spec/fabricators/speaker_fabricator.rb new file mode 100644 index 0000000..e3f28ad --- /dev/null +++ b/spec/fabricators/speaker_fabricator.rb @@ -0,0 +1,19 @@ +Fabricator :speaker do + name { Faker::Name.name } + email { |f| "#{f[:name].parameterize}@example.org" } + url { |f| "https://#{f[:name].parameterize}.example.org" } + facebook { |f| "fake_#{f[:name].parameterize}" } + twitter { |f| "fake_#{f[:name].parameterize}" } + + title { [Faker::Name.title, nil].sample } + organization_name { [Faker::Company.name, nil].sample } + organization_url do |f| + if f[:organization_name] + ["https://#{f[:organization_name].parameterize}.example.com", nil].sample + end + end + + photo_url do + Faker::Avatar.image(nil, '200x200', 'jpg').gsub('http', 'https') + end +end diff --git a/spec/fabricators/sponsor_fabricator.rb b/spec/fabricators/sponsor_fabricator.rb index c3f18e8..9ee5c28 100644 --- a/spec/fabricators/sponsor_fabricator.rb +++ b/spec/fabricators/sponsor_fabricator.rb @@ -1,6 +1,6 @@ Fabricator(:sponsor) do - name "MyString" - website "MyString" - twitter "MyString" - image "MyString" + name { Faker::Company.name } + image { Faker::Company.logo } + website {|f| "http://example.org/#{f[:name].downcase.strip}" } + twitter {|f| "https://twitter.com/#{f[:name].strip}" } end diff --git a/spec/fabricators/talk_fabricator.rb b/spec/fabricators/talk_fabricator.rb new file mode 100644 index 0000000..4fadc8c --- /dev/null +++ b/spec/fabricators/talk_fabricator.rb @@ -0,0 +1,8 @@ +Fabricator :talk do + title { "#{Faker::Hacker.ingverb.titleize} #{Faker::Hacker.adjective} #{Faker::Hacker.noun}" } + description { Faker::Lorem.paragraphs.join } + status { %i{ accepted proposal rejected }.sample } + + event + speaker +end diff --git a/spec/fabricators/venue_fabricator.rb b/spec/fabricators/venue_fabricator.rb index c1e6869..97681b7 100644 --- a/spec/fabricators/venue_fabricator.rb +++ b/spec/fabricators/venue_fabricator.rb @@ -1,6 +1,12 @@ Fabricator :venue do name { Faker::Company.name } description { Faker::Company.bs } + address { Faker::Address.street_address } + + latitude { Faker::Number.between(-90.00, 90.00) } + longitude { Faker::Number.between(-180.00, 180.00) } + + override_map_with_coordinates true location end diff --git a/spec/helpers/app_helper_spec.rb b/spec/helpers/app_helper_spec.rb index 2834a5f..56e4b72 100644 --- a/spec/helpers/app_helper_spec.rb +++ b/spec/helpers/app_helper_spec.rb @@ -2,6 +2,51 @@ describe AppHelper do + describe '#link_to_social' do + context 'when resource does not respond to link or isnt a string' do + it 'returns nothing' do + speaker = Fabricate(:speaker) + expect(helper.link_to_social(speaker, 'nope')).to be_nil + end + end + + it 'returns link for given profile when link is a social network' do + expect(helper.link_to_social('foo', :googlegroups)).to have_selector( + 'a[href="https://groups.google.com/forum/#!forum/foo"]' + ) + end + + it 'returns nothing when resource link is empty' do + speaker = Fabricate(:speaker, url: nil) + expect(helper.link_to_social(speaker, 'url')).to be_nil + end + + context 'when link is known a social network' do + it 'returns twiter link for resource' do + speaker = Fabricate(:speaker, twitter: 'foo') + result = helper.link_to_social(speaker, :twitter) + + expect(result).to have_selector('a[href="https://twitter.com/foo"]') + end + + it 'returns facebook link for resource' do + speaker = Fabricate(:speaker, facebook: 'foo') + result = helper.link_to_social(speaker, :facebook) + + expect(result).to have_selector('a[href="https://facebook.com/foo"]') + end + end + + context 'when link is not a social network' do + it "returns link pointing to link resource's value" do + speaker = Fabricate(:speaker, url: 'http://me.example.org') + result = helper.link_to_social(speaker, :link) + + expect(result).to have_selector('a[href="http://me.example.org"]') + end + end + end + describe '#oauth_providers' do it 'returns all oauth providers metadata' do helper.oauth_providers.each do |provider| @@ -41,6 +86,38 @@ end end + describe '#render_affiliation' do + context 'when title and org are blank' do + it 'returns nothing' do + expect(helper.render_affiliation(nil, nil)).to be_nil + end + end + + context 'when only title is present' do + it 'returns title' do + expect(helper.render_affiliation('John', nil)).to eq('John') + end + end + + context 'when title is not present' do + it 'returns org if present' do + expect(helper.render_affiliation(nil, 'Foo')).to eq('Foo') + end + + it 'returns a link to org if url is also present' do + result = helper.render_affiliation(nil, 'Foo', 'http://example.org') + + expect(result).to have_selector('a[href="http://example.org"]') + expect(result).to have_content('Foo') + end + + it 'returns nothing if only url is present' do + result = helper.render_affiliation(nil, nil, 'http://example.org') + expect(result).to be_nil + end + end + end + describe '#render_login_links' do it 'returns links targeting login paths to oauth providers' do helper.oauth_providers.each do |provider|