Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Commit

Permalink
Merge pull request #804 from ctumwebaze/master
Browse files Browse the repository at this point in the history
remove reunited label and field rapidftr/tracker#265
  • Loading branch information
tomclement committed May 18, 2015
2 parents eabd561 + b26de29 commit 1cf3c5b
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 6 deletions.
4 changes: 4 additions & 0 deletions app/controllers/children_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def index
@form_sections = form_sections
@system_fields = Child.default_child_fields + Child.build_date_fields_for_solar

unless Enquiry.enquiries_enabled?
@system_fields = @system_fields.reject { |field| field == 'reunited_at' }
end

respond_to do |format|
format.html
format.xml { render :xml => @children }
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/enquiries_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ def enquiry_title_fields(enquiry)
end

def enquiries_enabled
Enquiry.enquiries_enabled
Enquiry.enquiries_enabled?
end
end
2 changes: 1 addition & 1 deletion app/models/enquiry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def with_child_potential_matches(options = {})
end
end

def enquiries_enabled
def enquiries_enabled?
enquiries_enabled_setting = SystemVariable.find_by_name(SystemVariable::ENABLE_ENQUIRIES)
enquiries_enabled_setting.nil? || enquiries_enabled_setting.to_bool_value
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/permission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def self.all
'System' => SYSTEM
}

if Enquiry.enquiries_enabled
if Enquiry.enquiries_enabled?
perm_hash = perm_hash.merge('Enquiries' => ENQUIRIES, 'PotentialMatches' => POTENTIAL_MATCHES)
end

Expand All @@ -62,7 +62,7 @@ def self.hashed_values
'System' => SYSTEM.values
}

if Enquiry.enquiries_enabled
if Enquiry.enquiries_enabled?
perm_hash = perm_hash.merge('Enquiries' => ENQUIRIES.values, 'PotentialMatches' => POTENTIAL_MATCHES.values)
end

Expand Down
12 changes: 10 additions & 2 deletions app/views/children/_filter_box.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<form class="filter_panel">
<input type="hidden" name="order_by" value="<%= @order %>"/>
<%= t("children.filter_by.label") %>:
<span> <%= select_tag :filter, options_for_select([[ t("children.filter_by.all"), "" ],[t("children.filter_by.active"),"active"],[t("children.filter_by.reunited"),"reunited"],
[t("children.filter_by.flagged"),"flag"]], @filter), { :onchange => "this.form.submit();"} %> </span>
<%
options = [[ t("children.filter_by.all"), "" ],[t("children.filter_by.active"),"active"]]

if enquiries_enabled
options << [t("children.filter_by.reunited"),"reunited"]
end

options << [t("children.filter_by.flagged"),"flag"]
%>
<span> <%= select_tag :filter, options_for_select(options, @filter), { :onchange => "this.form.submit();"} %> </span>
</form>
26 changes: 26 additions & 0 deletions spec/controllers/children_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,32 @@ def mock_child(stubs = {})
end
end

context 'when enquiries feature is turned off' do
before { @session = fake_field_worker_login }
before :each do
SystemVariable.all.each { |variable| variable.destroy }
SystemVariable.create!(:name => SystemVariable::ENABLE_ENQUIRIES, :type => 'boolean', :value => '0')
end

it 'should not include reunited_at in the system fields' do
get :index
expect(assigns[:system_fields]).to_not include('reunited_at')
end
end

context 'when enquiries feature is turned on' do
before { @session = fake_field_worker_login }
before :each do
SystemVariable.all.each { |variable| variable.destroy }
SystemVariable.create!(:name => SystemVariable::ENABLE_ENQUIRIES, :type => 'boolean', :value => '1')
end

it 'should include reunited_at in the system fields' do
get :index
expect(assigns[:system_fields]).to include('reunited_at')
end
end

context 'viewing reunited children' do
context 'admin' do
before do
Expand Down
49 changes: 49 additions & 0 deletions spec/views/children/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require 'spec_helper'

describe 'children/index.html.erb', :type => :view do

before do
@user = double('user', :has_permission? => true, :user_name => 'name', :id => 'test-user-id')

allow(@user).to receive(:localize_date).and_return('July 19 2010 13:05:32UTC')
allow(controller).to receive(:current_user).and_return(@user)
allow(view).to receive(:current_user).and_return(@user)
allow(view).to receive(:logged_in?).and_return(true)
allow(view).to receive(:current_user_name).and_return('name')

@highlighted_fields = [
Field.new(:name => 'child_father', :display_name => 'Father of child', :visible => true),
Field.new(:name => 'child_name', :display_name => 'child_name', :visible => true)]
allow(Form).to receive(:find_by_name).and_return(double('Form', :sorted_highlighted_fields => @highlighted_fields, :title_fields => []))
end

context 'when enquiries are turned off' do
before :each do
@enable_enquiries = SystemVariable.create!(:name => SystemVariable::ENABLE_ENQUIRIES, :type => 'boolean', :value => 0)
end

after :each do
@enable_enquiries.destroy
end

it 'should not show the reunited filter' do
render
expect(rendered).to_not have_tag('option[value="reunited"]')
end
end

context 'when enquiries are turned on' do
before :each do
@enable_enquiries = SystemVariable.create!(:name => SystemVariable::ENABLE_ENQUIRIES, :type => 'boolean', :value => 1)
end

after :each do
@enable_enquiries.destroy
end

it 'should show the reunited filter' do
render
expect(rendered).to have_tag('option[value="reunited"]')
end
end
end

0 comments on commit 1cf3c5b

Please sign in to comment.