Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
Merge pull request #42 from gurix/fixes/40_emtpy_breadcrumb_names
Browse files Browse the repository at this point in the history
fixes #40 Empty question group name results in empty breadcrumb
  • Loading branch information
gurix committed Aug 4, 2014
2 parents 206099e + a5d83c1 commit efb3555
Show file tree
Hide file tree
Showing 21 changed files with 199 additions and 90 deletions.
10 changes: 5 additions & 5 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
AllCops:
Includes:
- Rakefile
- config.ru
Excludes:
Include:
- '**/Rakefile'
- '**/config.ru'
Exclude:
- bin/**
- spec/dummy/db/schema.rb
- spec/dummy/config/initializers/secret_token.rb
Expand All @@ -11,6 +11,6 @@ AllCops:
Documentation:
Enabled: false
LineLength:
Enabled: true
Enabled: true
Max: 160

12 changes: 6 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ gemspec
# To use debugger
group :development, :test do
gem 'pry'
gem 'pry-debugger'
gem 'pry-byebug'
gem 'ruby-progressbar'
gem 'colorize'
gem 'jquery-rails'
gem 'bootstrap-sass'
gem 'simple_form'
gem 'breadcrumbs_on_rails'
gem 'quiet_assets'
gem 'better_errors'
gem 'launchy'
gem 'binding_of_caller'
gem 'coveralls', require: false
gem 'selenium-webdriver'
gem 'i18n-tasks'
gem 'simple_form'
gem 'jquery-rails'
gem 'bootstrap-sass'
gem 'breadcrumbs_on_rails'
gem 'coveralls', require: false
end
27 changes: 13 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
helena (0.3.1)
helena (0.3.2)
bootstrap-sass
breadcrumbs_on_rails
haml
Expand All @@ -13,7 +13,7 @@ PATH
rails (~> 4.1.1)
rails-i18n
sass-rails (~> 4.0.3)
simple_form
simple_form (~> 3.1.0.rc2)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -51,11 +51,14 @@ GEM
erubis (>= 2.6.6)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
bootstrap-sass (3.2.0.0)
bootstrap-sass (3.2.0.1)
sass (~> 3.2)
breadcrumbs_on_rails (2.3.0)
bson (2.3.0)
builder (3.2.2)
byebug (2.7.0)
columnize (~> 0.3)
debugger-linecache (~> 1.2)
capybara (2.4.1)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
Expand All @@ -76,12 +79,7 @@ GEM
thor
database_cleaner (1.3.0)
debug_inspector (0.0.2)
debugger (1.6.8)
columnize (>= 0.3.1)
debugger-linecache (~> 1.2.0)
debugger-ruby_core_source (~> 1.3.5)
debugger-linecache (1.2.0)
debugger-ruby_core_source (1.3.5)
diff-lcs (1.2.5)
docile (1.1.5)
easy_translate (0.5.0)
Expand All @@ -106,11 +104,12 @@ GEM
highline (1.6.21)
hike (1.2.3)
i18n (0.6.11)
i18n-tasks (0.6.3)
i18n-tasks (0.7.2)
activesupport
easy_translate (>= 0.5.0)
erubis
highline
i18n
slop (>= 3.5.0)
term-ansicolor
terminal-table
Expand Down Expand Up @@ -156,9 +155,9 @@ GEM
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
pry-debugger (0.2.3)
debugger (~> 1.3)
pry (>= 0.9.10, < 0.11.0)
pry-byebug (1.3.3)
byebug (~> 2.7)
pry (~> 0.10)
quiet_assets (1.0.3)
railties (>= 3.1, < 5.0)
rack (1.5.2)
Expand Down Expand Up @@ -221,7 +220,7 @@ GEM
multi_json (~> 1.0)
rubyzip (~> 1.0)
websocket (~> 1.0.4)
simple_form (3.0.2)
simple_form (3.1.0.rc2)
actionpack (~> 4.0)
activemodel (~> 4.0)
simplecov (0.9.0)
Expand Down Expand Up @@ -276,7 +275,7 @@ DEPENDENCIES
launchy
mongoid-rspec
pry
pry-debugger
pry-byebug
quiet_assets
rspec-collection_matchers
rspec-rails
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/helena/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ class ApplicationController < ::ApplicationController
def authenticate_administrator
fail(ActionController::RoutingError, 'Access Denied') unless can_administer?
end

def add_breadcrumb(name, path = nil, options = {})
super(name.presence || t('shared.untitled'), path, options)
end
end
end
13 changes: 6 additions & 7 deletions app/controllers/helena/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ def session_answers
end

def session_params
if params[:session]
params.require(:session).permit(answers: @question_group.question_codes, question_types: @question_group.question_codes)
end
return unless params[:session]
params.require(:session).permit(answers: @question_group.question_codes, question_types: @question_group.question_codes)
end

def question_group_questions
Expand All @@ -73,10 +72,10 @@ def update_answers

value = session_params[:answers][question_code] if session_params

unless value.blank?
answer = Helena::Answer.build_generic(question_code, value, request.remote_ip)
@session.answers << answer
end
next if value.blank?

answer = Helena::Answer.build_generic(question_code, value, request.remote_ip)
@session.answers << answer
end
session_answers
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/helena/concerns/application_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module ApplicationModel
include Mongoid::Timestamps

included do
before_destroy :removable?
before_destroy :removable?

# Removable is given by default. Override for custom behaviour
def removable?
Expand Down
7 changes: 3 additions & 4 deletions app/models/helena/concerns/questions/validates_one_label.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ module ValidatesOneLabel

def labels_preselection
selected_labels = labels.select { |label| label.preselected == true }
if selected_labels.size > 1
selected_labels.each { |label| label.errors.add(:preselected, I18n.t(:taken, scope: 'activerecord.errors.messages')) }
errors.add(:labels, I18n.t('helena.admin.radio_group.only_one_preselection_allowed'))
end
return if selected_labels.size <= 1
selected_labels.each { |label| label.errors.add(:preselected, I18n.t(:taken, scope: 'activerecord.errors.messages')) }
errors.add(:labels, I18n.t('helena.admin.radio_group.only_one_preselection_allowed'))
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/helena/question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class Question

validates :code, presence: true

# consist of lowercase characters or digits, not starting with a digit or underscore and not ending with an underscore
# foo_32: correct, 32_foo: incorrect, _bar: incorrect, bar_: incorrect, FooBaar: incorrect
# consist of lowercase characters or digits, not starting with a digit or underscore and not ending with an underscore
# foo_32: correct, 32_foo: incorrect, _bar: incorrect, bar_: incorrect, FooBaar: incorrect
validates :code, format: { with: CODE_FORMAT }
validate :uniqueness_of_code

Expand Down
6 changes: 3 additions & 3 deletions app/models/helena/sub_question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class SubQuestion
def uniqueness_of_code
question_code_occurences = question.question_group.version.question_code_occurences

if question_code_occurences[code] > 1
errors.add :code, :taken, value: code
end
return true if question_code_occurences[code] <= 1

errors.add(:code, :taken, value: code)
end
end
end
1 change: 0 additions & 1 deletion app/views/helena/admin/question_groups/_form.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
= simple_form_for [:admin, @survey, @question_group] do |f|
= f.input :title
%br
= f.submit t('shared.save'), class: 'btn btn-success'
4 changes: 1 addition & 3 deletions app/views/helena/admin/questions/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
= f.input :code, hint: t('shared.code_hint')
= f.input :_type, collection: Helena::Question::TYPES.map { |type| [type.model_name.human, type] }
- if @question.respond_to? :required
= f.input :required, as: :boolean, wrapper: :checkbox
= f.input :required, as: :boolean
- if @question.is_a?(Helena::Questions::LongText) || @question.is_a?(Helena::Questions::StaticText)
= f.input :default_value
- if @question.is_a?(Helena::Questions::ShortText)
Expand All @@ -12,6 +12,4 @@
= render 'labels', form: f
- if @question.includes_subquestions?
= render 'sub_questions', form: f

%br
= f.submit t('shared.save'), class: 'btn btn-success'
4 changes: 2 additions & 2 deletions app/views/helena/admin/questions/_labels.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
%td.position
= label.input :position, as: :integer, label: false
%td.preselected
= label.input :preselected, as: :boolean, wrapper: :checkbox, label: Helena::Label.human_attribute_name(:preselected)
= label.input :preselected, as: :boolean, label: Helena::Label.human_attribute_name(:preselected)
%td.text
= label.input :text, label: false
%td.value
= label.input :value, label: false
%td.delete
- unless label.object.new_record?
= label.input :_destroy, as: :boolean, label: Helena::Label.human_attribute_name(:_destroy), wrapper: :checkbox
= label.input :_destroy, as: :boolean, label: Helena::Label.human_attribute_name(:_destroy)
7 changes: 3 additions & 4 deletions app/views/helena/admin/questions/_sub_questions.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@
= sub_question.input :code, label: false, hint: t('shared.code_hint')
- if @question.is_a?(Helena::Questions::CheckboxGroup)
%td.preselected
= sub_question.input :preselected, as: :boolean, wrapper: :checkbox
= sub_question.input :preselected, as: :boolean
%td.text
= sub_question.input :text, label: false
- if @question.is_a?(Helena::Questions::CheckboxGroup)
%td.value
= sub_question.input :value, label: false, as: :hidden, value: 1
%td.delete
- unless sub_question.object.new_record?
= sub_question.input :_destroy, as: :boolean,
wrapper: :checkbox,
label: Helena::SubQuestion.human_attribute_name(:_destroy)
= sub_question.input :_destroy, as: :boolean,
label: Helena::SubQuestion.human_attribute_name(:_destroy)
28 changes: 23 additions & 5 deletions config/initializers/simple_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
# wrapper, change the order or even add your own to the
# stack. The options given below are used to wrap the
# whole input.
config.wrappers :default, class: :input, hint_class: :field_with_hint, error_class: :field_with_errors do |b|
config.wrappers :default, class: :input,
hint_class: :field_with_hint,
error_class: :field_with_errors do |b|
## Extensions enabled by default
# Any of these extensions can be disabled for a
# given input by passing: `f.input EXTENSION_NAME => false`.
Expand Down Expand Up @@ -42,6 +44,12 @@
b.use :label_input
b.use :hint, wrap_with: { tag: :span, class: :hint }
b.use :error, wrap_with: { tag: :span, class: :error }

## full_messages_for
# If you want to display the full error message for the attribute, you can
# use the component :full_error, like:
#
# b.use :full_error, wrap_with: { tag: :span, class: :error }
end

# The default wrapper to be used by the FormBuilder.
Expand All @@ -65,7 +73,7 @@
config.error_notification_tag = :div

# CSS class to add for error notification helper.
config.error_notification_class = 'alert alert-error'
config.error_notification_class = 'error_notification'

# ID to add for error notification helper.
# config.error_notification_id = nil
Expand All @@ -91,10 +99,10 @@
# config.item_wrapper_class = nil

# How the label text should be generated altogether with the required text.
# config.label_text = lambda { |label, required| "#{required} #{label}" }
# config.label_text = lambda { |label, required, explicit_label| "#{required} #{label}" }

# You can define the class to use on all labels. Default is nil.
# config.label_class = 'control-label'
# config.label_class = nil

# You can define the class to use on all forms. Default is simple_form.
# config.form_class = :simple_form
Expand Down Expand Up @@ -140,5 +148,15 @@
# config.cache_discovery = !Rails.env.development?

# Default class for inputs
config.input_class = 'form-control'
# config.input_class = nil

# Define the default class of the input wrapper of the boolean input.
config.boolean_label_class = 'checkbox'

# Defines if the default input wrapper class should be included in radio
# collection wrappers.
# config.include_default_input_wrapper_class = true

# Defines which i18n scope will be used in Simple Form.
# config.i18n_scope = 'simple_form'
end
Loading

0 comments on commit efb3555

Please sign in to comment.