Skip to content

Commit

Permalink
fixed some stuff to make some of the tests happy
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Aronson committed Dec 1, 2011
1 parent 6ed0931 commit 0f4b73d
Show file tree
Hide file tree
Showing 47 changed files with 227 additions and 119 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Expand Up @@ -36,14 +36,14 @@ end
gem 'devise'

group :development do
gem 'rspec-rails', '2.6.1'
gem 'rspec-rails'
gem 'sqlite3'
end

group :test do
# Pretty printed test output
gem 'turn', :require => false
gem 'rspec-rails', '2.6.1'
gem 'rspec-rails'
gem 'sqlite3'
gem 'webrat', '0.7.1'
end
Expand Down
45 changes: 22 additions & 23 deletions Gemfile.lock
Expand Up @@ -29,7 +29,7 @@ GEM
activesupport (= 3.1.1)
activesupport (3.1.1)
multi_json (~> 1.0)
ansi (1.4.0)
ansi (1.4.1)
arel (2.2.1)
bcrypt-ruby (3.0.1)
builder (3.0.0)
Expand All @@ -39,27 +39,27 @@ GEM
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.1.2)
devise (1.4.9)
coffee-script-source (1.1.3)
devise (1.5.2)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.0.3)
warden (~> 1.0.3)
warden (~> 1.1)
diff-lcs (1.1.3)
erubis (2.7.0)
execjs (1.2.9)
multi_json (~> 1.0)
hike (1.2.1)
i18n (0.6.0)
jquery-rails (1.0.16)
jquery-rails (1.0.19)
railties (~> 3.0)
thor (~> 0.14)
json (1.6.1)
json (1.6.2)
mail (2.3.0)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.17.2)
multi_json (1.0.3)
multi_json (1.0.4)
nokogiri (1.5.0)
orm_adapter (0.0.5)
pg (0.11.0)
Expand Down Expand Up @@ -91,25 +91,24 @@ GEM
rake (0.9.2.2)
rdoc (3.11)
json (~> 1.4)
rspec (2.6.0)
rspec-core (~> 2.6.0)
rspec-expectations (~> 2.6.0)
rspec-mocks (~> 2.6.0)
rspec-core (2.6.4)
rspec-expectations (2.6.0)
rspec (2.7.0)
rspec-core (~> 2.7.0)
rspec-expectations (~> 2.7.0)
rspec-mocks (~> 2.7.0)
rspec-core (2.7.1)
rspec-expectations (2.7.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.6.0)
rspec-rails (2.6.1)
rspec-mocks (2.7.0)
rspec-rails (2.7.0)
actionpack (~> 3.0)
activesupport (~> 3.0)
railties (~> 3.0)
rspec (~> 2.6.0)
sass (3.1.10)
sass-rails (3.1.4)
rspec (~> 2.7.0)
sass (3.1.11)
sass-rails (3.1.5)
actionpack (~> 3.1.0)
railties (~> 3.1.0)
sass (>= 3.1.4)
sprockets (~> 2.0.0)
sass (~> 3.1.10)
tilt (~> 1.3.2)
sprockets (2.0.3)
hike (~> 1.2)
Expand All @@ -124,10 +123,10 @@ GEM
turn (0.8.3)
ansi
tzinfo (0.3.31)
uglifier (1.0.4)
uglifier (1.1.0)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
warden (1.0.6)
warden (1.1.0)
rack (>= 1.0)
webrat (0.7.1)
nokogiri (>= 1.2.0)
Expand All @@ -143,7 +142,7 @@ DEPENDENCIES
jquery-rails
pg
rails (= 3.1.1)
rspec-rails (= 2.6.1)
rspec-rails
sass-rails (~> 3.1.4)
sqlite3
turn
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/alternatives_controller.rb
Expand Up @@ -22,9 +22,8 @@ def edit
# POST /alternatives.json
def create
@alternative = Alternative.new(params[:alternative])
return if ! can_access @alternative
respond_to do |format|
if @alternative.save
if @alternative && can_access(@alternative) && @alternative.save
format.html { redirect_to @alternative.decision,
notice: 'Alternative was successfully created.' }
format.json { render json: @alternative, status: :created, location: @alternative }
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/decisions_controller.rb
Expand Up @@ -113,7 +113,7 @@ def update
notice: 'Decision was successfully updated.' }
format.json { head :ok }
else
format.html { render action: "show" }
format.html { render action: "edit" }
format.json { render json: @decision.errors, status: :unprocessable_entity }
end
end
Expand Down
5 changes: 2 additions & 3 deletions app/controllers/factors_controller.rb
Expand Up @@ -6,7 +6,7 @@ class FactorsController < ApplicationController
# GET /factors/new.json
def new
@factor = Factor.new
@factor.decision_id = @decision.id
@factor.decision_id = params[:decision_id]
return if ! can_access Decision.find @factor.decision_id
respond_to do |format|
format.html # new.html.erb
Expand All @@ -23,9 +23,8 @@ def edit
# POST /factors.json
def create
@factor = Factor.new(params[:factor])
return if ! can_access @factor
respond_to do |format|
if @factor.save
if @factor && can_access(@factor) && @factor.save
format.html { redirect_to @factor.decision,
notice: 'Factor was successfully created.' }
format.json { render json: @factor, status: :created, location: @factor }
Expand Down
2 changes: 1 addition & 1 deletion app/models/alternative.rb
Expand Up @@ -10,7 +10,7 @@ class Alternative < ActiveRecord::Base


def user_id
decision.user_id
decision ? decision.user_id : nil
end

end
2 changes: 1 addition & 1 deletion app/models/factor.rb
Expand Up @@ -9,7 +9,7 @@ class Factor < ActiveRecord::Base
# :uniqueness => true -- NOT YET, NEED TO SCOPE W/IN DECISION!

def user_id
decision.user_id
decision ? decision.user_id : nil
end

def weight
Expand Down
14 changes: 9 additions & 5 deletions app/views/devise/sessions/new.html.erb
@@ -1,11 +1,15 @@
<h2>Sign in</h2>

<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
<div><%= f.label :username %><br />
<%= f.text_field :username %></div>
<div>
<%= f.label :username %><br />
<%= f.text_field :username %>
</div>

<div><%= f.label :password %><br />
<%= f.password_field :password %></div>
<div>
<%= f.label :password %><br />
<%= f.password_field :password %>
</div>

<% if devise_mapping.rememberable? -%>
<div><%= f.check_box :remember_me %> <%= f.label :remember_me %></div>
Expand All @@ -14,4 +18,4 @@
<div><%= f.submit "Sign in" %></div>
<% end %>
<%= render :partial => "devise/shared/links" %>
<%= render :partial => "devise/shared/links" %>
46 changes: 23 additions & 23 deletions app/views/home/welcome.html.erb
@@ -1,28 +1,28 @@
<div style="margin:20px;text-align:left">
<%= image_tag 'decisionpoints_pb.jpg', align: :left, hspace: '20px' %>

<%= image_tag 'decisionpoints_pb.jpg', align: :left, hspace: '20px' %>
<p>Did you think that George W. Bush was The Decider?</p>

<p>Did you think that George W. Bush was The Decider?</p>
<p>No, THIS is The Decider!</p>

<p>No, THIS is The Decider!</p>
<p>The Decider helps you make rational decisions, based on how the options
rate in various aspects, and how important those aspects are to you.</p>

<p>The Decider helps you make rational decisions, based on how the options
rate in various aspects, and how important those aspects are to you.</p>
<p>This is a very rough prototype. The UI has not been polished at all, and
I am still tweaking the workflow. The main change I have in mind is to have
just a single master Update button on a Decision's screen, and let you
rename it from there.</p>

<p>This is a very rough prototype. The UI has not been polished at all, and
I am still tweaking the workflow. The main change I have in mind is to have
just a single master Update button on a Decision's screen, plus let you
rename it from there.</p>

<p>Other planned features include:</p>
<ul>
<li>Member directory (opt-in), with name and proximity searches
<li>Following people (need not be bidirectional)</li>
<li>Friending people (must be bidirectional)</li>
<li>Making selected decisions visible to your friends, your followers, other members, or even non-members</li>
<li>Seeing various lists of decisions, such as all you can see, just yours, just a given person's, etc.
<li>Copying someone else's decision to your account so you can play with it</li>
<li>Feel free to suggest more!</li>
</ul>

</div>
<p>Other planned features include:</p>
<ul>
<li>Guest account, so you can try it without creating an account
<li>Help
<li>Member directory (opt-in), with name and proximity searches
<li>Following people (need not be bidirectional)</li>
<li>Friending people (must be bidirectional)</li>
<li>Making selected decisions visible to your friends, your followers, other members, or even non-members</li>
<li>Seeing various lists of decisions, such as all you can see, just yours, just a given person's, etc.
<li>Copying someone else's decision to your account so you can play with it</li>
<li>Sending me feedback
<li>More info about me
<li>Feel free to suggest more!</li>
</ul>
13 changes: 10 additions & 3 deletions app/views/layouts/application.html.erb
Expand Up @@ -6,14 +6,21 @@
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<body style="margin:50px">
<div align="center">
<%= render "devise/menu/make_or_edit_registration_links" %> | <%= render "devise/menu/log_in_or_out_links" %>
<%= render "devise/menu/make_or_edit_registration_links" %>
| <%= render "devise/menu/log_in_or_out_links" %>
<h1 align="center"><%=title%></h1>
<% if notice %><h2 class="notice"><%= notice %></h2><% end %>
<% if alert %><h2 class="alert"><%= alert %></h2><% end %>

<%= yield %>
<div class="main">
<%= yield %>
</div>
<br clear="all">
<%= link_to "Author's Web Site", 'http://www.davearonson.com/' %>
| <%= link_to "Author's Code Blog", 'http://www.codosaur.us/' %>
| <%= link_to "Author's Excellence Blog", 'http://www.dare2xl.com/' %>
</div>

</body>
Expand Down
52 changes: 46 additions & 6 deletions spec/controllers/alternatives_controller_spec.rb
Expand Up @@ -2,6 +2,46 @@

describe AlternativesController do

# TODO: make the below stuff into fixtures?

valid_user_attributes = {
username: 'dave', # so it will be an admin
password: 'testing',
realname: 'Fester Bestertester',
email: 'fester@bestertester.org'
}

User.create valid_user_attributes
@user = User.find_by_username valid_user_attributes[:username]

valid_login_attributes = {
username: valid_user_attributes[:username],
password: valid_user_attributes[:password],
}

valid_decision_attributes = {
name: 'what name to use',
user_id: @user.id
}

Decision.create valid_decision_attributes
@decision = Decision.find_by_name valid_decision_attributes[:name]

valid_alternative_attributes = {
name: 'blargh',
decision_id: @decision.id
}
valid_attributes = valid_alternative_attributes

Alternative.create valid_alternative_attributes
@alternative = Alternative.find_by_name valid_alternative_attributes[:name]

before :each do
@user = User.find_by_username valid_user_attributes[:username]
sign_in @user
end


describe "GET edit" do
it "assigns the requested alternative as @alternative" do
alternative = Alternative.create! valid_attributes
Expand All @@ -24,9 +64,9 @@
assigns(:alternative).should be_persisted
end

it "redirects to the created alternative" do
it "redirects to the created alternative's decision" do
post :create, :alternative => valid_attributes
response.should redirect_to(Alternative.last)
response.should redirect_to(Decision.find valid_attributes[:decision_id])
end
end

Expand Down Expand Up @@ -65,10 +105,10 @@
assigns(:alternative).should eq(alternative)
end

it "redirects to the alternative" do
it "redirects to the decision" do
alternative = Alternative.create! valid_attributes
put :update, :id => alternative.id, :alternative => valid_attributes
response.should redirect_to(alternative)
response.should redirect_to(alternative.decision)
end
end

Expand Down Expand Up @@ -99,10 +139,10 @@
}.to change(Alternative, :count).by(-1)
end

it "redirects to the alternatives list" do
it "redirects to the decision" do
alternative = Alternative.create! valid_attributes
delete :destroy, :id => alternative.id.to_s
response.should redirect_to(alternatives_url)
response.should redirect_to(alternative.decision)
end
end

Expand Down

0 comments on commit 0f4b73d

Please sign in to comment.