Skip to content

Commit

Permalink
Fixed listing companies and pharmacies
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed Jan 14, 2015
1 parent ba8eda6 commit 61781d0
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 25 deletions.
58 changes: 52 additions & 6 deletions spec/home_2_list_spec.rb
Expand Up @@ -10,6 +10,10 @@
@browser.close
end

after :each do
logout
end

before :all do
@idx = 0
waitForOddbToBeReady(@browser, OddbUrl)
Expand All @@ -20,22 +24,64 @@
@browser.goto OddbUrl
end

{ 'hospitals' => 'hospitallist',
'pharmacies' => 'pharmacylist',
'companies' => 'companylist',
{
'companies' => 'companylist',
'hospitals' => 'hospitallist',
'pharmacies' => 'pharmacylist',
}.each {
|kind, link_name|
it "in home_#{kind} should be possible consult the corresponding list of #{kind}" do
login(ViewerUser, ViewerPassword)
url = OddbUrl + '/de/gcc/home_'+kind
@browser.goto url
@browser.url.should == url
@browser.link(:name, link_name).exist?.should == true
@browser.link(:name, link_name).click
@browser.url.index(link_name).should > 0
# require 'pry'; binding.pry
require 'pry'; binding.pry unless @browser.url.index(link_name)
@browser.url.index(link_name).should_not == nil
@browser.link(:name => 'range').exist?.should == true
# @browser.link(:href => /\/#{link_name.sub('list','')}\ean\//).exist?.should == true
end
}

CompanyListName = 'companylist'
CompanyLimitListed = 100
def count_nr_companies_displayed
nr_founds = 0
@browser.links.each{ |link| nr_founds += 1 if link.name.eql?('name') }
nr_founds
end
def check_nr_companies(must_have_all)
@browser.link(:name, CompanyListName).exist?.should == true
@browser.link(:name, CompanyListName).click
@browser.url.index(CompanyListName).should > 0
nr_founds = count_nr_companies_displayed
if must_have_all
nr_founds.should > CompanyLimitListed
else
nr_founds.should <= CompanyLimitListed
end
end

it "in home_companies we should see all companies when logged in as admin" do
login
@browser.goto OddbUrl + '/de/gcc/home_companies'
check_nr_companies(true)
end

it "in home_companies we should have the link active_companies if logged in as admin" do
login
@browser.goto OddbUrl + '/de/gcc/home_companies'
@browser.link(:name, CompanyListName).click
link = @browser.link(:name, 'listed_companies')
link.exist?.should == true
link.click
count_nr_companies_displayed.should <= CompanyLimitListed
end

it "in home_companies we should see all companies when logged in as user" do
login(ViewerUser, ViewerPassword)
@browser.goto OddbUrl + '/de/gcc/home_companies'
check_nr_companies(true)
end

end
23 changes: 11 additions & 12 deletions src/state/companies/companylist.rb
Expand Up @@ -32,20 +32,19 @@ def init
end
class CompanyList < CompanyResult
DIRECT_EVENT = :companylist
def init
model = @session.app.companies.values
if(@session.event != :listed_companies \
&& @session.allowed?('edit', 'org.oddb.model.!company.*'))
@model = model
else
def init
model = @session.app.registration_holders.values
if (@session.event == :listed_companies && @session.allowed?('edit', 'org.oddb.model.!company.*'))
@direct_event = :listed_companies
association = @session.user.model
@model = model.select { |company|
company.listed? || company == association
}
end
super
end
@model = model.select { |company|
company.listed? || company == association
}
else
@model = model
end
super
end
def direct_event
@direct_event || super
end
Expand Down
11 changes: 6 additions & 5 deletions src/state/global.rb
Expand Up @@ -168,7 +168,6 @@ def [](*args)
:analysis_alphabetical => State::Analysis::Alphabetical,
:data => State::User::DownloadItem,
:preferences => State::User::Preferences,
:companylist => State::Companies::CompanyList,
:compare => State::Drugs::Compare,
:compare_search => State::Drugs::CompareSearch,
:ddd => State::Drugs::DDD,
Expand All @@ -191,8 +190,6 @@ def [](*args)
:home_migel => State::Migel::Init,
:home_substances => State::Substances::Init,
:home_user => State::User::Init,
:hospitallist => State::Hospitals::HospitalList,
:pharmacylist => State::Pharmacies::PharmacyList,
:interaction_chooser => State::Interactions::InteractionChooser,
:limitation_text => State::Drugs::LimitationText,
:limitation_texts => State::Drugs::LimitationTexts,
Expand Down Expand Up @@ -366,16 +363,20 @@ def pharmacy
end
end
def pharmacylist
model = @session.pharmacies.values
model = @session.app.pharmacies.values
State::Pharmacies::PharmacyList.new(@session, model)
end
def companylist
model = @session.app.registration_holders.values
State::Companies::CompanyList.new(@session, model)
end
def hospital
if ean = @session.user_input(:ean) and model = @session.app.hospital(ean)
State::Hospitals::Hospital.new(@session, model)
end
end
def hospitallist
model = @session.hospitals.values
model = @session.app.hospitals.values
State::Hospitals::HospitalList.new(@session, model)
end
def export_csv
Expand Down
8 changes: 8 additions & 0 deletions src/util/oddbapp.rb
Expand Up @@ -1109,6 +1109,14 @@ def _search_exact_classified_result(sequences, type=:unknown, result=nil)
result
end

def pharmacies
companies.select{|key, item| item.is_pharmacy? }
end

def registration_holders
companies.select{|key, item| item.business_area.to_s == ODDB::BA_type::BA_pharma.to_s }
end

def search_pharmacies(key)
result = [ pharmacy_by_gln(key)] if key.to_s.match(VALID_EAN13)
return result if result and result.size > 0 and result.first.is_pharmacy?
Expand Down
1 change: 1 addition & 0 deletions src/util/validator.rb
Expand Up @@ -267,6 +267,7 @@ class Validator < SBSM::Validator
:paypal_ipn,
:paypal_return,
:paypal_thanks,
:pharmacylist,
:plugin,
:powerlink,
:preview,
Expand Down
21 changes: 19 additions & 2 deletions test/test_state/global.rb
Expand Up @@ -76,11 +76,16 @@ def set_persistent_user_input(key, value)
end
end
class StubApp
attr_accessor :companies, :galenic_groups, :fachinfos
attr_accessor :companies, :pharmacies, :hospitals, :galenic_groups, :fachinfos
attr_accessor :state_transp_called
def registration_holders
['registration_holder']
end
def initialize
@state_transp_called = false
@companies ||= {}
@companies ||= {}
@hospitals ||= {}
@pharmacies ||= {}
end
def company(oid)
@companies[oid.to_i]
Expand Down Expand Up @@ -240,12 +245,24 @@ def test_direct_request_path__else
end
assert_equal('request_path', @state.direct_request_path)
end
def test_companylist
flexmock(@session) do |s|
s.should_receive(:registration_holders).and_return(['registration_holder'])
end
assert_kind_of(State::Companies::CompanyList, @state.companylist)
end
def test_doctorlist
flexmock(@session) do |s|
s.should_receive(:doctors).and_return({'key' => 'model'})
end
assert_kind_of(State::Doctors::DoctorList, @state.doctorlist)
end
def test_pharmacylist
flexmock(@session) do |s|
s.should_receive(:pharmacies).and_return({'key' => 'model'})
end
assert_kind_of(State::Pharmacies::PharmacyList, @state.pharmacylist)
end
def test_download__init
flexmock(@session) do |s|
s.should_receive(:is_crawler?).and_return(true)
Expand Down

0 comments on commit 61781d0

Please sign in to comment.