Created
September 9, 2013 17:00
-
-
Save steveburkett/6498470 to your computer and use it in GitHub Desktop.
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
require "spec_helper" | |
module TimeZoneTestHelper | |
def self.included(base) | |
base.extend ClassMethods | |
end | |
module ClassMethods | |
def use_local_time_zone_for_tests | |
self.send :setup, :setup_local_time_zone | |
self.send :teardown, :reset_local_time_zone | |
end | |
end | |
def setup_local_time_zone | |
Time.zone = local_time_zone | |
end | |
def reset_local_time_zone | |
Time.zone = nil | |
end | |
private | |
def local_time_zone | |
ActiveSupport::TimeZone[Time.now.utc_offset] | |
end | |
end | |
describe "the dashboard", :js do | |
include TimeZoneTestHelper | |
let(:organization) { Organization.make!(name: "Test Organization") } | |
let(:user) { User.make!(:account_owner, organization: organization) } | |
let(:location) do | |
Location.make!( | |
organization: organization, | |
name: "Test Location", | |
google_places_score: 40, | |
average_reputation_score: 50 | |
) | |
end | |
let!(:google) { BusinessListing.make!(location: location) } | |
it "has the user's location in the list" do | |
visit_path_and_login_with(new_locations_path, user) | |
expect(page).to have_content("Test Location") | |
expect(page).to have_content(location.contact_info.street) | |
end | |
it "has some organzation metadata" do | |
Review.make!(business_listing: google) | |
visit_path_and_login_with(new_locations_path, user) | |
within(".organization-metadata") do | |
expect(page).to have_content(1) | |
expect(page).to have_content("1 Recent Reviews") | |
end | |
end | |
it "has a clickable google places score" do | |
visit_path_and_login_with(new_locations_path, user) | |
expect(page).to have_content("40%") | |
click_link("40%") | |
expect(current_path).to eq(places_location_scores_path(location_id: location.id)) | |
end | |
it "has a clickable reputation score" do | |
visit_path_and_login_with(new_locations_path, user) | |
expect(page).to have_content("50%") | |
click_link("50%") | |
expect(current_path).to eq(reputation_location_scores_path(location_id: location.id)) | |
end | |
it "has a trend arrow for the reputation score history" do | |
Trend.make!(location: location, business_listing: google, amount: 10, direction: Trend::UP, date: Date.yesterday) | |
visit_path_and_login_with(new_locations_path, user) | |
expect(page).to have_selector(".trend") | |
within(page.all(".trend")[1]) do | |
expect(page).to have_content("10") | |
expect(page).to have_content("2 days") | |
end | |
end | |
describe "export to csv button" do | |
it "displays the export button" do | |
visit_path_and_login_with(new_locations_path, user) | |
expect(page).to have_link("Export All Locations To CSV") | |
end | |
end | |
context "with groups" do | |
let(:location_group) { LocationGroup.make!(organization: organization, name: "Location Group") } | |
before do | |
location.update_attributes!(location_group_id: location_group.id) | |
google = BusinessListing.make!(location: location) | |
Review.make!(business_listing: google) | |
other_location_group = LocationGroup.make!(name: "Other Group", organization: organization) | |
Location.make!(organization: organization, location_group: other_location_group) | |
end | |
context "as an account owner with multiple groups" do | |
it "shows location groups and metadata when they exist" do | |
visit_path_and_login_with(new_locations_path, user) | |
expect(page).to have_content("Location Group") | |
expect(page).to have_no_content("Test Location") | |
within(page.first(".location-group-metadata")) do | |
expect(page).to have_content("(1)") | |
expect(page).to have_content("1 Recent Reviews") | |
end | |
end | |
it "has clickable groups" do | |
visit_path_and_login_with(new_locations_path, user) | |
click_link("Location Group") | |
expect(page).to have_content("Test Location") | |
page.find(".location-detail-vcard a").click | |
expect(current_path).to eq(location_path(location)) | |
end | |
it "allows deep linking to groups and navigation out" do | |
visit_path_and_login_with(new_locations_path + "/group/#{location_group.id}", user) | |
expect(page).to have_content("Test Location") | |
click_link("Back") | |
expect(page).to have_content("Location Group") | |
expect(page).to have_no_content("Test Location") | |
end | |
end | |
context "as a member with access to locations within a single group" do | |
let(:user) { User.make!(:member, organization: organization) } | |
before { LocationAssignment.create!(user: user, location: location) } | |
it "sees the 'My Locations' flat interface" do | |
visit_path_and_login_with(new_locations_path, user) | |
expect(page).to have_no_content("Location Group") | |
expect(page).to have_content("My Locations") | |
expect(page).to have_content("Test Location") | |
end | |
end | |
end | |
context "as an admin" do | |
let(:user) { User.make!(:admin, organization: organization) } | |
before do | |
o = Organization.make!(name: "Second Organization") | |
Location.make!(name: "Second Location", organization: o) | |
end | |
it "can switch to other organizations" do | |
visit_path_and_login_with(new_locations_path, user) | |
expect(page).to have_select( | |
"Organization", | |
options: [ "Test Organization", "Second Organization" ], | |
selected: "Test Organization" | |
) | |
select("Second Organization", from: "Organization") | |
expect(page).to have_no_content("Test Location") | |
expect(page).to have_content("Second Location") | |
expect(page).to have_select("Organization", selected: "Second Organization") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment