Skip to content

Commit

Permalink
[ci] Add rspec test for project watchlist
Browse files Browse the repository at this point in the history
* Migrate project watchlist tests to rspec test suite
* Fix caching issue that appears when changing watched projects within a second,
  first found in 82e3407...
  • Loading branch information
bgeuken committed Feb 17, 2016
1 parent 5f273a9 commit 8c72947
Show file tree
Hide file tree
Showing 6 changed files with 599 additions and 16 deletions.
12 changes: 9 additions & 3 deletions src/api/app/models/user.rb
Expand Up @@ -916,19 +916,25 @@ def self.realname_for_login(person)
end

def watched_project_names
@watched_projects ||= Rails.cache.fetch(['watched_project_names', self]) do
Rails.cache.fetch(['watched_project_names', self]) do
Project.where(id: watched_projects.pluck(:project_id)).pluck(:name).sort
end
end

def add_watched_project(name)
watched_projects.create(project: Project.find_by_name!(name))
self.touch
clear_watched_projects_cache
end

def remove_watched_project(name)
watched_projects.joins(:project).where(projects: { name: name }).delete_all
self.touch
clear_watched_projects_cache
end

# Needed to clear cache even when user's updated_at timestamp did not change,
# aka. changes within the same second. Mainly an issue when in our test suite
def clear_watched_projects_cache
Rails.cache.delete(['watched_project_names', self])
end

def watches?(name)
Expand Down
299 changes: 299 additions & 0 deletions src/api/spec/cassettes/Watchlists/add_projects_to_watchlist.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8c72947

Please sign in to comment.