This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it 'returns users with member privileges only' do | |
member = create(:user, :with_member_privilege) | |
create(:user, :with_admin_privilege) | |
create(:user, :with_member_privilege, :with_admin_privilege) | |
result = MembersOnlyQuery.call | |
expect(result).to match([member]) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it 'returns users with member privileges only' do | |
member_privilege = create(:privilege, :member) | |
admin_privilege = create(:privilege, :member) | |
member = create(:user) | |
admin = create(:user) | |
member_and_admin = create(:user) | |
create(:access_rule, user: member, privilege: member_privilege) | |
create(:access_rule, user: admin, privilege: admin_privilege) | |
create(:access_rule, user: member_and_admin, privilege: member_privilege) | |
create(:access_rule, user: member_and_admin, privilege: admin_privilege) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it 'returns accounts expired in last week' do | |
account_1 = create(:account, expiry_date: 1.day.ago) | |
account_2 = create(:account, expiry_date: 7.days.ago) | |
result = RecentlyExpiredAccountsQuery.call | |
expect(result).to match_array([account_1, account_2]) | |
end | |
it 'does not return accounts expiring in the future' do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it 'returns accounts expired in last week' do | |
create(:account, expiry_date: 1.day.from_now) | |
create(:account, expiry_date: Date.current) | |
account_1 = create(:account, expiry_date: 1.day.ago) | |
account_2 = create(:account, expiry_date: 7.days.ago) | |
create(:account, expiry_date: 8.days.ago) | |
result = RecentlyExpiredAccountsQuery.call | |
expect(result).to match_array([account_1, account_2]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
expect(OMDBClient).to receive(:get_movie).with(t: 'The Rock') { | |
{ | |
"Title" => "The Rock", | |
"Year" => "1996", | |
"Rated" => "R", | |
"Released" => "07 Jun 1996", | |
"Runtime" => "136 min", | |
"Genre" => "Action, Adventure, Thriller" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
allow(OMDBClient).to receive(:get_movie) { | |
{ | |
"Title" => "The Rock", | |
"Year" => "1996", | |
"Rated" => "R", | |
"Released" => "07 Jun 1996", | |
"Runtime" => "136 min", | |
"Genre" => "Action, Adventure, Thriller" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
allow(UserNotifier).to receive(:deletion_notification) | |
DestroyUser.call(user) | |
expect(UserNotifier).to have_received(:deletion_notification).with(user, delay: 5.minutes) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
expect(result).to match_array( | |
[ | |
be_a_kind_of(User::Member).and(have_attributes(name: ‘Tony’)), | |
be_a_kind_of(User::Admin).and(have_attributes(name: ‘Mike’)) | |
] | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OMDBClient | |
HOST_URL = 'www.omdbapi.com' | |
# http://www.omdbapi.com/ | |
def get_movie(args = {}) | |
uri = URI::HTTP.build( | |
host: HOST_URL, | |
query: { | |
apikey: ENV.fetch('OMDB_API_KEY') | |
}.merge(args).to_query |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Feature specs are used to test validation and authorization details, when those | |
# should be handled in faster, lower level specs (i.e. model & controller specs) | |
RSpec.describe 'Properties management', type: :feature do | |
scenario 'Admin creates a property' | |
scenario 'Admin attempts to create a property with missing name' | |
scenario 'Admin attempts to create a property with name which is too short' | |
scenario 'Admin attempts to create a property with duplicate name' | |
scenario 'Guest attempts to create a property' | |
scenario 'Regular user attempts to create a property' | |
end |