Commit bd28c3c5 authored by marcheing's avatar marcheing

Auto fix rubocop's offenses

parent 163744d8
......@@ -81,12 +81,12 @@ group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
#Unit test framework
# Unit test framework
# This beta is tested against Rails 5. Once it gets released use the stable version.
gem 'rspec-rails', '>= 3.5.0.beta1'
# Javascript test runner for Rails
gem "teaspoon-mocha"
gem 'teaspoon-mocha'
# Fixtures creation and management
gem 'factory_girl'
......@@ -108,7 +108,7 @@ end
group :test do
# Acceptance tests framework
gem 'cucumber-rails', :require => false
gem 'cucumber-rails', require: false
# Database cleanup for each scenario
gem 'database_cleaner'
......@@ -120,7 +120,7 @@ group :test do
gem 'shoulda-matchers', '~> 3.1'
# Test coverage report
gem 'simplecov', :require => false
gem 'simplecov', require: false
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
......
......@@ -48,22 +48,23 @@ class ContentsController < ApplicationController
end
private
# Use callbacks to share common setup or constraints between actions.
def set_content
@content = Content.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def content_params
params.require(:content).permit(:title, :user_id, :adult, :rating, :soundtrack, :view_count, :deleted, :zip_code, :director, :co_director, :team, :allow_comments, :video)
end
# Use callbacks to share common setup or constraints between actions.
def set_content
@content = Content.find(params[:id])
end
def find_last_encoded_video
@encoded_video = @content.encoded_contents.last
redirect_to root_path, notice: I18n.t('video_has_not_finished_encoding') unless @encoded_video.state == 'finished'
end
def check_profile
redirect_to new_profile_path, notice: I18n.t('need_complete_profile_to_send_content') if current_user.profile.nil?
end
def check_profile
redirect_to new_profile_path, notice: I18n.t('need_complete_profile_to_send_content') if current_user.profile.nil?
end
# Never trust parameters from the scary internet, only allow the white list through.
def content_params
params.require(:content).permit(:title, :user_id, :adult, :rating, :soundtrack, :view_count, :deleted, :zip_code, :director, :co_director, :team, :allow_comments, :video)
end
def find_last_encoded_video
@encoded_video = @content.encoded_contents.last
redirect_to root_path, notice: I18n.t('video_has_not_finished_encoding') unless @encoded_video.state == 'finished'
end
end
......@@ -57,23 +57,24 @@ class ProfilesController < ApplicationController
end
private
# Use callbacks to share common setup or constraints between actions.
def set_profile
@profile = Profile.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def profile_params
complete_params = params.require(:profile).permit(:first_name, :last_name, :gender, :state, :city, :country, :school, :responsible_document, :responsible_name, :receive_mass_email, :phone, :user_id, :address, :zip_code, :occupation, :school_type)
complete_params[:birthdate] = Date.new params[:profile][:year].to_i, params[:profile][:month].to_i, params[:profile][:day].to_i
complete_params
end
# Use callbacks to share common setup or constraints between actions.
def set_profile
@profile = Profile.find(params[:id])
end
def set_carmen_locale
Carmen.i18n_backend.locale = I18n.locale.to_s.split('-').first
end
# Never trust parameters from the scary internet, only allow the white list through.
def profile_params
complete_params = params.require(:profile).permit(:first_name, :last_name, :gender, :state, :city, :country, :school, :responsible_document, :responsible_name, :receive_mass_email, :phone, :user_id, :address, :zip_code, :occupation, :school_type)
complete_params[:birthdate] = Date.new params[:profile][:year].to_i, params[:profile][:month].to_i, params[:profile][:day].to_i
complete_params
end
def states_params
params.require(:country)
end
def set_carmen_locale
Carmen.i18n_backend.locale = I18n.locale.to_s.split('-').first
end
def states_params
params.require(:country)
end
end
......@@ -22,4 +22,3 @@ class Content < ApplicationRecord
RequestZencoderJob.perform_later(self)
end
end
......@@ -3,7 +3,7 @@ class Profile < ApplicationRecord
validates :terms_of_service, acceptance: true
validates :first_name, :last_name, :country, :state, :city,
:zip_code, :birthdate, :gender, :occupation, presence: true
:zip_code, :birthdate, :gender, :occupation, presence: true
validates :responsible_name, :responsible_document, presence: true, if: :underaged?
def adult?
......
......@@ -2,8 +2,8 @@ class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:confirmable, :lockable, :timeoutable
:recoverable, :rememberable, :trackable, :validatable,
:confirmable, :lockable, :timeoutable
validates :email, confirmation: true
......
......@@ -27,7 +27,7 @@ When(/^I fill the director field with my name$/) do
end
When(/^I mark the specific location checkbox$/) do
step "I check the \"video-has-location\" box"
step 'I check the "video-has-location" box'
end
When(/^I fill the zip code field with my zip code$/) do
......
......@@ -7,7 +7,7 @@ Given(/^I should see "(.*?)"$/) do |content|
end
When(/^I take a picture of the page$/) do
page.save_screenshot("/tmp/picture.png")
page.save_screenshot('/tmp/picture.png')
end
When(/^I click on the "(.*?)" link$/) do |link|
......
......@@ -33,4 +33,3 @@ end
Then(/^I should be able to see the share button$/) do
expect(has_css?('a[id^="vjs-share-button"]')).to eq true
end
......@@ -11,7 +11,7 @@ Given(/^I select "(.*?)" as my birthdate's (.*?)$/) do |value, field|
end
Given(/^I mark the terms of service checkbox$/) do
step "I check the \"user-terms\" box"
step 'I check the "user-terms" box'
end
When(/^I click on the button to send the profile information$/) do
......@@ -57,7 +57,7 @@ Given(/^I try to see a nonexistent profile$/) do
end
Then(/^I should see the error message for occupation can't be blank$/) do
step "I should see \"#{I18n.t 'errors.format', {attribute: Profile.human_attribute_name('occupation'), message: I18n.t('errors.messages.blank')}}\""
step "I should see \"#{I18n.t 'errors.format', attribute: Profile.human_attribute_name('occupation'), message: I18n.t('errors.messages.blank')}\""
end
Then(/^I should see the not found page$/) do
......
require 'English'
Given(/^the user has a complete profile$/) do
@profile = create(:profile, user_id: @user.id)
end
......@@ -25,7 +27,7 @@ end
Then(/^I should receive a successful notification$/) do
`zencoder_fetcher -u #{ZencoderSettings.notifications.url} #{ZencoderSettings.api_key} -n 1 -x`
expect($?.success?).to eq true
expect($CHILD_STATUS.success?).to eq true
end
Then(/^the encoded content should have been updated$/) do
......
# Run all acceptance tests on the default language
Before do |scenario|
if defined?(page) && ! page.driver.nil?
Before do |_scenario|
if defined?(page) && !page.driver.nil?
header_method = [:add_header, :header].find(&page.driver.method(:respond_to?))
page.driver.send(header_method, 'Accept-Language', I18n.default_locale) if header_method
end
......
......@@ -4,73 +4,72 @@
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
# files.
unless ARGV.any? { |a| a =~ /^gems/ } # Don't load anything when running the gems:* tasks
unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks
vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
$LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil?
vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
$LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil?
begin
require 'cucumber/rake/task'
begin
require 'cucumber/rake/task'
namespace :cucumber do
Cucumber::Rake::Task.new({:ok => 'test:prepare'}, 'Run features that should pass') do |t|
t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
t.fork = true # You may get faster startup if you set this to false
t.profile = 'default'
end
namespace :cucumber do
Cucumber::Rake::Task.new({ok: 'test:prepare'}, 'Run features that should pass') do |t|
t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
t.fork = true # You may get faster startup if you set this to false
t.profile = 'default'
end
Cucumber::Rake::Task.new({:wip => 'test:prepare'}, 'Run features that are being worked on') do |t|
t.binary = vendored_cucumber_bin
t.fork = true # You may get faster startup if you set this to false
t.profile = 'wip'
end
Cucumber::Rake::Task.new({wip: 'test:prepare'}, 'Run features that are being worked on') do |t|
t.binary = vendored_cucumber_bin
t.fork = true # You may get faster startup if you set this to false
t.profile = 'wip'
end
Cucumber::Rake::Task.new({:rerun => 'test:prepare'}, 'Record failing features and run only them if any exist') do |t|
t.binary = vendored_cucumber_bin
t.fork = true # You may get faster startup if you set this to false
t.profile = 'rerun'
end
Cucumber::Rake::Task.new({rerun: 'test:prepare'}, 'Record failing features and run only them if any exist') do |t|
t.binary = vendored_cucumber_bin
t.fork = true # You may get faster startup if you set this to false
t.profile = 'rerun'
end
desc 'Run all features'
task :all => [:ok, :wip]
desc 'Run all features'
task all: [:ok, :wip]
task :statsetup do
require 'rails/code_statistics'
::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?('features')
::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?('features')
end
task :statsetup do
require 'rails/code_statistics'
::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?('features')
::CodeStatistics::TEST_TYPES << 'Cucumber features' if File.exist?('features')
end
task :annotations_setup do
Rails.application.configure do
if config.respond_to?(:annotations)
config.annotations.directories << 'features'
config.annotations.register_extensions('feature') { |tag| /#\s*(#{tag}):?\s*(.*)$/ }
task :annotations_setup do
Rails.application.configure do
if config.respond_to?(:annotations)
config.annotations.directories << 'features'
config.annotations.register_extensions('feature') { |tag| /#\s*(#{tag}):?\s*(.*)$/ }
end
end
end
end
end
desc 'Alias for cucumber:ok'
task :cucumber => 'cucumber:ok'
desc 'Alias for cucumber:ok'
task cucumber: 'cucumber:ok'
task :default => :cucumber
task default: :cucumber
task :features => :cucumber do
STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
end
task features: :cucumber do
STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
end
# In case we don't have the generic Rails test:prepare hook, append a no-op task that we can depend upon.
task 'test:prepare' do
end
# In case we don't have the generic Rails test:prepare hook, append a no-op task that we can depend upon.
task 'test:prepare' do
end
task :stats => 'cucumber:statsetup'
task stats: 'cucumber:statsetup'
task :notes => 'cucumber:annotations_setup'
rescue LoadError
desc 'cucumber rake task not available (cucumber not installed)'
task :cucumber do
abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
task notes: 'cucumber:annotations_setup'
rescue LoadError
desc 'cucumber rake task not available (cucumber not installed)'
task :cucumber do
abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
end
end
end
end
task :default => 'teaspoon'
task default: 'teaspoon'
......@@ -128,9 +128,11 @@ RSpec.describe ContentsController, type: :controller do
describe 'POST #zencoder_callback' do
let!(:job_id) { '1' }
let!(:thumb_output) { [ images: [ url: 'http://test.com' ] ] }
let!(:output) { { id: '2', state: 'finished', width: '640', height: '320', duration_in_ms: '5000',
file_size_in_bytes: '1024', url: 'http://test.com', thumbnails: thumb_output } }
let!(:thumb_output) { [images: [url: 'http://test.com']] }
let!(:output) {
{ id: '2', state: 'finished', width: '640', height: '320', duration_in_ms: '5000',
file_size_in_bytes: '1024', url: 'http://test.com', thumbnails: thumb_output }
}
let!(:outputs) { [output] }
let!(:video_file_mock) { instance_double('video_file') }
let!(:thumb_file_mock) { instance_double('thumb_file') }
......
require 'rails_helper'
describe HomeController, :type => :controller do
describe HomeController, type: :controller do
context 'actions' do
context 'index' do
describe 'Rendering' do
......
......@@ -65,21 +65,21 @@ RSpec.describe ProfilesController, type: :controller do
end
end
describe "POST #create" do
context "with valid params" do
it "creates a new Profile" do
describe 'POST #create' do
context 'with valid params' do
it 'creates a new Profile' do
expect {
post :create, params: { profile: valid_request_parameters }
}.to change(Profile, :count).by(1)
end
it "redirects to the created profile" do
it 'redirects to the created profile' do
post :create, params: { profile: valid_request_parameters }
expect(response).to redirect_to(root_path)
end
end
context "with invalid params" do
context 'with invalid params' do
before do
expect_any_instance_of(Profile).to receive(:save).and_return false
post :create, params: { profile: valid_request_parameters }
......@@ -89,31 +89,31 @@ RSpec.describe ProfilesController, type: :controller do
end
end
describe "PUT #update" do
describe 'PUT #update' do
let(:profile) { build(:profile) }
before do
expect(Profile).to receive(:find).with(profile.id.to_s).and_return profile
end
context "with valid params" do
context 'with valid params' do
let(:new_attributes) {
skip("Add a hash of attributes valid for your model")
skip('Add a hash of attributes valid for your model')
}
it "updates the requested profile" do
it 'updates the requested profile' do
put :update, params: {id: profile.to_param, profile: new_attributes}
profile.reload
skip("Add assertions for updated state")
skip('Add assertions for updated state')
end
it "redirects to the profile" do
it 'redirects to the profile' do
put :update, params: {id: profile.to_param, profile: valid_request_parameters }
expect(response).to redirect_to(profile)
end
end
context "with invalid params" do
context 'with invalid params' do
before do
expect_any_instance_of(Profile).to receive(:update).and_return false
put :update, params: {id: profile.to_param, profile: valid_request_parameters }
......@@ -123,19 +123,19 @@ RSpec.describe ProfilesController, type: :controller do
end
end
describe "DELETE #destroy" do
describe 'DELETE #destroy' do
let(:profile) { build(:profile) }
before do
expect(Profile).to receive(:find).with(profile.id.to_s).and_return profile
end
it "destroys the requested profile" do
it 'destroys the requested profile' do
expect(profile).to receive(:destroy)
delete :destroy, params: { id: profile.id }
end
it "redirects to the profiles list" do
it 'redirects to the profiles list' do
delete :destroy, params: {id: profile.to_param}
expect(response).to redirect_to(profiles_url)
end
......
require 'rails_helper'
describe StaticViewsController, :type => :controller do
describe StaticViewsController, type: :controller do
context 'actions' do
context 'terms_of_use' do
context 'rendering' do
......
......@@ -20,17 +20,17 @@ FactoryGirl.define do
factory :another_profile, class: Profile do
sequence(:id, 1)
first_name "Name"
country "BR"
city "Rio de Janeiro"
responsible_document "532221420"
first_name 'Name'
country 'BR'
city 'Rio de Janeiro'
responsible_document '532221420'
birthdate Date.yesterday
responsible_name "Name"
gender "Female"
last_name "Last"
school "School"
phone "012246654"
state "Rio de Janeiro"
responsible_name 'Name'
gender 'Female'
last_name 'Last'
school 'School'
phone '012246654'
state 'Rio de Janeiro'
terms_of_service '1'
association :user, strategy: :build
zip_code '00000-098'
......
......@@ -11,9 +11,11 @@ RSpec.describe Content, type: :model do
describe 'paperclip attachments' do
it { is_expected.to have_attached_file(:video) }
it { is_expected.to validate_attachment_presence(:video) }
it { is_expected.to validate_attachment_content_type(:video).
allowing('video/mp4', 'video/x-flv', 'video/MP2T', 'video/3gpp', 'video/quicktime', 'video/x-msvideo', 'video/x-ms-wmv').
rejecting('text/plain', 'text/xml', 'image/png', 'image/gif') }
it {
is_expected.to validate_attachment_content_type(:video)
.allowing('video/mp4', 'video/x-flv', 'video/MP2T', 'video/3gpp', 'video/quicktime', 'video/x-msvideo', 'video/x-ms-wmv')
.rejecting('text/plain', 'text/xml', 'image/png', 'image/gif')
}
end
describe 'relations' do
......
......@@ -8,14 +8,18 @@ RSpec.describe EncodedContent, type: :model do
describe 'paperclip attachments' do
it { is_expected.to have_attached_file(:video) }
it { is_expected.to validate_attachment_content_type(:video).
allowing('video/mp4', 'video/x-flv', 'video/MP2T', 'video/3gpp', 'video/quicktime', 'video/x-msvideo', 'video/x-ms-wmv').
rejecting('text/plain', 'text/xml', 'image/png', 'image/gif') }
it {
is_expected.to validate_attachment_content_type(:video)
.allowing('video/mp4', 'video/x-flv', 'video/MP2T', 'video/3gpp', 'video/quicktime', 'video/x-msvideo', 'video/x-ms-wmv')
.rejecting('text/plain', 'text/xml', 'image/png', 'image/gif')
}
it { is_expected.to have_attached_file(:thumbnail) }
it { is_expected.to validate_attachment_content_type(:thumbnail).
allowing('image/png', 'image/gif', 'image/jpg').
rejecting('text/plain', 'text/xml', 'video/mp4', 'video/x-flv') }
it {
is_expected.to validate_attachment_content_type(:thumbnail)
.allowing('image/png', 'image/gif', 'image/jpg')
.rejecting('text/plain', 'text/xml', 'video/mp4', 'video/x-flv')
}
end
describe 'relations' do
......
require 'simplecov'
SimpleCov.coverage_dir("coverage/rspec")
SimpleCov.coverage_dir('coverage/rspec')
# Minimum coverage is only desired on CI tools when building the environment. CI is a
# default environment variable used by GitlabCI (and Travis). For reference, see here:
# http://docs.gitlab.com/ce/ci/variables/README.html
SimpleCov.minimum_coverage(100) if ENV["CI"] == 'true'
SimpleCov.minimum_coverage(100) if ENV['CI'] == 'true'
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
abort('The Rails environment is running in production mode!') if Rails.env.production?
require 'spec_helper'
require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point!
......
require "rails_helper"
require 'rails_helper'
RSpec.describe ContentsController, type: :routing do
describe "routing" do
it "routes to #index" do
expect(:get => "/contents").to_not route_to("contents#index")
describe 'routing' do
it 'routes to #index' do
expect(get: '/contents').to_not route_to('contents#index')
end
it "routes to #new" do
expect(:get => "/contents/new").to route_to("contents#new")
it 'routes to #new' do
expect(get: '/contents/new').to route_to('contents#new')
end
it "routes to #show" do
expect(:get => "/contents/1").to route_to("contents#show", :id => "1")
it 'routes to #show' do
expect(get: '/contents/1').to route_to('contents#show', id: '1')
end
it "routes to #edit" do
expect(:get => "/contents/1/edit").to_not route_to("contents#edit", :id => "1")
it 'routes to #edit' do
expect(get: '/contents/1/edit').to_not route_to('contents#edit', id: '1')
end
it "routes to #create" do
expect(:post => "/contents").to route_to("contents#create")
it 'routes to #create' do
expect(post: '/contents').to route_to('contents#create')
end
it "routes to #update via PUT" do
expect(:put => "/contents/1").to_not route_to("contents#update", :id => "1")
it 'routes to #update via PUT' do
expect(put: '/contents/1').to_not route_to('contents#update', id: '1')
end
it "routes to #update via PATCH" do
expect(:patch => "/contents/1").to_not route_to("contents#update", :id => "1")
it 'routes to #update via PATCH' do
expect(patch: '/contents/1').to_not route_to('contents#update', id: '1')
end
it "routes to #destroy" do
expect(:delete => "/contents/1").to_not route_to("contents#destroy", :id => "1")
it 'routes to #destroy' do
expect(delete: '/contents/1').to_not route_to('contents#destroy', id: '1')
end
it 'routes to #callback' do
expect(:post => '/contents/zencoder_callback').to route_to('contents#zencoder_callback')
expect(post: '/contents/zencoder_callback').to route_to('contents#zencoder_callback')
end
end
end
require 'rails_helper'
describe HomeController, :type => :routing do
describe HomeController, type: :routing do
describe 'routing' do
it 'routes root to index' do
expect(get: '/').to route_to(controller: 'home', action: 'index')
......
require "rails_helper"
require 'rails_helper'
RSpec.describe ProfilesController, type: :routing do
describe "routing" do
it "routes to #index" do
expect(:get => "/profiles").to_not route_to("profiles#index")
describe 'routing' do
it 'routes to #index' do
expect(get: '/profiles').to_not route_to('profiles#index')
end
it "routes to #new" do
expect(:get => "/profiles/new").to route_to("profiles#new")
it 'routes to #new' do
expect(get: '/profiles/new').to route_to('profiles#new')
end
it "routes to #show" do
expect(:get => "/profiles/1").to route_to("profiles#show", :id => "1")
it 'routes to #show' do
expect(get: '/profiles/1').to route_to('profiles#show', id: '1')
end
it "routes to #edit" do
expect(:get => "/profiles/1/edit").to route_to("profiles#edit", :id => "1")
it 'routes to #edit' do
expect(get: '/profiles/1/edit').to route_to('profiles#edit', id: '1')
end
it "routes to #create" do
expect(:post => "/profiles").to route_to("profiles#create")
it 'routes to #create' do
expect(post: '/profiles').to route_to('profiles#create')
end
it "routes to #update via PUT" do
expect(:put => "/profiles/1").to route_to("profiles#update", :id => "1")
it 'routes to #update via PUT' do
expect(put: '/profiles/1').to route_to('profiles#update', id: '1')
end
it "routes to #update via PATCH" do
expect(:patch => "/profiles/1").to route_to("profiles#update", :id => "1")
it 'routes to #update via PATCH' do
expect(patch: '/profiles/1').to route_to('profiles#update', id: '1')
end
it "routes to #destroy" do
expect(:delete => "/profiles/1").to route_to("profiles#destroy", :id => "1")
it 'routes to #destroy' do
expect(delete: '/profiles/1').to route_to('profiles#destroy', id: '1')
end
it "routes to #states" do
expect(:get => '/states').to route_to("profiles#states")
it 'routes to #states' do
expect(get: '/states').to route_to('profiles#states')
end
end
end
require 'rails_helper'
describe StaticViewsController, :type => :routing do
describe StaticViewsController, type: :routing do
describe 'routing' do
it 'routes root to terms_of_use' do
expect(get: '/terms_of_use').to route_to(controller: 'static_views', action: 'terms_of_use')
......
......@@ -49,55 +49,53 @@ RSpec.configure do |config|