Adding tables
This commit is contained in:
parent
73edbc369c
commit
32194b11b9
29
app/assets/javascripts/components/seat.js.jsx
Normal file
29
app/assets/javascripts/components/seat.js.jsx
Normal 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>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
39
app/assets/javascripts/components/table.js.jsx
Normal file
39
app/assets/javascripts/components/table.js.jsx
Normal 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>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -1,6 +1,8 @@
|
|||||||
class TablesController < ApplicationController
|
class TablesController < ApplicationController
|
||||||
before_action :set_table, only: [:show, :edit, :update, :destroy]
|
before_action :set_table, only: [:show, :edit, :update, :destroy]
|
||||||
|
|
||||||
|
respond_to :html, :json
|
||||||
|
|
||||||
# GET /tables
|
# GET /tables
|
||||||
# GET /tables.json
|
# GET /tables.json
|
||||||
def index
|
def index
|
||||||
|
|||||||
1
app/views/tables/show.json.jbuilder
Normal file
1
app/views/tables/show.json.jbuilder
Normal file
@ -0,0 +1 @@
|
|||||||
|
json.extract! @table, :id, :title, :created_at, :updated_at
|
||||||
@ -1,6 +1,9 @@
|
|||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
resources :players
|
resources :players
|
||||||
resources :tables
|
resources :tables do
|
||||||
|
resources :seats
|
||||||
|
resources :games
|
||||||
|
end
|
||||||
|
|
||||||
resources :games do
|
resources :games do
|
||||||
member do
|
member do
|
||||||
|
|||||||
41
spec/features/tables/table_join_spec.rb
Normal file
41
spec/features/tables/table_join_spec.rb
Normal 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
|
||||||
Loading…
x
Reference in New Issue
Block a user