diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5462b4a..3c51c1e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -23,64 +23,67 @@ require 'yaml' require 'authentication.rb' class ApplicationController < ActionController::Base - helper :all - protect_from_forgery + helper :all + protect_from_forgery - include AuthenticationSystem + include AuthenticationSystem - before_filter :startup - #before_filter :set_timezone - before_filter :require_login, :only => [ :edit, :new, :create, :update, :delete, :destroy ] + before_filter :startup + # before_filter :set_timezone + before_filter :require_login, only: [:edit, :new, :create, :update, :delete, + :destroy] - protected - def rescue_action(exception) - # Acesso negado - if exception.is_a?(AccessDenied) - respond_to do |format| - format.html { - if logged_in? - render :file => "#{Rails.root}/public/401.html", :status => 401 - else - login_by_html - end - } - format.xml { head 401 } - end + rescue_from AccessDenied, with: :deny_access + rescue_from ActiveRecord::RecordInvalid, with: :reshow_form + rescue_from ActiveRecord::RecordNotFound, with: :show_not_found - # Erro de validacao - elsif exception.is_a?(ActiveRecord::RecordInvalid) - respond_to do |format| - format.html { render :action => (params[:from].nil? ? (exception.record.new_record? ? 'new' : 'edit') : params[:from]) } - format.xml { render :xml => exception.record.errors, :status => :unprocessable_entity } - end + protected - # Registro nao encontrado - elsif (RAILS_ENV == 'production') and exception.is_a?(ActiveRecord::RecordNotFound) - respond_to do |format| - format.html { render :file => "#{Rails.root}/public/404.html", :status => 404 } - format.xml { head 404 } - end + def deny_access + respond_to do |format| + format.html do + if logged_in? + render file: "#{Rails.root}/public/401.html", status: 401 + else + login_by_html + end + end + format.xml { head 401 } + end + end - # Outras excecoes - else - super - end - end + def reshow_form(exception) + respond_to do |format| + format.html { render action: (params[:from].nil? ? (exception.record.new_record? ? 'new' : 'edit') : params[:from]) } + format.xml { render xml: exception.record.errors, status: :unprocessable_entity } + end + end - #def set_timezone - # #Time.zone = session[:user].tz - # Time.zone = "America/Fortaleza" - #end + def show_not_found + if (RAILS_ENV == 'production') + respond_to do |format| + format.html { render file: "#{Rails.root}/public/404.html", status: 404 } + format.xml { head 404 } + end + else + fail ActiveRecord::RecordNotFound + end + end - def startup - if session[:user_id] - @current_user = User.find(session[:user_id]) - else - login_by_token - end + # def set_timezone + # #Time.zone = session[:user].tz + # Time.zone = "America/Fortaleza" + # end - @color = App.default_color - @color = @current_user.pref_color if @current_user - @color = params[:color].to_i if params[:color] - end + def startup + if session[:user_id] + @current_user = User.find(session[:user_id]) + else + login_by_token + end + + @color = App.default_color + @color = @current_user.pref_color if @current_user + @color = params[:color].to_i if params[:color] + end end diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 9206668..50a4605 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -20,35 +20,26 @@ # along with this program. If not, see . class CoursesController < ApplicationController - - before_filter :require_admin, :only => [:new, :create, :edit, :update, :destroy] - before_filter :require_login, :only => [:enroll, :unenroll] - before_filter :find_course, :except => [:index] - #after_filter :cache_sweep, :only => [ :create, :update, :destroy ] + before_filter :require_admin, only: [:new, :create, :edit, :update, + :destroy] + before_filter :require_login, only: [:enroll, :unenroll] + before_filter :find_course, except: [:index] + # after_filter :cache_sweep, only: [ :create, :update, :destroy ] def index - params[:period] = nil if params[:period] == App.current_period @period = params[:period] || App.current_period - - if logged_in? and !@current_user.courses.empty? - @courses = Course.all(:order => 'grade asc, full_name asc', - :conditions => ['period = ? and hidden = ? and id not in (?)', - @period, false, @current_user.courses]) - else - @courses = Course.all(:order => 'grade asc, full_name asc', - :conditions => ['period = ? and hidden = ?', @period, false]) - end + @courses = Course.visible.where(period: @period) respond_to do |format| format.html - format.xml { render :xml => @courses } + format.xml { render xml: @courses } end end def show respond_to do |format| format.html - format.xml { render :xml => @course } + format.xml { render xml: @course } end end @@ -61,8 +52,9 @@ class CoursesController < ApplicationController respond_to do |format| format.html { redirect_to course_path(@course) } - format.xml { head :created, :location => course_url(@course, - :format => :xml) } + format.xml do + head :created, location: course_url(@course, format: :xml) + end end end @@ -111,19 +103,21 @@ class CoursesController < ApplicationController end protected + def find_course if params[:id] - params[:id] = Course.first(:conditions => ['short_name = ?', params[:id]], :order => 'period desc').id if !params[:id].is_numeric? and !Course.find_by_short_name(params[:id]).nil? + @course = Course.from_param(params[:id]) + else + @course = Course.new(params[:course]) end - @course = params[:id] ? Course.find(params[:id]) : Course.new(params[:course]) end def require_admin - raise AccessDenied.new unless admin? + fail AccessDenied, 'only admins can modify courses' unless admin? end def cache_sweep - expire_fragment(course_path(@course.id, :part => 'right')) + expire_fragment(course_path(@course.id, part: 'right')) expire_fragment(course_path(@course.id)) expire_fragment(courses_path) end diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb index 5c8624f..37f8573 100644 --- a/app/helpers/attachments_helper.rb +++ b/app/helpers/attachments_helper.rb @@ -27,7 +27,7 @@ module AttachmentsHelper end def nest_path(items, paths, from, to, level) - result = {} + result = { } base = from - 1 base = base + 1 while base+1 <= to and paths[base+1][level].nil? diff --git a/app/models/course.rb b/app/models/course.rb index c34bc0a..8e75533 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -20,64 +20,70 @@ # along with this program. If not, see . class Course < ActiveRecord::Base - acts_as_paranoid + default_scope order('grade asc, full_name asc, period desc') + + scope :visible, where(hidden: false) + has_many :attachments, - :order => 'path is not null, path, file_name', - :dependent => :destroy + order: 'path is not null, path, file_name', + dependent: :destroy has_many :events, - :order => 'time asc', - :dependent => :destroy + order: 'time asc', + dependent: :destroy has_many :news, - :foreign_key => 'receiver_id', - :order => 'id desc', - :class_name => 'News', - :dependent => :destroy + foreign_key: 'receiver_id', + order: 'id desc', + class_name: 'News', + dependent: :destroy has_many :log_entries, - :order => 'created_at desc', - :dependent => :destroy + order: 'created_at desc', + dependent: :destroy has_many :wiki_pages, - :order => 'position', - :dependent => :destroy + order: 'position', + dependent: :destroy has_and_belongs_to_many :users, - :order => 'last_seen desc' + order: 'last_seen desc' validates_presence_of :short_name validates_presence_of :full_name validates_presence_of :code - validates_numericality_of :grade, :only_integer => true - validates_inclusion_of :hidden, :in => [true, false], :allow_nil => false - validates_format_of :short_name, :with => /^[^0-9]/ + validates_numericality_of :grade, only_integer: true + validates_inclusion_of :hidden, in: [true, false], allow_nil: false + validates_format_of :short_name, with: /^[^0-9]/ after_create :add_initial_wiki_pages def related_courses - Course.all(:conditions => ['short_name = ?', self.short_name], :limit => 4, - :order => 'period desc') + Course.all(conditions: ['short_name = ?', short_name], limit: 4, + order: 'period desc') end def recent_news - self.news.all(:conditions => ['timestamp > ?', 7.days.ago]) + news.all(conditions: ['timestamp > ?', 7.days.ago]) end def add_initial_wiki_pages App.initial_wiki_pages.each do |page_title| - wiki_page = WikiPage.new(:title => page_title, :description => 'New course', - :content => App.initial_wiki_page_content) + wiki_page = WikiPage.new(title: page_title, description: 'New course', + content: App.initial_wiki_page_content) wiki_page.user = User.first - self.wiki_pages << wiki_page + wiki_pages << wiki_page wiki_page.save! end end def to_param - return self.short_name if self.period == App.current_period - return self.id.to_s + period == App.current_period ? short_name : id.to_s + end + + def self.from_param(param) + param.is_numeric? ? Course.find(param) : Course.find_by_short_name(param) end end diff --git a/app/models/coverage/.last_run.json b/app/models/coverage/.last_run.json new file mode 100644 index 0000000..2cc330d --- /dev/null +++ b/app/models/coverage/.last_run.json @@ -0,0 +1,5 @@ +{ + "result": { + "covered_percent": 3.57 + } +} diff --git a/app/models/coverage/.resultset.json.lock b/app/models/coverage/.resultset.json.lock new file mode 100644 index 0000000..e69de29 diff --git a/app/models/log_entry/attachment_log_entry.rb b/app/models/log_entry/attachment_log_entry.rb index dadd8b7..1d89331 100644 --- a/app/models/log_entry/attachment_log_entry.rb +++ b/app/models/log_entry/attachment_log_entry.rb @@ -20,21 +20,28 @@ # along with this program. If not, see . class AttachmentLogEntry < LogEntry - belongs_to :attachment, - :foreign_key => "target_id", - :with_deleted => true + belongs_to :attachment, + :foreign_key => "target_id", + :with_deleted => true end class AttachmentDeleteLogEntry < AttachmentLogEntry - def reversible?() - attachment.deleted? - end - def undo!(current_user) - attachment.update_attribute(:deleted_at, nil) - AttachmentRestoreLogEntry.create!(:target_id => attachment.id, :user_id => current_user.id, :course => attachment.course) - end + def reversible?() + attachment.deleted? + end + + def undo!(current_user) + attachment.update_attribute(:deleted_at, nil) + AttachmentRestoreLogEntry.create!(:target_id => attachment.id, + :user_id => current_user.id, :course => attachment.course) + end +end + +class AttachmentEditLogEntry < AttachmentLogEntry end -class AttachmentEditLogEntry < AttachmentLogEntry; end -class AttachmentCreateLogEntry < AttachmentLogEntry; end -class AttachmentRestoreLogEntry < AttachmentLogEntry; end +class AttachmentCreateLogEntry < AttachmentLogEntry +end + +class AttachmentRestoreLogEntry < AttachmentLogEntry +end diff --git a/app/models/log_entry/event_log_entry.rb b/app/models/log_entry/event_log_entry.rb index 7dd2926..2723333 100644 --- a/app/models/log_entry/event_log_entry.rb +++ b/app/models/log_entry/event_log_entry.rb @@ -20,21 +20,27 @@ # along with this program. If not, see . class EventLogEntry < LogEntry - belongs_to :event, - :foreign_key => "target_id", - :with_deleted => true + belongs_to :event, + :foreign_key => "target_id", + :with_deleted => true end class EventDeleteLogEntry < EventLogEntry - def reversible?() - event.deleted? - end - def undo!(current_user) - event.recover! - EventRestoreLogEntry.create!(:target_id => event.id, :user_id => current_user.id, :course => event.course, :version => event.version) - end + def reversible?() + event.deleted? + end + + def undo!(current_user) + event.recover! + EventRestoreLogEntry.create!(:target_id => event.id, :user_id => current_user.id, :course => event.course, :version => event.version) + end +end + +class EventEditLogEntry < EventLogEntry end -class EventEditLogEntry < EventLogEntry; end -class EventCreateLogEntry < EventLogEntry; end -class EventRestoreLogEntry < EventLogEntry; end +class EventCreateLogEntry < EventLogEntry +end + +class EventRestoreLogEntry < EventLogEntry +end diff --git a/app/models/user.rb b/app/models/user.rb index 00d1a24..799a0db 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -22,100 +22,102 @@ require 'digest/sha1' class User < ActiveRecord::Base - - # Plugins - acts_as_paranoid - - # Associacoes - has_and_belongs_to_many :courses, :order => 'full_name', :conditions => "period = #{App.current_period}" - - # Validacao - validates_length_of :login, :within => 3..40 - validates_length_of :name, :within => 3..40 - validates_length_of :display_name, :within => 3..40 - - validates_presence_of :login, :email, :display_name - validates_uniqueness_of :login, :email, :display_name - - validates_format_of :login, :with => /^[^0-9]/ - validates_format_of :display_name, :with => /^[^0-9]/ - - validates_format_of :email, - :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i - - # Seguranca - attr_protected :id, :salt - attr_accessor :password, :password_confirmation - - def User.find_by_login_and_pass(login, pass) - user = find(:first, :conditions => [ "login = ?", login ]) - return (!user.nil? and User.encrypt(pass, user.salt) == user.hashed_password) ? user : nil - end - - def to_xml(options = {}) - options[:indent] ||= 2 - xml = options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent]) - xml.instruct! unless options[:skip_instruct] - xml.user do - xml.id self.id - xml.name self.name - xml.display_name self.display_name - xml.login self.login - xml.created_at self.created_at - xml.last_seen self.last_seen - xml.description self.description - end - end - - # Gera uma nova senha, e a envia por email. - def generate_password_reset_key! - update_attribute(:password_reset_key, User.random_string(30)) - save! - Notifications.deliver_forgot_password(self.email, self.password_reset_key) - end - - def reset_login_key - self.login_key = Digest::SHA1.hexdigest(Time.now.to_s + password.to_s + rand(123456789).to_s).to_s - end - - def reset_login_key! - reset_login_key - save! - self.login_key - end - - def to_param - self.login.match(/^[-_a-z0-9]*$/i).nil? ? self.id.to_s : self.login - end - - protected - def validate - if new_record? - errors.add_on_blank :password - errors.add_on_blank :password_confirmation - end - - if !@password.blank? - errors.add(:password_confirmation) if @password_confirmation.blank? or @password != @password_confirmation - errors.add(:password, 'é muito curta') if !(5..40).include?(@password.length) - end - end - - def before_save - self.salt = User.random_string(10) if !self.salt? - self.secret = User.random_string(32) if !self.secret? - self.hashed_password = User.encrypt(@password, self.salt) if !@password.blank? - end - - def self.encrypt(pass, salt) - Digest::SHA1.hexdigest(pass + salt) - end - - def self.random_string(len) - chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a - newpass = "" - 1.upto(len) { |i| newpass << chars[rand(chars.size-1)] } - return newpass - end - + acts_as_paranoid + + has_and_belongs_to_many :courses, order: 'full_name', + conditions: "period = #{App.current_period}" + + validates_length_of :login, within: 3..40 + validates_length_of :name, within: 3..40 + validates_length_of :display_name, within: 3..40 + + validates_presence_of :login, :email, :display_name + validates_uniqueness_of :login, :email, :display_name + + validates_format_of :login, with: /^[^0-9]/ + validates_format_of :display_name, with: /^[^0-9]/ + + validates_format_of :email, + with: /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i + + attr_protected :id, :salt + attr_accessor :password, :password_confirmation + + def self.find_by_login_and_pass(login, pass) + user = find(:first, conditions: ['login = ?', login]) + (!user.nil? && User.encrypt(pass, user.salt) == user.hashed_password) ? user : nil + end + + def to_xml(options = {}) + options[:indent] ||= 2 + xml = options[:builder] ||= Builder::XmlMarkup.new(indent: options[:indent]) + xml.instruct! unless options[:skip_instruct] + xml.user do + xml.id id + xml.name name + xml.display_name display_name + xml.login login + xml.created_at created_at + xml.last_seen last_seen + xml.description description + end + end + + # Gera uma nova senha, e a envia por email. + def generate_password_reset_key! + update_attribute(:password_reset_key, User.random_string(30)) + save! + Notifications.deliver_forgot_password(email, password_reset_key) + end + + def reset_login_key + self.login_key = Digest::SHA1.hexdigest(Time.now.to_s + password.to_s + + rand(123_456_789).to_s).to_s + end + + def reset_login_key! + reset_login_key + save! + login_key + end + + def to_param + login.match(/^[-_a-z0-9]*$/i).nil? ? id.to_s : login + end + + def courses_not_enrolled(period) + Course.all(conditions: ['period = ? and hidden = ? and id not in (?)', + period, false, courses]) + end + + protected + + def validate + if new_record? + errors.add_on_blank :password + errors.add_on_blank :password_confirmation + end + + return unless @password.blank? + errors.add(:password_confirmation) if @password_confirmation.blank? || + @password != @password_confirmation + errors.add(:password, 'é muito curta') unless @password.length >= 5 + end + + def before_save + self.salt = User.random_string(10) unless self.salt? + self.secret = User.random_string(32) unless self.secret? + self.hashed_password = User.encrypt(@password, salt) unless @password.blank? + end + + def self.encrypt(pass, salt) + Digest::SHA1.hexdigest(pass + salt) + end + + def self.random_string(len) + chars = ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a + newpass = '' + 1.upto(len) { |_i| newpass << chars[rand(chars.size - 1)] } + newpass + end end diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index 8ecc6c7..29e4ea5 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -22,73 +22,68 @@ require 'acts_as_versioned' require 'tempfile' - class WikiPage < ActiveRecord::Base - attr_accessible :title, :front_page, :content, :description - attr_writer :type # Plugins acts_as_paranoid - acts_as_list :scope => 'course_id = #{course_id}' - acts_as_versioned :if_changed => [:content, :description, :title] - self.non_versioned_columns << 'front_page' - self.non_versioned_columns << 'position' - self.non_versioned_columns << 'deleted_at' - self.non_versioned_columns << 'canonical_title' + acts_as_list scope: 'course_id = #{course_id}' + acts_as_versioned if_changed: [:content, :description, :title] + non_versioned_columns << 'front_page' + non_versioned_columns << 'position' + non_versioned_columns << 'deleted_at' + non_versioned_columns << 'canonical_title' # Associacoes belongs_to :course - belongs_to :user, :with_deleted => true + belongs_to :user, with_deleted: true # Valicacao validates_presence_of :front_page validates_presence_of :description validates_presence_of :title validates_presence_of :content - validates_uniqueness_of :title, :scope => :course_id - validates_uniqueness_of :canonical_title, :scope => :course_id - validates_format_of :title, :with => /^[^0-9]/ + validates_uniqueness_of :title, scope: :course_id + validates_uniqueness_of :canonical_title, scope: :course_id + validates_format_of :title, with: /^[^0-9]/ before_validation :set_canonical_title before_save :set_position # acts_as_paranoid_versioned - self.versioned_class.class_eval do - def self.delete_all(conditions = nil) - return + versioned_class.class_eval do + def self.delete_all(_conditions = nil) + nil end end def set_canonical_title - self.canonical_title = self.title.pretty_url + canonical_title = title.pretty_url end def set_position - if !self.front_page - self.remove_from_list - elsif self.position.nil? - self.update_attribute(:position, (self.course.wiki_pages.maximum(:position)||0) + 1) + if !front_page + remove_from_list + elsif position.nil? + update_attribute(:position, (course.wiki_pages.maximum(:position) || 0) + 1) end end def validate - begin - self.content.format_wiki - rescue - errors.add("content", "possui erro de sintaxe: " + $!.to_s.html_escape) - end + content.format_wiki + rescue + errors.add("content", "possui erro de sintaxe: " + $ERROR_INFO.to_s.html_escape) end def to_param - self.canonical_title + canonical_title end def self.find_front_page - WikiPage.all(:conditions => ["front_page = ?", true]) + WikiPage.all(conditions: ["front_page = ?", true]) end - def WikiPage.diff(from, to) + def self.diff(from, to) # Cria um arquivo com o conteudo da versao antiga original_content_file = Tempfile.new("old") original_content_file << from.content << "\n" @@ -100,12 +95,12 @@ class WikiPage < ActiveRecord::Base new_content_file.flush # Calcula as diferencas - diff = `diff -u #{original_content_file.path()} #{new_content_file.path()}` + diff = `diff -u #{original_content_file.path} #{new_content_file.path}` # Fecha os arquivos temporarios new_content_file.close! original_content_file.close! - return diff + diff end end diff --git a/app/views/courses/_form.html.haml b/app/views/courses/_form.html.haml index 9e5ab98..cecc718 100644 --- a/app/views/courses/_form.html.haml +++ b/app/views/courses/_form.html.haml @@ -2,29 +2,29 @@ %dl %dt - %label{:for => "course_full_name"} Nome completo - %dd= text_field 'course', 'full_name' + %label{:for => "course_full_name"}= Course.human_attribute_name(:full_name) + %dd= text_field 'course', 'full_name' %dt - %label{:for => "course_short_name"} Nome abreviado + %label{:for => "course_short_name"}= Course.human_attribute_name(:short_name) %dd= text_field 'course', 'short_name' %dt - %label{:for => "course_code"} Código + %label{:for => "course_code"}= Course.human_attribute_name(:code) %dd= text_field 'course', 'code' %dt - %label{:for => "course_grade"} Semestre + %label{:for => "course_grade"}= Course.human_attribute_name(:grade) %dd= text_field 'course', 'grade' %dt - %label{:for => "course_period"} Data + %label{:for => "course_period"}= Course.human_attribute_name(:period) %dd= text_field 'course', 'period' %dt - %label{:for => "course_hidden"} Ocultar + %label{:for => "course_hidden"}= Course.human_attribute_name(:hidden) %dd= check_box 'course', 'hidden' %dt - %label{:for => "course_description"} Descrição + %label{:for => "course_description"}= Course.human_attribute_name(:description) %dd= preserve(text_area('course', 'description', :cols => 60, :rows => 10)) diff --git a/app/views/courses/edit.html.haml b/app/views/courses/edit.html.haml index b1a8b8e..83962a1 100644 --- a/app/views/courses/edit.html.haml +++ b/app/views/courses/edit.html.haml @@ -1,7 +1,7 @@ %h4.title= App.title -%h1.title Editar disciplina +%h1.title= t(:edit_course) %p = form_tag course_path(@course.id), :method => :put do = render :partial => 'form' - = submit_tag 'Editar', :accesskey => 'e' + = submit_tag t(:edit), :accesskey => 'e' diff --git a/app/views/courses/index.html.haml b/app/views/courses/index.html.haml index 9b383df..0d73c66 100644 --- a/app/views/courses/index.html.haml +++ b/app/views/courses/index.html.haml @@ -1,5 +1,5 @@ .cmd - = action_icon('add', 'Cadastrar nova disciplina', new_course_url, :accesskey => '+') if admin? + = action_icon('add', 'Cadastrar nova disciplina', new_course_url, accesskey: '+') if admin? %h4.title= App.title %h1.title= "Disciplinas #{@period}" @@ -8,6 +8,7 @@ %ul - if logged_in? - if params[:period].nil? + - @courses = @current_user.courses_not_enrolled(@period) %h3 Disciplinas Matriculadas - if @current_user.courses.empty? %li.no_itens Nenhuma disciplina matriculada @@ -17,7 +18,7 @@ = action_icon('subtract', 'Desmatricular-se', unenroll_course_url(course)) = link_to h(course.full_name), course_url(course) - -# cache(courses_path) do + -# cache(courses_path) do - old_grade = 0 - for course in @courses - if course.grade != old_grade @@ -32,5 +33,5 @@ %h3 Outros Semestres - %li= link_to "2008.2", :period => '2008.2' - %li= link_to "2008.1", :period => '2008.1' + %li= link_to "2008.2", period: '2008.2' + %li= link_to "2008.1", period: '2008.1' diff --git a/app/views/courses/new.html.haml b/app/views/courses/new.html.haml index d762f91..a7dc9d9 100644 --- a/app/views/courses/new.html.haml +++ b/app/views/courses/new.html.haml @@ -1,6 +1,6 @@ %h4.title= App.title -%h1.title Adicionar disciplina +%h1.title= t(:new_course) = form_tag courses_url, :method => :post do = render :partial => 'form' - = submit_tag "Cadastrar", :accesskey => 'e' + = submit_tag t(:create), :accesskey => 'e' diff --git a/app/views/courses/show.html.haml b/app/views/courses/show.html.haml index 4f6cfa5..d5c8e6e 100644 --- a/app/views/courses/show.html.haml +++ b/app/views/courses/show.html.haml @@ -1,11 +1,9 @@ .cmd - if admin? - = action_icon 'edit', 'Editar disciplina', edit_course_url, :accesskey => 'e' + = action_icon 'edit', t(:edit_course), edit_course_url, :accesskey => 'e' =# action_icon 'trash', 'Excluir disciplina', course_url, :confirm => 'Tem certeza que deseja excluir?', :method => :delete --# cache(course_path(@course.id)) do - -%h4.title Disciplina +%h4.title= t(:course).capitalize %h1.title= h(@course.full_name) %p= @course.description.format_wiki @@ -31,32 +29,31 @@ .box .cmd - = action_icon 'add', 'Adicionar página wiki', new_course_wiki_instance_url(@course) + = action_icon 'add', t(:create_wiki_page), new_course_wiki_instance_url(@course) - %h3 Páginas Wiki + %h3= t(:wiki_pages) %ul.wiki - @course.wiki_pages.find_front_page.each do |wiki| %li{highlight(wiki.id)} .cmd{:style => 'margin-bottom: -27px; margin-top: -9px;'} - =action_icon 'arrow2_n', 'Mover para cima', move_up_course_wiki_instance_url(@course.to_param, wiki.id) unless wiki.first? - =action_icon 'arrow2_s', 'Mover para baixo', move_down_course_wiki_instance_url(@course.to_param, wiki.id) unless wiki.last? + =action_icon 'arrow2_n', t(:move_up), move_up_course_wiki_instance_url(@course.to_param, wiki.id) unless wiki.first? + =action_icon 'arrow2_s', t(:move_down), move_down_course_wiki_instance_url(@course.to_param, wiki.id) unless wiki.last? - if wiki.last? %span{:style => 'margin-right: 14px'}   =link_to h(wiki.title), course_wiki_instance_url(@course.to_param, wiki.id) - if @course.wiki_pages.empty? - %li.no_itens Nenhuma página wiki + %li.no_itens= t(:no_wiki_pages) - else - %li.show_all= link_to "Ver todas as páginas wiki", course_wiki_url(@course) + %li.show_all= link_to t(:see_all_wiki_pages), course_wiki_url(@course) .box - .cmd= action_icon 'add', 'Adicionar anexo', new_course_attachment_url(@course) + .cmd= action_icon 'add', t(:create_attachment), new_course_attachment_url(@course) - %h3 Repositório de Arquivos + %h3= t(:repository) .repositorio = nested_attachments_to_html(attachments_to_nested_hash(@course.attachments.find_front_page)) - if @course.attachments.empty? %ul.wiki - %li.no_itens Nenhum arquivo + %li.no_itens= t(:no_attachments) - else - %li.show_all= link_to "Ver todos os arquivos", course_attachments_url(@course) - + %li.show_all= link_to t(:see_all_attachments), course_attachments_url(@course) diff --git a/config/application.rb b/config/application.rb index 260602f..c80e030 100644 --- a/config/application.rb +++ b/config/application.rb @@ -51,7 +51,7 @@ module WikiUFC ["#900", "#c00", "#444", "#888"], - # Aqua + # Aqua ["#7b7", "#455", "#899", "#abb"], ["#005B9A", "#455", "#899", "#abb"], ["#8D009A", "#455", "#899", "#abb"], @@ -76,6 +76,8 @@ module WikiUFC # Templates config.initial_wiki_pages = ['Ementa', 'Notas de Aula'] config.initial_wiki_page_content = 'Página em branco.' + + config.i18n.default_locale = 'pt-BR' end end @@ -85,4 +87,3 @@ require "haml" require "haml/template" Haml::Template.options[:escape_attrs] = false Haml::Template.options[:escape_html] = false - diff --git a/config/database.yml b/config/database.yml new file mode 100644 index 0000000..0c0164e --- /dev/null +++ b/config/database.yml @@ -0,0 +1,11 @@ +development: + adapter: sqlite3 + database: db/wiki.sqlite3 + +test: + adapter: sqlite3 + database: db/test.sqlite3 + +production: + adapter: sqlite3 + database: db/wiki.sqlite3 diff --git a/config/environments/development.rb b/config/environments/development.rb index 164c15d..5fd276c 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,5 +1,3 @@ -#require 'brI18n' - WikiUFC::Application.configure do # Settings specified here will take precedence over those in config/application.rb diff --git a/config/environments/production.rb b/config/environments/production.rb index 52d655b..7eaaeb0 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,5 +1,3 @@ -#require 'brI18n' - WikiUFC::Application.configure do # Settings specified here will take precedence over those in config/application.rb @@ -67,4 +65,3 @@ WikiUFC::Application.configure do # with SQLite, MySQL, and PostgreSQL) # config.active_record.auto_explain_threshold_in_seconds = 0.5 end - diff --git a/config/environments/test.rb b/config/environments/test.rb index c17dcf4..9a89af6 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -34,4 +34,6 @@ WikiUFC::Application.configure do # Print deprecation notices to the stderr config.active_support.deprecation = :stderr + + config.i18n.default_locale = 'en' end diff --git a/config/initializers/load_app_config.rb.rails2 b/config/initializers/load_app_config.rb.rails2 deleted file mode 100644 index ea22d0b..0000000 --- a/config/initializers/load_app_config.rb.rails2 +++ /dev/null @@ -1,21 +0,0 @@ -require 'ostruct' -::App = OpenStruct.new - -# Define os campos essenciais -required_fields = %w( - title - language - max_upload_file_size - default_color -) - -# Carrega as configuracoes personalizadas -require "#{RAILS_ROOT}/config/application.rb" - -# Verifica se todas os campos essenciais foram instanciados -required_fields.each do |field| - raise "Required configuration not found: App.#{field}" unless App.respond_to?(field) -end - -# Internacionalizacao -#Gibberish.current_language = App.language if RAILS_ENV != 'test' diff --git a/config/initializers/localization.rb.rails2 b/config/initializers/localization.rb.rails2 deleted file mode 100644 index ce91dc0..0000000 --- a/config/initializers/localization.rb.rails2 +++ /dev/null @@ -1,21 +0,0 @@ -#TzTime.zone = TZInfo::Timezone.new("America/Fortaleza") - -class Time - alias :strftime_nolocale :strftime - - def strftime(format) - format = format.dup - format.gsub!(/%a/, Date::ABBR_DAYNAMES[self.wday]) - format.gsub!(/%A/, Date::DAYNAMES[self.wday]) - format.gsub!(/%b/, Date::ABBR_MONTHNAMES[self.mon]) - format.gsub!(/%B/, Date::MONTHNAMES[self.mon]) - self.strftime_nolocale(format) - end -end - - -ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!( - :default => '%d/%m/%Y %H:%M', - :date_time12 => "%d/%m/%Y %I:%M%p", - :date_time24 => "%d/%m/%Y %H:%M" -) diff --git a/config/initializers/new_rails_defaults.rb.rails2 b/config/initializers/new_rails_defaults.rb.rails2 deleted file mode 100644 index 8ec3186..0000000 --- a/config/initializers/new_rails_defaults.rb.rails2 +++ /dev/null @@ -1,19 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# These settings change the behavior of Rails 2 apps and will be defaults -# for Rails 3. You can remove this initializer when Rails 3 is released. - -if defined?(ActiveRecord) - # Include Active Record class name as root for JSON serialized output. - ActiveRecord::Base.include_root_in_json = true - - # Store the full class name (including module namespace) in STI type column. - ActiveRecord::Base.store_full_sti_class = true -end - -# Use ISO 8601 format for JSON serialized times and dates. -ActiveSupport.use_standard_json_time_format = true - -# Don't escape HTML entities in JSON, leave that for the #json_escape helper. -# if you're including raw json in an HTML page. -ActiveSupport.escape_html_entities_in_json = false \ No newline at end of file diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index aae2016..98adada 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -4,6 +4,8 @@ pt-BR: course_created: Disciplina cadastrada course_updated: Disciplina editada course_removed: Disciplina excluída + edit_course: Editar disciplina + new_course: Cadastrar disciplina event: evento events: eventos @@ -29,22 +31,32 @@ pt-BR: attachment_updated: Arquivo editado attachment_removed: Arquivo excluído attachment_restored: Arquivo restaurado + create_attachment: Adicionar arquivo + see_all_attachments: Ver todos os arquivos + no_attachments: Nenhum arquivo + repository: Repositório de Arquivos wiki_page: Página wiki + wiki_pages: Páginas wiki wiki_page_created: Página wiki criada wiki_page_removed: Página wiki removida wiki_page_updated: Página wiki atualizada wiki_page_restored: Página wiki restaurada + create_wiki_page: Adicionar página wiki + see_all_wiki_pages: Ver todas as páginas wiki + no_wiki_pages: Nenhuma página wiki recent_changes: Mudanças recentes log_about: Mudanças recentes em {disciplina} - undo: Desfazer login_failed: Não foi possível fazer login login_required: É necessário fazer login para acessar esta área do site login_success: Olá, {u}! logout_success: Você fez logout + move_up: Mover para cima + move_down: Mover para baixo + navigation: navegação forums: fórums @@ -55,6 +67,9 @@ pt-BR: is_too_large: é grande demais is_needed: é requerido + undo: Desfazer + create: Cadastrar + body: conteúdo code: código content: conteúdo @@ -70,22 +85,21 @@ pt-BR: short_name: nome abreviado time: horário title: título + edit: Editar - logged_in_as: Identificado como %{u} + logged_in_as: Bem vindo %{u} member_since: Membro desde %{c} last_seen: Última visita há %{c} welcome_back: Bem vindo %{u} dashboard: Dashboard - number: - human: - storage_units: - format: "%n %u" - units: - byte: - one: "Byte" - other: "Bytes" - kb: "KB" - mb: "MB" - gb: "GB" - tb: "TB" + activerecord: + attributes: + course: + short_name: Nome abreviado + full_name: Nome completo + description: Descrição + code: Código + grade: Semestre + period: Data + hidden: Oculto diff --git a/test/functional/courses_controller_test.rb b/test/functional/courses_controller_test.rb index fe448e8..b54a785 100644 --- a/test/functional/courses_controller_test.rb +++ b/test/functional/courses_controller_test.rb @@ -22,7 +22,7 @@ require File.dirname(__FILE__) + '/../test_helper.rb' require 'courses_controller' # Re-raise errors caught by the controller. -#class CoursesController; def rescue_action(e) raise e end; end +# class CoursesController; def rescue_action(e) raise e end; end class CoursesControllerTest < ActionController::TestCase @@ -34,13 +34,13 @@ class CoursesControllerTest < ActionController::TestCase context "An anonymous user" do - should_have_access_denied_on_post_to(:new, {}) - should_have_access_denied_on_post_to(:create, {}) - should_have_access_denied_on_post_to(:edit, {:id => 1}) - should_have_access_denied_on_post_to(:update, {:id => 1}) - should_have_access_denied_on_post_to(:destroy, {:id => 1}) - should_request_login_on_post_to(:enroll, {:id => 1}) - should_request_login_on_post_to(:unenroll, {:id => 1}) + should_request_login_on_post_to(:new, {}) + should_request_login_on_post_to(:create, {}) + should_request_login_on_post_to(:edit, id: 1) + should_request_login_on_post_to(:update, id: 1) + should_request_login_on_post_to(:destroy, id: 1) + should_request_login_on_post_to(:enroll, id: 1) + should_request_login_on_post_to(:unenroll, id: 1) context "on get to :index" do setup { get :index } @@ -54,13 +54,13 @@ class CoursesControllerTest < ActionController::TestCase end should "display the selected period" do - get :index, :period => "1970.1" + get :index, period: "1970.1" assert_select 'h1', "Disciplinas 1970.1" end end context "on get to :show" do - setup { get :show, :id => @course.id } + setup { get :show, id: @course.id } should respond_with :success should render_template 'show' @@ -83,8 +83,8 @@ class CoursesControllerTest < ActionController::TestCase #context "A user" do # setup { login_as :bob } # should_be_restful do |resource| - # resource.create.params = { :short_name => 'test', :full_name => 'test', :description => 'test' } - # resource.update.params = { :short_name => 'test', :full_name => 'test', :description => 'test' } + # resource.create.params = { short_name: 'test', full_name: 'test', description: 'test' } + # resource.update.params = { short_name: 'test', full_name: 'test', description: 'test' } # end #end @@ -92,8 +92,8 @@ class CoursesControllerTest < ActionController::TestCase #context "A stranger" do # setup { logout } # should_be_restful do |resource| - # resource.create.params = { :short_name => 'test', :full_name => 'test', :description => 'test' } - # resource.update.params = { :short_name => 'test', :full_name => 'test', :description => 'test' } + # resource.create.params = { short_name: 'test', full_name: 'test', description: 'test' } + # resource.update.params = { short_name: 'test', full_name: 'test', description: 'test' } # resource.denied.actions = [ :new, :edit, :create, :update, :destroy ] # resource.denied.redirect = "'/login'" # resource.denied.flash = /must be logged in/i