Permalink
Browse files

All tests would pass, but @javascript in

 features/equipment_stats_new.feature is breaking it.
Run without this test or remove @javascript from that test to see others
pass.
  • Loading branch information...
Alex Berry
Alex Berry committed Apr 27, 2012
1 parent 0cab44b commit f78ac64aea2389aa26b76e5d94c58650e9cac341
Binary file not shown.
@@ -1,11 +1,26 @@
class AdminsEquipmentsStatsController < ApplicationController
+ respond_to :json
+
def new
@equipment = Equipment.find(params[:equipment_id])
@stats = Stat.all
@equipment_stat = EquipmentStat.all
end
def create
+ @equipment_stat = EquipmentStat.create(params[:equipment_stat])
+ @equipment = @equipment_stat.equipment
+ response_hash = { :equipment_stat => @equipment_stat,
+ :equipment => @equipment }
+ respond_with response_hash, :location => nil
+ end
+ def update
+ @equipment_stat = EquipmentStat.find(params[:equipment_stat][:id])
+ @equipment_stat.update_attributes(params[:equipment_stat])
+ @equipment = @equipment_stat.equipment
+ response_hash = { :equipment_stat => @equipment_stat,
+ :equipment => @equipment }
+ render json: response_hash
end
end
@@ -1,4 +1,7 @@
class EquipmentStat < ActiveRecord::Base
+ # Assignment
+ attr_accessible :stat_id, :equipment_id, :modifier
+
# Associations
belongs_to :stat
belongs_to :equipment
@@ -19,22 +19,79 @@
<th>Cost</th>
<th></th>
</tr>
-<tr data-role="edit-equipment_attributes">
- <td><%= select_tag "stats", options_from_collection_for_select(@stats, :id, :name) %></td>
- <td><%= number_field_tag :modifier, 0, :in => -100...100 %></td>
+<tr data-role="edit_equipment_attributes">
+ <td><%= select_tag "stat_id", options_from_collection_for_select(@stats, :id, :name), id: 'edit_equipment_stat_stat' %></td>
+ <td><%= number_field_tag 'modifier', 0, :in => -100...100, id: 'edit_equipment_stat_modifier' %></td>
<td data-for="price"></td>
- <td><button>Save</button></td>
+ <td><button id="edit_equipment_stat_submit">Save</button></td>
</tr>
</table>
-<%= form_tag new_admin_equipment_stat_path(@equipment), method: :post,
- remote: true, id: :new_stat_form do %>
- <%= hidden_field_tag :stat_id %>
- <%= hidden_field_tag :modifier %>
+<%= form_tag admin_equipment_stats_path(@equipment), method: :post,
+ remote: true, id: :new_equipment_stat_form do %>
+ <%= hidden_field_tag 'equipment_stat[stat_id]', '', id: :new_equipment_stat_stat %>
+ <%= hidden_field_tag 'equipment_stat[modifier]', '', id: :new_equipment_stat_modifier %>
+ <%= hidden_field_tag 'equipment_stat[equipment_id]', @equipment.id %>
<% end %>
<%= form_tag edit_admin_equipment_stat_path(@equipment), method: :put,
- remote: true, id: :update_stat_form do %>
- <%= hidden_field_tag :stat_id %>
- <%= hidden_field_tag :modifier %>
+ remote: true, id: :update_equipment_stat_form do %>
+ <%= hidden_field_tag 'equipment_stat[stat_id]', '', id: :update_equipment_stat_stat %>
+ <%= hidden_field_tag 'equipment_stat[modifier]', '', id: :update_equipment_stat_modifier %>
+ <%= hidden_field_tag 'equipment_stat[equipment_id]', @equipment.id %>
+ <%= hidden_field_tag 'equipment_stat_id', '', id: :update_equipment_stat_id %>
<% end %>
-
</section>
+<script>
+ jQuery(function($) {
+ $s = {}
+ $s['input_row'] = $("tr[data-role=edit_equipment_attributes]")
+ $s['input_stat'] = $("#edit_equipment_stat_stat")
+ $s['input_modifier'] = $("#edit_equipment_stat_modifier")
+ $s['input_submit'] = $("#edit_equipment_stat_submit")
+
+ $s['new_form'] = $("#new_equipment_stat_form")
+ $s['new_stat'] = $("#new_equipment_stat_stat")
+ $s['new_modifier'] = $("#new_equipment_stat_modifier")
+
+ test_selectors($s, {verbose: false})
+
+ $s['new_form'].bind("ajax:success", receive_new_equipment_stat)
+ $s['input_submit'].click(send_new_equipment_stat)
+
+ function send_new_equipment_stat(){
+ $s['new_stat'].val($s['input_stat'].val());
+ $s['new_modifier'].val($s['input_modifier'].val());
+ $s['new_form'].submit()
+ }
+ function receive_new_equipment_stat(event, data){
+ console.log(data)
+ $('<tr data-equipment_stat="' + data.equipment_stat.id + '">'+
+ '<td data-role="stat">' + data.equipment_stat.stat_id + '</td>'+
+ '<td data-role="modifier">' + data.equipment_stat.modifier + '</td>'+
+ '<td data-role="price"></td>'+
+ '</tr>').insertBefore($s['input_row']);
+ }
+ function send_update_equipement_stat(){
+
+ }
+ function receive_update_equipment_stat(){
+
+ }
+ function test_selectors(selectors, options){
+ var defaults = {
+ verbose: false
+ }
+ var settings = $.extend(defaults, options)
+
+ console.log("Begin Selector Tests")
+ for(i in selectors){
+ if(selectors[i].length == 0){
+ console.log("Selector Test Failed: " + i)
+ }else{
+ if(settings.verbose){
+ console.log("Passed: " + i)
+ }
+ }
+ }
+ }
+ });
+</script>
View
@@ -1,4 +1,3 @@
-# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
Chassis.delete_all
Chassis.create([
{name: 'Large'}, {name: 'Medium'}, {name: 'Small'}
@@ -3,9 +3,10 @@ Feature: Add Stats to Equipment
I want to add new stats to a piece of equipment
So that is has a value in the game
+ @javascript
Scenario: Add Stats to a Feature
Given I am signed in as an admin
And an equipment exists
And I visit the admin equipment stats page
Then I add stats to the equipment
- And I see the equipment
+ And I see the equipment with an updated price
@@ -3,5 +3,15 @@
end
Then /^I add stats to the equipment$/ do
- page.should have_css(table[data-role='
+ within("tr[data-role=edit_equipment_attributes]") do
+ select :health, from: 'edit_equipment_stat_stat'
+ fill_in 'edit_equipment_stat_modifier', with: '1'
+ page.should have_css('td[data-for=price]')
+ click_button "Save"
+ end
+end
+
+Then /^I see the equipment with an updated price$/ do
+ equipment_stat = EquipmentStat.first
+ page.should have_css("tr[data-equipment_stat='#{equipment_stat.id}']")
end
@@ -1,6 +1,7 @@
Given /^I create a robot$/ do
click_link "Create a Robot"
fill_in( "Robot name", with: "Robbie")
+ save_and_open_page
select("Medium", from: "Chassis")
click_button( "Deployz!!" )
end
View
@@ -9,7 +9,7 @@
ActionController::Base.allow_rescue = false
begin
- DatabaseCleaner.strategy = :transaction
+ #DatabaseCleaner.strategy = :transaction
rescue NameError
raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end
@@ -1,3 +1,10 @@
+require 'spec_helper'
+require 'helpers/helper'
+
+RSpec.configure do |c|
+ c.include Helpers
+end
+
describe AdminsEquipmentsStatsController do
context "JSON" do
describe "POST new" do
@@ -7,21 +14,38 @@
end
it "creates a new equipment_stat" do
- json = { :format => 'json', :application => { :stat => @stat.id, :modifier => 2 } }
+ json = { :format => 'json', :equipment_stat =>
+ { :equipment_id => @equipment.id, :stat_id => @stat.id, :modifier => 2 } }
+
post :create, json
+
+ json = response_json
+ json.should include 'equipment'
+ json.should include 'equipment_stat'
+ json.should_not include 'error'
end
end
describe "PUT update" do
+ before do
+ @equipment = create :equipment
+ @stat = create :stat
+ @equipment_stat = create :equipment_stat, :equipment => @equipment, :stat => @stat
+ end
- end
- end
-end
- json = response_json
- assert json['error'].present?
+ it "updates an existing equipment_stat" do
+ json = { :format => 'json', :equipment_stat =>
+ { :id => @equipment_stat.id, :equipment_id => @equipment.id,
+ :stat_id => @stat.id, :modifier => 4 } }
- module Helpers
- def response_json
- ActiveSupport::JSON.decode @response.body
+ put :update, json
+
+ json = response_json
+ json.should include 'equipment'
+ json.should include 'equipment_stat'
+ json.should_not include 'error'
+ json['equipment_stat']['modifier'].should == 4
end
end
+ end
+end
@@ -1,5 +0,0 @@
-require 'spec_helper'
-
-describe RobotsController do
-
-end
View
@@ -0,0 +1,5 @@
+module Helpers
+ def response_json
+ ActiveSupport::JSON.decode @response.body
+ end
+end
@@ -5,6 +5,11 @@
it { should have_db_column(:created_at) }
it { should have_db_column(:updated_at) }
+ # Assignment
+ it{ should allow_mass_assignment_of(:stat_id) }
+ it{ should allow_mass_assignment_of(:equipment_id) }
+ it{ should allow_mass_assignment_of(:modifier) }
+
# Associations
it{ should belong_to(:stat) }
it{ should belong_to(:equipment) }

0 comments on commit f78ac64

Please sign in to comment.