Skip to content

Commit

Permalink
cleaned up
Browse files Browse the repository at this point in the history
Conflicts:
	enju_leaf.gemspec
	lib/enju_leaf.rb
	lib/enju_leaf/version.rb
	spec/controllers/user_export_files_controller_spec.rb
	spec/controllers/user_groups_controller_spec.rb
	spec/routing/accounts_spec.rb
  • Loading branch information
nabeta committed Feb 19, 2015
1 parent 25389f6 commit 42d16f3
Show file tree
Hide file tree
Showing 20 changed files with 115 additions and 116 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ gem "enju_event", github: "next-l/enju_event", branch: "master"
gem "enju_message", github: "next-l/enju_message", branch: "master"
gem "enju_search_log", github: "next-l/enju_search_log", branch: "master"
gem "enju_manifestation_viewer", github: "next-l/enju_manifestation_viewer", branch: "master"
gem "cancancan"
gem "coveralls", require: false, group: :test

# To use a debugger
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require 'rspec/core'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/**/*_spec.rb']
spec.pattern = FileList['spec/**/*_spec.rb']
end

task :default => :spec
2 changes: 1 addition & 1 deletion lib/enju_leaf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def render_500
return if performed?
#flash[:notice] = t('page.connection_failed')
respond_to do |format|
format.html {render file: "#{Rails.root.to_s}/public/500", layout: false, status: 500}
format.html {render file: "#{Rails.root}/public/500", layout: false, status: 500}
format.xml {render template: 'page/500', status: 500}
format.json { render text: '{"error": "server_error"}' }
format.xml {render template: 'page/500.xml', status: 500}
Expand Down
4 changes: 2 additions & 2 deletions lib/enju_leaf/calculate_stat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ def check_date
end

def send_message
sender = User.find(1) # system
sender = User.find(1) #system
message_template = MessageTemplate.localized_template('counting_completed', user.profile.locale)
request = MessageRequest.new
request.assign_attributes({:sender => sender, :receiver => user, :message_template => message_template})
request.assign_attributes({sender: sender, receiver: user, message_template: message_template})
request.save_message_body
request.transition_to!(:sent)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/enju_leaf/export_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ def enju_export_file_model

module InstanceMethods
def send_message
sender = User.find(1)
sender = User.find(1) #system
message_template = MessageTemplate.localized_template('export_completed', user.profile.locale)
request = MessageRequest.new
request.assign_attributes({:sender => sender, :receiver => user, :message_template => message_template})
request.assign_attributes({sender: sender, receiver: user, message_template: message_template})
request.save_message_body
request.transition_to!(:sent)
end
Expand Down
13 changes: 6 additions & 7 deletions lib/enju_leaf/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ def link_to_wikipedia(string)
end

def locale_display_name(locale)
Language.where(:iso_639_1 => locale).first.display_name
Language.where(iso_639_1: locale).first.display_name
end

def locale_native_name(locale)
Language.where(:iso_639_1 => locale).first.native_name
Language.where(iso_639_1: locale).first.native_name
end

def move_position(object)
render :partial => 'page/position', :locals => {:object => object}
render partial: 'page/position', locals: {object: object}
end

def localized_state(state)
Expand Down Expand Up @@ -91,7 +91,7 @@ def back_to_index(options = {})
options.delete(:page) if options[:page].to_i == 1
end
unless controller_name == 'test'
link_to t('page.listing', :model => t("activerecord.models.#{controller_name.singularize}")), url_for(params.merge(:controller => controller_name, :action => :index, :id => nil, :only_path => true).merge(options))
link_to t('page.listing', model: t("activerecord.models.#{controller_name.singularize}")), url_for(params.merge(controller: controller_name, action: :index, id: nil, only_path: true).merge(options))
end
end

Expand All @@ -102,12 +102,11 @@ def set_focus_on_search_form
def markdown_helper(string)
return unless string
if defined?(JRUBY_VERSION)
string
# Kramdown::Document.new(string.to_s).to_html.html_safe
Kramdown::Document.new(string.to_s).to_html.html_safe
else
markdown = Redcarpet::Markdown.new(
Redcarpet::Render::HTML,
:autolink => true, :safe_links_only => true
autolink: true, safe_links_only: true
)
markdown.render(string.to_s).html_safe
end
Expand Down
30 changes: 15 additions & 15 deletions lib/enju_leaf/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ def enju_leaf_user_model
# :expired_at, :locked, :role_id,
# :user_has_role_attributes, :auto_generated_password,
# :profile_attributes,
# :as => :admin
# as: :admin

scope :administrators, -> { joins(:role).where('roles.name = ?', 'Administrator') }
scope :librarians, -> { joins(:role).where('roles.name = ? OR roles.name = ?', 'Administrator', 'Librarian') }
scope :suspended, -> { where('locked_at IS NOT NULL') }
has_one :profile
if defined?(EnjuBiblio)
has_many :import_requests
has_many :picture_files, :as => :picture_attachable, :dependent => :destroy
has_many :picture_files, as: :picture_attachable, dependent: :destroy
end
has_one :user_has_role, :dependent => :destroy
has_one :role, :through => :user_has_role
has_one :user_has_role, dependent: :destroy
has_one :role, through: :user_has_role
belongs_to :user_group
belongs_to :library
belongs_to :required_role, class_name: 'Role', foreign_key: 'required_role_id'
Expand All @@ -39,18 +39,18 @@ def enju_leaf_user_model
validates :username, presence: true, uniqueness: true, format: {
with: /\A[0-9A-Za-z][0-9A-Za-z_\-]*[0-9A-Za-z]\Z/
}
validates :email, :format => Devise::email_regexp, :allow_blank => true, :uniqueness => true
validates_date :expired_at, :allow_blank => true
validates :email, format: Devise::email_regexp, allow_blank: true, uniqueness: true
validates_date :expired_at, allow_blank: true

with_options :if => :password_required? do |v|
with_options if: :password_required? do |v|
v.validates_presence_of :password
v.validates_confirmation_of :password
v.validates_length_of :password, :allow_blank => true,
:within => Devise::password_length
v.validates_length_of :password, allow_blank: true,
within: Devise::password_length
end

validates_presence_of :email, :email_confirmation, :on => :create, :if => proc{|user| !user.operator.try(:has_role?, 'Librarian')}
validates_confirmation_of :email, :on => :create #, :if => proc{|user| !user.operator.try(:has_role?, 'Librarian')}
validates_presence_of :email, :email_confirmation, on: :create, if: proc{|user| !user.operator.try(:has_role?, 'Librarian')}
validates_confirmation_of :email, on: :create #, if: proc{|user| !user.operator.try(:has_role?, 'Librarian')}

before_validation :set_lock_information
before_destroy :check_role_before_destroy
Expand All @@ -61,7 +61,7 @@ def enju_leaf_user_model
friendly_id :username
#has_paper_trail
normalize_attributes :username
normalize_attributes :email, :with => :strip
normalize_attributes :email, with: :strip

attr_accessor :operator, :password_not_verified,
:update_own_account, :auto_generated_password,
Expand Down Expand Up @@ -178,7 +178,7 @@ def check_expiration

def check_role_before_destroy
if self.has_role?('Administrator')
raise 'This is the last administrator in this system.' if Role.where(:name => 'Administrator').first.users.size == 1
raise 'This is the last administrator in this system.' if Role.where(name: 'Administrator').first.users.size == 1
end
end

Expand All @@ -200,7 +200,7 @@ def is_admin?

def last_librarian?
if self.has_role?('Librarian')
role = Role.where(:name => 'Librarian').first
role = Role.where(name: 'Librarian').first
true if role.users.size == 1
end
end
Expand Down Expand Up @@ -232,7 +232,7 @@ def deletable_by?(current_user)

# 最後の管理者を削除しようとした
if has_role?('Administrator')
if Role.where(:name => 'Administrator').first.users.size == 1
if Role.where(name: 'Administrator').first.users.size == 1
errors[:base] << I18n.t('user.last_administrator')
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/enju_leaf/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module EnjuLeaf
VERSION = "1.2.0.pre1"
VERSION = "1.2.0.beta.1"
end
2 changes: 1 addition & 1 deletion lib/tasks/enju_leaf_tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require 'tasks/profile'
namespace :enju_leaf do
desc "create initial records for enju_leaf"
task :setup => :environment do
Dir.glob(Rails.root.to_s + '/db/fixtures/enju_leaf/*.yml').each do |file|
Dir.glob(Rails.root + '/db/fixtures/enju_leaf/*.yml').each do |file|
ActiveRecord::Fixtures.create_fixtures('db/fixtures/enju_leaf', File.basename(file, '.*'))
end

Expand Down
13 changes: 7 additions & 6 deletions spec/controllers/my_accounts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
end

it "assigns the requested user as @user" do
get :show, :id => 'admin'
get :show, id: 'admin'
expect(response).to be_success
end
end

describe "When not logged in" do
it "assigns the requested user as @user" do
get :show, :id => 'admin'
get :show, id: 'admin'
expect(assigns(:user)).to be_nil
expect(response).to redirect_to(new_user_session_url)
end
Expand Down Expand Up @@ -80,8 +80,8 @@

describe "PUT update" do
before(:each) do
@attrs = {:user_attributes => {:email => 'newaddress@example.jp', :current_password => 'password'}, :locale => 'en'}
@invalid_attrs = {:user_attributes => {:username => ''}, :user_number => '日本語'}
@attrs = {:user_attributes => {email: 'newaddress@example.jp', :current_password => 'password'}, :locale => 'en'}
@invalid_attrs = {:user_attributes => {username: ''}, user_number: '日本語'}
@invalid_passwd_attrs = {:user_attributes => {:current_password=> ''}}
end

Expand Down Expand Up @@ -124,11 +124,12 @@
expect(response).to render_template("edit")
end
end

describe "with invalid password params" do
it "assigns the requested user as @user" do
put :update, profile: @invalid_passwd_attrs
expect(assigns(:profile).errors).not_to be_blank
end
expect(assigns(:profile).errors).not_to be_blank
end
end
end

Expand Down
24 changes: 12 additions & 12 deletions spec/controllers/profiles_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
fixtures :all

describe "GET index", :solr => true do
before do
Profile.reindex
end
before do
Profile.reindex
end

describe "When logged in as Administrator" do
login_fixture_admin
Expand Down Expand Up @@ -202,24 +202,24 @@

describe "with valid params" do
it "assigns a newly created user as @profile" do
post :create, :profile => @attrs
post :create, profile: @attrs
assigns(:profile).should be_valid
end

it "redirects to the created user" do
post :create, :profile => @attrs
post :create, profile: @attrs
response.should redirect_to(profile_url(assigns(:profile)))
end
end

describe "with invalid params" do
it "assigns a newly created but unsaved user as @profile" do
post :create, :profile => @invalid_attrs
post :create, profile: @invalid_attrs
assigns(:profile).should_not be_valid
end

it "re-renders the 'new' template" do
post :create, :profile => @invalid_attrs
post :create, profile: @invalid_attrs
response.should render_template("new")
end
end
Expand All @@ -230,24 +230,24 @@

describe "with valid params" do
it "assigns a newly created user as @profile" do
post :create, :profile => @attrs
post :create, profile: @attrs
assigns(:profile).should be_valid
end

it "redirects to the created user" do
post :create, :profile => @attrs
post :create, profile: @attrs
response.should redirect_to(profile_url(assigns(:profile)))
end
end

describe "with invalid params" do
it "assigns a newly created but unsaved user as @profile" do
post :create, :profile => @invalid_attrs
post :create, profile: @invalid_attrs
assigns(:profile).should_not be_valid
end

it "re-renders the 'new' template" do
post :create, :profile => @invalid_attrs
post :create, profile: @invalid_attrs
response.should render_template("new")
end
end
Expand Down Expand Up @@ -311,7 +311,7 @@
end

it "should update other user's role" do
put :update, id: profiles(:user1).id, profile: {:user_attributes => {:user_has_role_attributes => {:role_id => 4}, :email => profiles(:user1).user.email, :locale => 'en', :id => profiles(:user1).user.id}}
put :update, id: profiles(:user1).id, profile: {:user_attributes => {:user_has_role_attributes => {:role_id => 4}, :email => profiles(:user1).user.email, :locale => 'en', id: profiles(:user1).user.id}}
response.should redirect_to profile_url(assigns(:profile))
assigns(:profile).reload
assigns(:profile).user.role.should eq Role.where(name: 'Administrator').first
Expand Down
Loading

0 comments on commit 42d16f3

Please sign in to comment.