Adding tables

This commit is contained in:
Jesse C. Fisher 2016-02-09 04:02:24 -08:00
parent 73edbc369c
commit 32194b11b9
7 changed files with 116 additions and 1 deletions

View File

@ -0,0 +1,29 @@
var Seat = React.createClass({
onClick: function(e) {
// TODO: Sit at table
$.ajax({
url: window.location.pathname + '/sit',
type: 'POST',
dataType: 'json',
complete: function (jqXHR, textStatus) {
// callback
},
success: function (data, textStatus, jqXHR) {
// success callback
},
error: function (jqXHR, textStatus, errorThrown) {
// error callback
}
});
},
render: function() {
return (
<button onClick={this.onClick}>
Sit
</button>
);
}
});

View File

@ -0,0 +1,39 @@
var Table = React.createClass({
// TODO: Declare all propTypes
propTypes: {
title: React.PropTypes.string,
id: React.PropTypes.number,
url: React.PropTypes.string
},
getInitialState: function() {
return {
data: null,
id: "",
title: ""
};
},
componentDidMount: function() {
$.getJSON(this.props.url, function(result) {
if (this.isMounted()) {
this.setState({ data: result });
}
}.bind(this));
},
render: function() {
if (!this.state.data) {
return <div>Loading...</div>;
}
return (
<div id={"table-" + this.state.data.id}>
<h1>{this.state.data.title}</h1>
<Seat />
<Seat />
<Seat />
<Seat />
</div>
);
}
});

View File

@ -1,6 +1,8 @@
class TablesController < ApplicationController
before_action :set_table, only: [:show, :edit, :update, :destroy]
respond_to :html, :json
# GET /tables
# GET /tables.json
def index

View File

@ -0,0 +1 @@
json.extract! @table, :id, :title, :created_at, :updated_at

View File

@ -1,6 +1,9 @@
Rails.application.routes.draw do
resources :players
resources :tables
resources :tables do
resources :seats
resources :games
end
resources :games do
member do

View File

@ -0,0 +1,41 @@
# Feature: Table show
# As a visitor
# I want to view a table
# So I can sit and play a game
feature 'Table show', :devise do
context "As a visitor" do
before(:each) do
@table = FactoryGirl.create :table
visit tables_path
click_link @table.title
end
# Scenario: Visitor can view a table
# Given I am not signed in
# When I visit a table
# Then I see the table attributes
scenario 'visitor can see the table', js: true do
expect(page).to have_selector "#table-#{@table.id} > h1", @table.title
end
scenario 'visitor can sit at the table', js: true do
click_button 'Sit'
expect(page).to have_content "Guest"
end
end
context "As a user" do
# Scenario: User can view a table
# Given I am signed in
# When I click a table
# Then I see an index of tables
scenario 'visitor can see the table', js: true do
@table = FactoryGirl.create :table
# TODO: sign in
visit tables_path
click_link @table.title
expect(page).to have_button "Sit"
expect(page).to have_selector "#table-#{@table.id} > .title", @table.title
expect(current_path).to eq table_path(@table)
end
end
end