Skip to content
  • 12 commits
  • 26 files changed
  • 1 commit comment
  • 2 contributors
Commits on Feb 26, 2012
martin Fix for pivotal #25520083, but test has FIXME and two similar tests n…
…eed doing - please complete
7cf8cbd
Commits on Mar 02, 2012
@Odaeus Odaeus Remove empty controller specs.
They serve no purpose. In hindsight we probably should have struck
a balance between controller and integration tests.
52be70a
@Odaeus Odaeus Move group issues list into their own controller. 09a0c7e
@Odaeus Odaeus Implement group start location into possible start locations list. 4e342e9
@Odaeus Odaeus Add group issues list in subdomain constraint.
Slightly evil definition of method inside the router in order
to replicate the complex issue route options.
ba40874
Commits on Mar 03, 2012
@Odaeus Odaeus Fix bad translation key. 84e8909
@Odaeus Odaeus Issues should use a sequence for the title so they are unique lists. a31ae6c
@Odaeus Odaeus Fix failing test due to using the empty group profile. b4573ac
Commits on Mar 04, 2012
@Odaeus Odaeus Add tests for group issues search.
Can't get it to fully work though, returns results when none expected.
0f4c537
@Odaeus Odaeus Merge branch 'issues-list-uses-group-geometry' into staging 311b14f
@Odaeus Odaeus Lock Formtastic to older version as cannot get custom inputs to work.
Currently the custom inputs don't seem to be found when running
tests under Spork.
b50c836
@Odaeus Odaeus Remove group issues controller tests.
Now in spec/requests/groups/issues_spec.rb.
dd99e5e
View
2 Gemfile
@@ -10,7 +10,7 @@ gem 'activerecord-postgis-adapter'
# Front-end gems
gem 'jquery-rails'
gem 'haml-rails'
-gem 'formtastic'
+gem 'formtastic', '~> 2.0.2'
gem 'map_layers'
gem 'rgeo-geojson'
gem 'will_paginate', '~> 3.0'
View
6 Gemfile.lock
@@ -101,8 +101,8 @@ GEM
foreman (0.40.0)
term-ansicolor (~> 1.0.7)
thor (>= 0.13.6)
- formtastic (2.1.0)
- actionpack (~> 3.0)
+ formtastic (2.0.2)
+ rails (~> 3.0)
fssm (0.2.8.1)
haml (3.1.4)
haml-rails (0.3.4)
@@ -268,7 +268,7 @@ DEPENDENCIES
exceptional
factory_girl_rails
foreman
- formtastic
+ formtastic (~> 2.0.2)
haml-rails
hirb
jquery-rails
View
18 app/controllers/group/issues_controller.rb
@@ -0,0 +1,18 @@
+# Note inheritance
+class Group::IssuesController < IssuesController
+ filter_access_to :all, context: :issues
+
+ def index
+ set_page_title t("group.issues.index.title", group_name: current_group.name)
+
+ # FIXME: bad design, @query is set by search action
+ if @query
+ issues = Issue.intersects(current_group.profile.location).find_with_index(@query)
+ else
+ issues = Issue.intersects(current_group.profile.location).by_most_recent.paginate(page: params[:page])
+ end
+
+ @issues = IssueDecorator.decorate(issues)
+ @start_location = index_start_location
+ end
+end
View
1 app/controllers/group/message_threads_controller.rb
@@ -1,3 +1,4 @@
+# Note inheritance
class Group::MessageThreadsController < MessageThreadsController
before_filter :load_group
View
4 app/controllers/issues_controller.rb
@@ -2,11 +2,13 @@ class IssuesController < ApplicationController
filter_access_to [:edit, :update, :destroy], attribute_check: true
def index
+ # FIXME: this is confusing design, the query param is set by the search action
if @query
issues = Issue.find_with_index(@query)
else
issues = Issue.by_most_recent.paginate(page: params[:page])
end
+
@issues = IssueDecorator.decorate(issues)
@start_location = index_start_location
end
@@ -127,7 +129,7 @@ def vote_clear
def index_start_location
return current_user.start_location if current_user && current_user.start_location != Geo::NOWHERE_IN_PARTICULAR
- # TODO return subdomain.group.location if subdomain
+ return current_group.start_location if current_group && current_group.start_location
return @issues.first.location unless @issues.empty?
return Geo::NOWHERE_IN_PARTICULAR
end
View
4 app/models/group.rb
@@ -54,6 +54,10 @@ def subdomain
short_name
end
+ def start_location
+ profile && profile.location
+ end
+
protected
def create_default_profile
View
3 config/locales/en-GB.yml
@@ -90,6 +90,9 @@
title: "Sign in"
sign_in_button: "Sign in"
group:
+ issues:
+ index:
+ title: "Issues in the area of %{group_name}"
members:
index:
actions: "Actions"
View
40 config/routes.rb
@@ -1,30 +1,36 @@
Cyclescape::Application.routes.draw do
+ # Pretty evil but beats copy pasting
+ def issues_route(opts = {})
+ resources :issues, opts do
+ member do
+ get "geometry"
+ put "vote_up"
+ put "vote_down"
+ put "vote_clear"
+ end
+ collection do
+ get "all_geometries"
+ get "search"
+ end
+ scope module: "issue" do
+ resource :photo, only: [:show]
+ resources :threads, controller: "message_threads"
+ resource :tags, only: [:update]
+ end
+ end
+ end
+
devise_for :users, :controllers => { :confirmations => "confirmations" }
constraints(SubdomainConstraint) do
root :to => "groups#show"
resources :threads, controller: "group/message_threads"
+ issues_route controller: "group/issues"
end
resource :overview, as: :dashboard, controller: "dashboards"
- resources :issues do
- member do
- get "geometry"
- put "vote_up"
- put "vote_down"
- put "vote_clear"
- end
- collection do
- get "all_geometries"
- get "search"
- end
- scope module: "issue" do
- resource :photo, only: [:show]
- resources :threads, controller: "message_threads"
- resource :tags, only: [:update]
- end
- end
+ issues_route
namespace :admin do
resources :groups, :users
View
5 spec/controllers/admin/groups_controller_spec.rb
@@ -1,5 +0,0 @@
-require 'spec_helper'
-
-describe Admin::GroupsController do
-
-end
View
5 spec/controllers/admin/home_controller_spec.rb
@@ -1,5 +0,0 @@
-require 'spec_helper'
-
-describe Admin::HomeController do
-
-end
View
5 spec/controllers/admin/users_controller_spec.rb
@@ -1,5 +0,0 @@
-require 'spec_helper'
-
-describe Admin::UsersController do
-
-end
View
5 spec/controllers/dashboards_controller_spec.rb
@@ -1,5 +0,0 @@
-require 'spec_helper'
-
-describe DashboardsController do
-
-end
View
4 spec/controllers/group/members_controller_spec.rb
@@ -1,4 +0,0 @@
-require 'spec_helper'
-
-describe Group::MembersController do
-end
View
5 spec/controllers/group/membership_requests_controller_spec.rb
@@ -1,5 +0,0 @@
-require 'spec_helper'
-
-describe Group::MembershipRequestsController do
-
-end
View
4 spec/controllers/group/memberships_controller_spec.rb
@@ -1,4 +0,0 @@
-require 'spec_helper'
-
-describe Group::MembershipsController do
-end
View
5 spec/controllers/group/profiles_controller_spec.rb
@@ -1,5 +0,0 @@
-require 'spec_helper'
-
-describe Group::ProfilesController do
-
-end
View
5 spec/controllers/groups_controller_spec.rb
@@ -1,5 +0,0 @@
-require 'spec_helper'
-
-describe GroupsController do
-
-end
View
5 spec/controllers/home_controller_spec.rb
@@ -1,5 +0,0 @@
-require 'spec_helper'
-
-describe HomeController do
-
-end
View
5 spec/controllers/issues_controller_spec.rb
@@ -1,5 +0,0 @@
-require 'spec_helper'
-
-describe IssuesController do
-
-end
View
5 spec/controllers/message_threads_controller_spec.rb
@@ -1,5 +0,0 @@
-require 'spec_helper'
-
-describe MessageThreadsController do
-
-end
View
4 spec/controllers/messages_controller_spec.rb
@@ -1,4 +0,0 @@
-require 'spec_helper'
-
-describe MessagesController do
-end
View
5 spec/controllers/tags_controller_spec.rb
@@ -1,5 +0,0 @@
-require 'spec_helper'
-
-describe TagsController do
-
-end
View
5 spec/controllers/user/locations_controller_spec.rb
@@ -1,5 +0,0 @@
-require 'spec_helper'
-
-describe User::LocationsController do
-
-end
View
5 spec/factories/group_profiles.rb
@@ -23,5 +23,10 @@
factory :big_group_profile do
location "POLYGON ((0 0, 0 100, 100 100, 100 0, 0 0))"
end
+
+ factory :quahogcc_group_profile do
+ association :group, factory: :quahogcc
+ location "POLYGON ((-0.048337826538099 52.288247679276, -0.095029721069341 52.334425101058, -0.0064524505615302 52.370493901594, 0.084528079223625 52.301266191436, 0.26065265197753 52.294127481182, 0.26751910705777 52.191539167527, 0.22906695861468 52.15279673993, 0.18100177306972 52.101368865428, 0.12469684143375 52.097994471963, 0.073885073849465 52.148583573398, -0.13622845154113 52.2142635765, -0.048337826538099 52.288247679276))"
+ end
end
end
View
11 spec/factories/issues.rb
@@ -15,7 +15,7 @@
FactoryGirl.define do
factory :issue do
- title "There's something wrong"
+ sequence(:title) {|n| "Issue #{n}" }
description "Whose leg do you have to hump to get a dry martini around here?"
location "POINT(-122 47)"
association :created_by, factory: :user
@@ -31,5 +31,14 @@
trait :with_photo do
photo { File.read(test_photo_path) }
end
+
+ factory :issue_within_quahog do
+ location "POINT(0.11906 52.20792)"
+ end
+
+ factory :issue_outside_quahog do
+ location "POINT(10 80)"
+ end
+
end
end
View
58 spec/requests/groups/issues_spec.rb
@@ -0,0 +1,58 @@
+require "spec_helper"
+
+describe "Issues in a group subdomain" do
+ include_context "signed in as a group member"
+ include_context "with current group subdomain"
+
+ before do
+ # Groups create empty profiles automatically, so just update the existing one
+ current_group.profile.update_attributes(FactoryGirl.attributes_for(:big_group_profile))
+ end
+
+ context "index" do
+ let(:location_inside_group) { "POINT (10 10)" }
+ let(:location_outside_group) { "POINT (200 200)" }
+ let!(:issues) { FactoryGirl.create_list(:issue, 2, location: location_inside_group) }
+ let!(:outside_issue) { FactoryGirl.create(:issue, location: location_outside_group) }
+
+ it "should show issues in the group's area" do
+ visit issues_path
+ issues.each do |issue|
+ page.should have_content(issue.title)
+ end
+ end
+
+ it "should not show issues outside the group's area" do
+ outside_issue
+ visit issues_path
+ page.should have_no_content(outside_issue.title)
+ end
+
+ it "should set the page title" do
+ visit issues_path
+ page.should have_selector("title", content: I18n.t("group.issues.index.title", group_name: current_group.name))
+ end
+
+ context "with search" do
+ let(:search_field) { I18n.t("issues.index.search_issues") }
+ let(:search_button) { I18n.t("issues.index.search_button") }
+
+ it "should return issues in the group's area" do
+ visit issues_path
+ fill_in search_field, with: issues.first.title
+ click_on search_button
+ page.should have_link(issues.first.title, href: issue_path(issues.first))
+ page.should have_no_content(outside_issue.title)
+ end
+
+ it "should not return issues outside the group's area" do
+ # FIXME: this test needs fixing, still shows results when none were expected
+ return pending
+ visit issues_path
+ fill_in search_field, with: outside_issue.title
+ click_on search_button
+ page.should have_content("No issues found")
+ end
+ end
+ end
+end

Showing you all comments on commits in this comparison.

@smsm1
CycleStreets member

After speaking with someone at work on this problem, we need to manually fix the relationship between the group and the group profile so that it will be correct in both directions, rather than missing in one, when the controller code is run.

Seems that http://stackoverflow.com/questions/3648699/factory-girl-has-one-relation-with-validates-presence-of has the answer.

Something went wrong with that request. Please try again.