Use Ruby 1.9 hash syntax & consistent formatting

This commit is contained in:
Jon Atack 2015-03-25 10:36:17 +05:30
parent 542bde646e
commit 8a9e454131
1 changed files with 65 additions and 58 deletions

View File

@ -31,9 +31,9 @@ module Ransack
describe '#sort_link with default search_key' do describe '#sort_link with default search_key' do
subject { @controller.view_context subject { @controller.view_context
.sort_link( .sort_link(
[:main_app, Person.search(:sorts => ['name desc'])], [:main_app, Person.search(sorts: ['name desc'])],
:name, :name,
:controller => 'people' controller: 'people'
) )
} }
it { it {
@ -53,10 +53,10 @@ module Ransack
subject { @controller.view_context subject { @controller.view_context
.sort_link( .sort_link(
Person.search( Person.search(
{ :sorts => ['name desc'] }, :search_key => :people_search { sorts: ['name desc'] }, search_key: :people_search
), ),
:name, :name,
:controller => 'people' controller: 'people'
) )
} }
it { it {
@ -73,10 +73,11 @@ module Ransack
describe '#sort_link desc through association table defined as a symbol' do describe '#sort_link desc through association table defined as a symbol' do
subject { @controller.view_context subject { @controller.view_context
.sort_link( .sort_link(
Person.search({ :sorts => 'comments_body asc' }), Person.search({ sorts: 'comments_body asc' }),
:comments_body, :controller => 'people' :comments_body,
) controller: 'people'
} )
}
it { it {
should match( should match(
if ActiveRecord::VERSION::STRING =~ /^3\.[1-2]\./ if ActiveRecord::VERSION::STRING =~ /^3\.[1-2]\./
@ -93,10 +94,11 @@ module Ransack
describe '#sort_link through association table defined as a string' do describe '#sort_link through association table defined as a string' do
subject { @controller.view_context subject { @controller.view_context
.sort_link( .sort_link(
Person.search({ :sorts => 'comments.body desc' }), Person.search({ sorts: 'comments.body desc' }),
'comments.body', :controller => 'people' 'comments.body',
) controller: 'people'
} )
}
it { it {
should match( should match(
if ActiveRecord::VERSION::STRING =~ /^3\.[1-2]\./ if ActiveRecord::VERSION::STRING =~ /^3\.[1-2]\./
@ -113,24 +115,25 @@ module Ransack
describe '#sort_link works even if search params are a blank string' do describe '#sort_link works even if search params are a blank string' do
before { @controller.view_context.params[:q] = '' } before { @controller.view_context.params[:q] = '' }
specify { specify {
expect { expect { @controller.view_context
@controller.view_context.sort_link( .sort_link(
Person.search(@controller.view_context.params[:q]), Person.search(
:name, @controller.view_context.params[:q]),
:controller => 'people' :name,
) controller: 'people'
)
}.not_to raise_error }.not_to raise_error
} }
end end
describe '#sort_link with search_key defined as a string' do describe '#sort_link with search_key defined as a string' do
subject { subject { @controller.view_context
@controller.view_context.sort_link( .sort_link(
Person.search( Person.search(
{ :sorts => ['name desc'] }, :search_key => 'people_search' { sorts: ['name desc'] }, search_key: 'people_search'
), ),
:name, :name,
:controller => 'people' controller: 'people'
) )
} }
it { it {
@ -149,8 +152,8 @@ module Ransack
.sort_link( .sort_link(
[:main_app, Person.search()], [:main_app, Person.search()],
:name, :name,
:controller => 'people', controller: 'people',
'default_order' => 'desc' default_order: 'desc'
) )
} }
it { should_not match /default_order/ } it { should_not match /default_order/ }
@ -159,9 +162,9 @@ module Ransack
describe '#sort_link with multiple search_keys defined as an array' do describe '#sort_link with multiple search_keys defined as an array' do
subject { @controller.view_context subject { @controller.view_context
.sort_link( .sort_link(
[:main_app, Person.search(:sorts => ['name desc', 'email asc'])], [:main_app, Person.search(sorts: ['name desc', 'email asc'])],
:name, [:name, 'email DESC'], :name, [:name, 'email DESC'],
:controller => 'people' controller: 'people'
) )
} }
it { it {
@ -176,9 +179,9 @@ module Ransack
describe '#sort_link with multiple search_keys does not break on nil values & ignores them' do describe '#sort_link with multiple search_keys does not break on nil values & ignores them' do
subject { @controller.view_context subject { @controller.view_context
.sort_link( .sort_link(
[:main_app, Person.search(:sorts => ['name desc', nil, 'email', nil])], [:main_app, Person.search(sorts: ['name desc', nil, 'email', nil])],
:name, [nil, :name, nil, 'email DESC', nil], :name, [nil, :name, nil, 'email DESC', nil],
:controller => 'people' controller: 'people'
) )
} }
it { it {
@ -193,10 +196,10 @@ module Ransack
describe '#sort_link with multiple search_keys should allow a label to be specified' do describe '#sort_link with multiple search_keys should allow a label to be specified' do
subject { @controller.view_context subject { @controller.view_context
.sort_link( .sort_link(
[:main_app, Person.search(:sorts => ['name desc', 'email asc'])], [:main_app, Person.search(sorts: ['name desc', 'email asc'])],
:name, [:name, 'email DESC'], :name, [:name, 'email DESC'],
'Property Name', 'Property Name',
:controller => 'people' controller: 'people'
) )
} }
it { should match /Property Name ▼/ } it { should match /Property Name ▼/ }
@ -205,9 +208,9 @@ module Ransack
describe '#sort_link with multiple search_keys should flip multiple fields specified without a direction' do describe '#sort_link with multiple search_keys should flip multiple fields specified without a direction' do
subject { @controller.view_context subject { @controller.view_context
.sort_link( .sort_link(
[:main_app, Person.search(:sorts => ['name desc', 'email asc'])], [:main_app, Person.search(sorts: ['name desc', 'email asc'])],
:name, [:name, :email], :name, [:name, :email],
:controller => 'people' controller: 'people'
) )
} }
it { it {
@ -224,8 +227,8 @@ module Ransack
.sort_link( .sort_link(
[:main_app, Person.search()], [:main_app, Person.search()],
:name, [:name, :email], :name, [:name, :email],
:controller => 'people', controller: 'people',
'default_order' => 'desc' default_order: 'desc'
) )
} }
it { it {
@ -242,8 +245,8 @@ module Ransack
.sort_link( .sort_link(
[:main_app, Person.search()], [:main_app, Person.search()],
:name, [:name, :email], :name, [:name, :email],
:controller => 'people', controller: 'people',
:default_order => :desc default_order: :desc
) )
} }
it { it {
@ -260,8 +263,8 @@ module Ransack
.sort_link( .sort_link(
[:main_app, Person.search()], [:main_app, Person.search()],
:name, [:name, :email], :name, [:name, :email],
:controller => 'people', controller: 'people',
:default_order => { 'name' => 'desc', :email => 'asc' } default_order: { name: 'desc', email: 'asc' }
) )
} }
it { it {
@ -278,8 +281,8 @@ module Ransack
.sort_link( .sort_link(
[:main_app, Person.search()], [:main_app, Person.search()],
:name, [:name, 'email desc'], :name, [:name, 'email desc'],
:controller => 'people', controller: 'people',
:default_order => { 'name' => 'desc', :email => 'asc' } default_order: { name: 'desc', email: 'asc' }
) )
} }
it { it {
@ -295,7 +298,8 @@ module Ransack
subject { @controller.view_context subject { @controller.view_context
.sort_link( .sort_link(
[:main_app, Note.search()], [:main_app, Note.search()],
:notable_of_Person_type_name, "Notable", :controller => 'notes' :notable_of_Person_type_name, "Notable",
controller: 'notes'
) )
} }
it { it {
@ -313,16 +317,17 @@ module Ransack
context 'view has existing parameters' do context 'view has existing parameters' do
before do before do
@controller.view_context.params.merge!({ :exist => 'existing' }) @controller.view_context.params.merge!({ exist: 'existing' })
end end
describe '#sort_link should not remove existing params' do describe '#sort_link should not remove existing params' do
subject { subject { @controller.view_context
@controller.view_context.sort_link( .sort_link(
Person.search( Person.search(
{ :sorts => ['name desc'] }, :search_key => 'people_search' { sorts: ['name desc'] },
), search_key: 'people_search'
),
:name, :name,
:controller => 'people' controller: 'people'
) )
} }
it { should match /exist\=existing/ } it { should match /exist\=existing/ }
@ -332,10 +337,10 @@ module Ransack
describe '#sort_link with hide order indicator set to true' do describe '#sort_link with hide order indicator set to true' do
subject { @controller.view_context subject { @controller.view_context
.sort_link( .sort_link(
[:main_app, Person.search(:sorts => ['name desc'])], [:main_app, Person.search(sorts: ['name desc'])],
:name, :name,
:controller => 'people', controller: 'people',
:hide_indicator => true hide_indicator: true
) )
} }
it { should match /Full Name/ } it { should match /Full Name/ }
@ -344,24 +349,25 @@ module Ransack
describe '#sort_link with hide order indicator set to false' do describe '#sort_link with hide order indicator set to false' do
subject { @controller.view_context subject { @controller.view_context
.sort_link( .sort_link(
[:main_app, Person.search(:sorts => ['name desc'])], [:main_app, Person.search(sorts: ['name desc'])],
:name, :name,
:controller => 'people', controller: 'people',
:hide_indicator => false hide_indicator: false
) )
} }
it { should match /Full Name ▼/ } it { should match /Full Name ▼/ }
end end
describe '#search_form_for with default format' do describe '#search_form_for with default format' do
subject { @controller.view_context.search_form_for(Person.search) {} } subject { @controller.view_context
.search_form_for(Person.search) {} }
it { should match /action="\/people"/ } it { should match /action="\/people"/ }
end end
describe '#search_form_for with pdf format' do describe '#search_form_for with pdf format' do
subject { subject {
@controller.view_context @controller.view_context
.search_form_for(Person.search, :format => :pdf) {} .search_form_for(Person.search, format: :pdf) {}
} }
it { should match /action="\/people.pdf"/ } it { should match /action="\/people.pdf"/ }
end end
@ -369,14 +375,15 @@ module Ransack
describe '#search_form_for with json format' do describe '#search_form_for with json format' do
subject { subject {
@controller.view_context @controller.view_context
.search_form_for(Person.search, :format => :json) {} .search_form_for(Person.search, format: :json) {}
} }
it { should match /action="\/people.json"/ } it { should match /action="\/people.json"/ }
end end
describe '#search_form_for with an array of routes' do describe '#search_form_for with an array of routes' do
subject { subject {
@controller.view_context.search_form_for([:admin, Comment.search]) {} @controller.view_context
.search_form_for([:admin, Comment.search]) {}
} }
it { should match /action="\/admin\/comments"/ } it { should match /action="\/admin\/comments"/ }
end end