diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..5859406 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.2.3 diff --git a/.travis.yml b/.travis.yml index c693a78..a18bd2e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,4 +4,4 @@ before_install: - gem --version - gem install bundler rvm: - - 2.1.2 + - 2.2.2 diff --git a/Gemfile b/Gemfile index d9eab27..94a4006 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,8 @@ source 'https://rubygems.org' -ruby '2.1.2' +ruby '2.2.2' # Rails -gem 'rails', '4.0.0' +gem 'rails', '4.2.1' # Postgres gem 'pg' @@ -18,6 +18,9 @@ gem 'jquery-rails' gem "oauth" gem "omniauth-twitter" +# Responders +gem 'responders' + # Pagination gem 'will_paginate', '3.0.4' gem 'bootstrap-will_paginate', '0.0.9' @@ -31,6 +34,9 @@ gem 'jbuilder', '~> 1.2' # Giver user.show a friendly URL gem 'friendly_id', "~> 5.0.0" +# Display emoji +gem 'gemoji' + group :doc do # bundle exec rake doc:rails generates the API under doc/api. gem 'sdoc', require: false diff --git a/Gemfile.lock b/Gemfile.lock index 0a4e2ac..1472989 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,62 +1,71 @@ GEM remote: https://rubygems.org/ specs: - actionmailer (4.0.0) - actionpack (= 4.0.0) - mail (~> 2.5.3) - actionpack (4.0.0) - activesupport (= 4.0.0) - builder (~> 3.1.0) - erubis (~> 2.7.0) - rack (~> 1.5.2) + actionmailer (4.2.1) + actionpack (= 4.2.1) + actionview (= 4.2.1) + activejob (= 4.2.1) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 1.0, >= 1.0.5) + actionpack (4.2.1) + actionview (= 4.2.1) + activesupport (= 4.2.1) + rack (~> 1.6) rack-test (~> 0.6.2) - activemodel (4.0.0) - activesupport (= 4.0.0) - builder (~> 3.1.0) - activerecord (4.0.0) - activemodel (= 4.0.0) - activerecord-deprecated_finders (~> 1.0.2) - activesupport (= 4.0.0) - arel (~> 4.0.0) - activerecord-deprecated_finders (1.0.3) - activesupport (4.0.0) - i18n (~> 0.6, >= 0.6.4) - minitest (~> 4.2) - multi_json (~> 1.3) - thread_safe (~> 0.1) - tzinfo (~> 0.3.37) - arel (4.0.2) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.1) + actionview (4.2.1) + activesupport (= 4.2.1) + builder (~> 3.1) + erubis (~> 2.7.0) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.1) + activejob (4.2.1) + activesupport (= 4.2.1) + globalid (>= 0.3.0) + activemodel (4.2.1) + activesupport (= 4.2.1) + builder (~> 3.1) + activerecord (4.2.1) + activemodel (= 4.2.1) + activesupport (= 4.2.1) + arel (~> 6.0) + activesupport (4.2.1) + i18n (~> 0.7) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.3, >= 0.3.4) + tzinfo (~> 1.1) + arel (6.0.0) bootstrap-sass (2.3.2.0) sass (~> 3.2) bootstrap-will_paginate (0.0.9) will_paginate - builder (3.1.4) + builder (3.2.2) capybara (2.1.0) mime-types (>= 1.16) nokogiri (>= 1.3.3) rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) - childprocess (0.5.3) + childprocess (0.5.6) ffi (~> 1.0, >= 1.0.11) coderay (1.1.0) coffee-rails (4.0.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.0) - coffee-script (2.2.0) + coffee-script (2.4.1) coffee-script-source execjs - coffee-script-source (1.7.0) - database_cleaner (1.3.0) + coffee-script-source (1.9.1.1) + database_cleaner (1.4.1) diff-lcs (1.2.5) - docile (1.1.4) - dotenv (0.11.1) - dotenv-deployment (~> 0.0.2) - dotenv-deployment (0.0.2) - dotenv-rails (0.11.1) - dotenv (= 0.11.1) + docile (1.1.5) + dotenv (2.0.1) + dotenv-rails (2.0.1) + dotenv (= 2.0.1) erubis (2.7.0) - execjs (2.2.0) + execjs (2.5.2) factory_girl (4.2.0) activesupport (>= 3.0.0) factory_girl_rails (4.2.1) @@ -64,64 +73,80 @@ GEM railties (>= 3.0.0) faker (1.2.0) i18n (~> 0.5) - ffi (1.9.3) - friendly_id (5.0.4) + ffi (1.9.8) + friendly_id (5.0.5) activerecord (>= 4.0.0) - hashie (2.1.2) + gemoji (2.1.0) + globalid (0.3.5) + activesupport (>= 4.1.0) + hashie (3.4.1) hike (1.2.3) - i18n (0.6.9) + i18n (0.7.0) jbuilder (1.5.3) activesupport (>= 3.0.0) multi_json (>= 1.2.0) - jquery-rails (3.1.0) - railties (>= 3.0, < 5.0) + jquery-rails (4.0.3) + rails-dom-testing (~> 1.0) + railties (>= 4.2.0) thor (>= 0.14, < 2.0) - json (1.8.1) - mail (2.5.4) - mime-types (~> 1.16) - treetop (~> 1.4.8) + json (1.8.2) + loofah (2.0.1) + nokogiri (>= 1.5.9) + mail (2.6.3) + mime-types (>= 1.16, < 3) method_source (0.8.2) - mime-types (1.25.1) - mini_portile (0.6.0) - minitest (4.7.5) - multi_json (1.10.1) - nokogiri (1.6.2.1) - mini_portile (= 0.6.0) + mime-types (2.5) + mini_portile (0.6.2) + minitest (5.6.1) + multi_json (1.11.0) + nokogiri (1.6.6.2) + mini_portile (~> 0.6.0) oauth (0.4.7) - omniauth (1.2.1) - hashie (>= 1.2, < 3) + omniauth (1.2.2) + hashie (>= 1.2, < 4) rack (~> 1.0) - omniauth-oauth (1.0.1) + omniauth-oauth (1.1.0) oauth omniauth (~> 1.0) - omniauth-twitter (1.0.1) - multi_json (~> 1.3) - omniauth-oauth (~> 1.0) - pg (0.17.1) - polyglot (0.3.5) - pry (0.10.0) + omniauth-twitter (1.2.0) + json (~> 1.3) + omniauth-oauth (~> 1.1) + pg (0.18.1) + pry (0.10.1) coderay (~> 1.1.0) method_source (~> 0.8.1) slop (~> 3.4) - rack (1.5.2) - rack-test (0.6.2) + rack (1.6.0) + rack-test (0.6.3) rack (>= 1.0) - rails (4.0.0) - actionmailer (= 4.0.0) - actionpack (= 4.0.0) - activerecord (= 4.0.0) - activesupport (= 4.0.0) + rails (4.2.1) + actionmailer (= 4.2.1) + actionpack (= 4.2.1) + actionview (= 4.2.1) + activejob (= 4.2.1) + activemodel (= 4.2.1) + activerecord (= 4.2.1) + activesupport (= 4.2.1) bundler (>= 1.3.0, < 2.0) - railties (= 4.0.0) - sprockets-rails (~> 2.0.0) - railties (4.0.0) - actionpack (= 4.0.0) - activesupport (= 4.0.0) + railties (= 4.2.1) + sprockets-rails + rails-deprecated_sanitizer (1.0.3) + activesupport (>= 4.2.0.alpha) + rails-dom-testing (1.0.6) + activesupport (>= 4.2.0.beta, < 5.0) + nokogiri (~> 1.6.0) + rails-deprecated_sanitizer (>= 1.0.1) + rails-html-sanitizer (1.0.2) + loofah (~> 2.0) + railties (4.2.1) + actionpack (= 4.2.1) + activesupport (= 4.2.1) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (10.3.2) - rdoc (4.1.1) - json (~> 1.4) + rake (10.4.2) + rdoc (4.2.0) + responders (2.1.0) + railties (>= 4.2.0, < 5) rspec-core (2.14.8) rspec-expectations (2.14.5) diff-lcs (>= 1.1.3, < 2.0) @@ -136,44 +161,42 @@ GEM rspec-mocks (~> 2.14.0) rubyzip (0.9.9) sass (3.2.19) - sass-rails (4.0.3) + sass-rails (4.0.5) railties (>= 4.0.0, < 5.0) - sass (~> 3.2.0) - sprockets (~> 2.8, <= 2.11.0) + sass (~> 3.2.2) + sprockets (~> 2.8, < 3.0) sprockets-rails (~> 2.0) - sdoc (0.4.0) - json (~> 1.8) - rdoc (~> 4.0, < 5.0) + sdoc (0.4.1) + json (~> 1.7, >= 1.7.7) + rdoc (~> 4.0) selenium-webdriver (2.35.1) childprocess (>= 0.2.5) multi_json (~> 1.0) rubyzip (< 1.0.0) websocket (~> 1.0.4) - simplecov (0.8.2) + simplecov (0.10.0) docile (~> 1.1.0) - multi_json - simplecov-html (~> 0.8.0) - simplecov-html (0.8.0) - slop (3.5.0) - sprockets (2.11.0) + json (~> 1.8) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.0) + slop (3.6.0) + sprockets (2.12.3) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - sprockets-rails (2.0.1) + sprockets-rails (2.2.4) actionpack (>= 3.0) activesupport (>= 3.0) - sprockets (~> 2.8) + sprockets (>= 2.8, < 4.0) thor (0.19.1) - thread_safe (0.3.4) + thread_safe (0.3.5) tilt (1.4.1) - treetop (1.4.15) - polyglot - polyglot (>= 0.3.1) - turbolinks (2.2.2) + turbolinks (2.5.3) coffee-rails - tzinfo (0.3.39) - uglifier (2.5.0) + tzinfo (1.2.2) + thread_safe (~> 0.1) + uglifier (2.7.1) execjs (>= 0.3.0) json (>= 1.8.0) websocket (1.0.7) @@ -194,14 +217,16 @@ DEPENDENCIES factory_girl_rails (= 4.2.1) faker (= 1.2.0) friendly_id (~> 5.0.0) + gemoji jbuilder (~> 1.2) jquery-rails oauth omniauth-twitter pg pry - rails (= 4.0.0) + rails (= 4.2.1) rake + responders rspec-rails (~> 2.14.0) sass-rails (~> 4.0.0) sdoc diff --git a/README.md b/README.md index c50f5e9..186acf3 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,6 @@ rake db:test:prepare ```bash rake db:populate ``` -``` These commands do the following: 1. Install all of the necessary gems listed in the Gemfile @@ -40,6 +39,12 @@ TWITTER_KEY= TWITTER_SECRET= ``` +Copy images for emoji + +``` +rake emoji +``` + ## Authors * Melissa Holmes [@meltar](https://github.com/meltar) * Kylie Stradley [@kstradley](https://github.com/kstradley) diff --git a/Rakefile b/Rakefile index d0ad5d6..ed2bc20 100644 --- a/Rakefile +++ b/Rakefile @@ -3,4 +3,7 @@ require File.expand_path('../config/application', __FILE__) +load 'tasks/emoji.rake' + ChallegeMe::Application.load_tasks + diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 384657b..bfbbe05 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -6,4 +6,8 @@ def current_user?(user) false end end + + def champion(user) + emojify ":#{user.champion.name.downcase.tr(" ", "_")}:" + end end diff --git a/app/helpers/emoji_helper.rb b/app/helpers/emoji_helper.rb new file mode 100644 index 0000000..c8f00ac --- /dev/null +++ b/app/helpers/emoji_helper.rb @@ -0,0 +1,11 @@ +module EmojiHelper + def emojify(content) + h(content).to_str.gsub(/:([\w+-]+):/) do |match| + if emoji = Emoji.find_by_alias($1) + %(#$1) + else + match + end + end.html_safe if content.present? + end +end diff --git a/app/models/user.rb b/app/models/user.rb index ec160df..49d70ca 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -14,93 +14,4 @@ def self.search query all end end - - def self.all_champions - [ - 'Alarm clock', - 'Doorknob', - 'Toilet seat', - 'Faucet', - 'Towel', - 'Toothbrush', - 'Contact lens', - 'Glasses ', - 'Shaving Cream', - 'Razor', - 'Soap', - 'Shampoo', - 'Diaper', - 'Kitchen Cabinet', - 'Baby bottle', - 'Bib', - 'Baby food', - 'Baby spoon', - 'Sock', - 'Shoe', - 'Bottle of Dish soap', - 'Keys', - 'Wallet', - 'Cell Phone', - 'Headphones', - 'Coffee Cup', - 'Coffee Maker', - 'Piece of Paper', - 'Frying Pan', - 'Cast Iron Pan', - 'Bacon', - 'Burrito', - 'Taco', - 'Cookie', - 'Muffin', - 'Marshmallow', - 'Fork', - 'Spoon', - 'Spork', - 'Butter Knife', - 'Baby night light', - 'Sunflower seed', - 'Dental floss', - 'Rock', - 'scissors', - 'diary', - 'necklace', - 'blender', - 'Drum stick', - 'guitar', - 'banana', - 'yarn', - 'toenail', - 'popsicle', - 'Potted plant', - 'Post card', - 'Quill pen', - 'Fountain pen', - 'gum', - 'Kitchen twine', - 'sofa', - 'couch', - 'kiwi', - 'cardboard box', - 'pencil', - 'paper clip', - 'kumquat', - 'toaster', - 'strawberry', - 'stapler', - 'comb', - 'toy boat', - 'leaf', - 'lightbulb', - 'push pin', - 'bike lock', - 'apple', - 'ice cream', - 'ten gallon hat', - 'vacuum cleaner', - 'sundial', - 'cookie', - 'orange', - 'pinecone', - ] - end end diff --git a/app/views/challenges/index.html.erb b/app/views/challenges/index.html.erb index ac56326..7794074 100644 --- a/app/views/challenges/index.html.erb +++ b/app/views/challenges/index.html.erb @@ -1,4 +1,4 @@ -

<%= @user.name %>, represented by the brave and loyal <%= @user.champion.name %>


+

<%= @user.name %>, represented by the brave and loyal <%= champion(name) %>


<% unless current_user?(@user) %> <%= button_to "Challenge", challenges_path(:challenged_user => @user.id), method: :post %> <% end %> @@ -14,9 +14,9 @@
    <% @challenges.each do |challenge| %>
  1. - <%= winner_name(challenge.users, challenge.winner_id) %> + <%= winner_name(challenge.users, challenge.winner_id) champion(@user) %> defeated - <%= loser_name(challenge.users, challenge.loser_id) %> + <%= loser_name(challenge.users, challenge.loser_id) champion(@user) %> at <%= challenge.description.downcase %>
  2. diff --git a/app/views/challenges/show.html.erb b/app/views/challenges/show.html.erb index c72b178..c35a25e 100644 --- a/app/views/challenges/show.html.erb +++ b/app/views/challenges/show.html.erb @@ -6,10 +6,10 @@

    Winner
    - <%= @winner.name %>'s <%= @winner.champion.name %>

    + <%= @winner.name %>'s <%= champion(@winner) %>

    Loser
    - <%= @loser.name %>'s <%= @loser.champion.name %>

    + <%= @loser.name %>'s <%= champion(@loser) %>
    diff --git a/app/views/users/_user.html.erb b/app/views/users/_user.html.erb index 4962984..5d38bc7 100644 --- a/app/views/users/_user.html.erb +++ b/app/views/users/_user.html.erb @@ -5,8 +5,8 @@

    <%= link_to "#{user.name}", user_path(user.id) %>

    - - <%= user.champion.name %> + + <%= champion(user) %> Wins: <%= user.wins %> Losses: <%= user.losses %>
    diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 57cd21f..4565487 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -4,7 +4,7 @@

    <%= @user.name %>

    represented by the brave and loyal

    -

    <%= @user.champion.name %>

    +

    <%= champion(@user) %>

    Challenge History

    diff --git a/lib/tasks/sample_data.rake b/lib/tasks/sample_data.rake index d05cf70..e6fbc5b 100644 --- a/lib/tasks/sample_data.rake +++ b/lib/tasks/sample_data.rake @@ -8,7 +8,7 @@ namespace :db do users = User.all users.each do |u| - champ_name = Faker::Commerce.product_name + champ_name = Emoji.all.sample.name u.champion = Champion.create!(name: champ_name) end end diff --git a/lib/user_builder.rb b/lib/user_builder.rb index a9fc2c5..f9fba1f 100644 --- a/lib/user_builder.rb +++ b/lib/user_builder.rb @@ -4,7 +4,7 @@ def build auth user = User.create(name: auth["info"]["nickname"], uid: auth["uid"], ) - champion = Champion.create(name: User.all_champions.sample, + champion = Champion.create(name: Emoji.all.sample.name, user_id: user.id, ) end diff --git a/spec/controllers/challenges_controller_spec.rb b/spec/controllers/challenges_controller_spec.rb index eaff81a..9cbf0fc 100644 --- a/spec/controllers/challenges_controller_spec.rb +++ b/spec/controllers/challenges_controller_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'rails_helper' describe ChallengesController do diff --git a/spec/controllers/sessions_controller_spec.rb b/spec/controllers/sessions_controller_spec.rb index 702c559..dee0f7c 100644 --- a/spec/controllers/sessions_controller_spec.rb +++ b/spec/controllers/sessions_controller_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'rails_helper' describe SessionsController do diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 142455c..27acb63 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'rails_helper' describe UsersController do diff --git a/spec/helpers/challenges_helper_spec.rb b/spec/helpers/challenges_helper_spec.rb index d0841bb..d60292e 100644 --- a/spec/helpers/challenges_helper_spec.rb +++ b/spec/helpers/challenges_helper_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'rails_helper' # Specs in this file have access to a helper object that includes # the ChallengesHelper. For example: diff --git a/spec/helpers/sessions_helper_spec.rb b/spec/helpers/sessions_helper_spec.rb index cc4c89d..8003b8b 100644 --- a/spec/helpers/sessions_helper_spec.rb +++ b/spec/helpers/sessions_helper_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'rails_helper' # Specs in this file have access to a helper object that includes # the SessionsHelper. For example: diff --git a/spec/helpers/users_helper_spec.rb b/spec/helpers/users_helper_spec.rb index 5073928..32f3073 100644 --- a/spec/helpers/users_helper_spec.rb +++ b/spec/helpers/users_helper_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'rails_helper' # Specs in this file have access to a helper object that includes # the UsersHelper. For example: diff --git a/spec/models/challenge_spec.rb b/spec/models/challenge_spec.rb index 3ee4138..f69ce0b 100644 --- a/spec/models/challenge_spec.rb +++ b/spec/models/challenge_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'rails_helper' describe Challenge do subject(:challenge) { described_class.create(description: "being the ugliest") } diff --git a/spec/models/champion_spec.rb b/spec/models/champion_spec.rb index 81313ba..b778972 100644 --- a/spec/models/champion_spec.rb +++ b/spec/models/champion_spec.rb @@ -1,5 +1,5 @@ -require 'spec_helper' +require 'rails_helper' describe Champion do - pending "add some examples to (or delete) #{__FILE__}" + end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 36da80f..6581118 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'rails_helper' describe User do subject(:user) { described_class.create(name: "TwitterName", wins: 0, losses: 0) } diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb new file mode 100644 index 0000000..51f5efc --- /dev/null +++ b/spec/rails_helper.rb @@ -0,0 +1,2 @@ +require 'spec_helper' + diff --git a/spec/requests/user_pages_spec.rb b/spec/requests/user_pages_spec.rb index de617eb..44d960b 100644 --- a/spec/requests/user_pages_spec.rb +++ b/spec/requests/user_pages_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'rails_helper' describe "UserPages" do subject { page } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4d8661b..39de47e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,57 +1,42 @@ -require 'simplecov' -SimpleCov.start - +# This file is copied to spec/ when you run 'rails generate rspec:install' ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'rspec/autorun' -require 'database_cleaner' -#require 'capybara/rspec' - +# Requires supporting ruby files with custom matchers and macros, etc, +# in spec/support/ and its subdirectories. Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } -ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration) - +# Checks for pending migrations before tests are run. +# If you are not using ActiveRecord, you can remove this line. +ActiveRecord::Migration.maintain_test_schema! RSpec.configure do |config| - + # ## Mock Framework + # + # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: + # + # config.mock_with :mocha + # config.mock_with :flexmock + # config.mock_with :rr + + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_path = "#{::Rails.root}/spec/fixtures" + # If you're not using ActiveRecord, or you'd prefer not to run each of your + # examples within a transaction, remove the following line or assign false + # instead of true. config.use_transactional_fixtures = true + # If true, the base class of anonymous controllers will be inferred + # automatically. This will be the default behavior in future versions of + # rspec-rails. config.infer_base_class_for_anonymous_controllers = false + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 config.order = "random" - - def login_with_oauth(service = :twitter) - get "/auth/#{service}/callback" - end - - def login_success(service = :twitter) - visit "/auth/#{service}/callback" - end - - def login_failure - visit "/auth/failure" - end - - # Capybara - config.include Capybara::DSL - - # Database Cleaner - config.before(:suite) do - DatabaseCleaner.strategy = :transaction - DatabaseCleaner.clean_with(:truncation) - end - - config.before(:each) do - DatabaseCleaner.start - end - - config.after(:each) do - DatabaseCleaner.clean - end - end -