Merge pull request #65 from ENSL/develop

Develop
This commit is contained in:
simplefl 2015-10-28 18:12:31 +01:00
commit f07670850d
6 changed files with 112 additions and 876 deletions

View file

@ -1,2 +1,2 @@
ruby: ruby:
config/styles/ruby.yml config_file: config/styles/ruby.yml

View file

@ -4,7 +4,19 @@ class Api::V1::UsersController < Api::V1::BaseController
end end
def show def show
if params[:format].nil? || params[:format] == "id"
@user = User.find(params[:id]) @user = User.find(params[:id])
elsif params[:format] == "steamid"
steamid_i = params[:id].to_i
@user = User.first(conditions: { steamid: format("0:%d:%d", steamid_i % 2, steamid_i >> 1) })
elsif params[:format] == "steamidstr"
@user = User.first(conditions: { steamid: params[:id] })
end
if @user.nil?
raise ActionController::RoutingError.new("User Not Found")
end
if @user.steamid.present? if @user.steamid.present?
@steam = steam_profile @user @steam = steam_profile @user
end end
@ -16,6 +28,8 @@ class Api::V1::UsersController < Api::V1::BaseController
time_zone: @user.time_zone, time_zone: @user.time_zone,
avatar: @user.profile.avatar.url, avatar: @user.profile.avatar.url,
admin: @user.admin?, admin: @user.admin?,
referee: @user.ref?,
caster: @user.caster?,
moderator: @user.gather_moderator?, moderator: @user.gather_moderator?,
steam: @user.steamid.nil? ? nil : { steam: @user.steamid.nil? ? nil : {
id: @user.steamid, id: @user.steamid,
@ -30,7 +44,7 @@ class Api::V1::UsersController < Api::V1::BaseController
team: @user.team.present? ? { id: @user.team.id, name: @user.team.name } : nil team: @user.team.present? ? { id: @user.team.id, name: @user.team.name } : nil
} }
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
raise ActionController::RoutingError.new('User Not Found') raise ActionController::RoutingError.new("User Not Found")
end end
private private

14
app/views/users/_general.html.erb Normal file → Executable file
View file

@ -4,10 +4,18 @@
<dl> <dl>
<dt>Age</dt> <dt>Age</dt>
<dd><%= @user.age %></dd> <dd><%= @user.age %></dd>
<% if !@user.country.blank? %>
<dt>Country</dt> <dt>Country</dt>
<dd><%= @user.country %></dd> <dd><%= @user.country %></dd>
<% end %>
<% if !@user.profile.town.blank? %>
<dt>Town</dt> <dt>Town</dt>
<dd><%= @user.profile.town %></dd> <dd><%= @user.profile.town %></dd>
<% end %>
<% if !@user.steamid.blank? %>
<dt>SteamID</dt> <dt>SteamID</dt>
<dd> <dd>
<p><%= @user.steamid %></p> <p><%= @user.steamid %></p>
@ -15,9 +23,13 @@
<%= link_to "Search for Steam Account" %> <%= link_to "Search for Steam Account" %>
</div> </div>
</dd> </dd>
<% end %>
<% if !@user.profile.stream.blank? %>
<dt>Stream</dt> <dt>Stream</dt>
<dd><%= @user.profile.stream.blank? ? "No Stream Provided" : @user.profile.stream %></dd> <dd><%= @user.profile.stream %></dd>
</dd> </dd>
<% end %>
</dl> </dl>
<h4>Contact</h4> <h4>Contact</h4>

File diff suppressed because it is too large Load diff

View file

@ -10,16 +10,15 @@ describe Api::V1::UsersController do
@user = create :user, :chris @user = create :user, :chris
end end
it "returns user data" do def user_expectation(json, user)
get :show, id: @user.id expect(json["id"]).to eq(user.id)
expect(json["username"]).to eq(user.username)
expect(response).to be_success expect(json["country"]).to eq(user.country)
expect(json["id"]).to eq(@user.id) expect(json["time_zone"]).to eq(user.time_zone)
expect(json["username"]).to eq(@user.username) expect(json["admin"]).to eq(user.admin?)
expect(json["country"]).to eq(@user.country) expect(json["referee"]).to eq(user.ref?)
expect(json["time_zone"]).to eq(@user.time_zone) expect(json["caster"]).to eq(user.caster?)
expect(json["admin"]).to eq(@user.admin?) expect(json["moderator"]).to eq(user.gather_moderator?)
expect(json["moderator"]).to eq(@user.gather_moderator?)
expect(json).to have_key("steam") expect(json).to have_key("steam")
expect(json["steam"]).to have_key("id") expect(json["steam"]).to have_key("id")
expect(json["steam"]).to have_key("url") expect(json["steam"]).to have_key("url")
@ -30,6 +29,37 @@ describe Api::V1::UsersController do
expect(json["team"]).to be_nil expect(json["team"]).to be_nil
end end
it "returns user data" do
get :show, id: @user.id
expect(response).to be_success
user_expectation(json, @user)
end
it "returns user data for query with id specified as format" do
get :show, id: @user.id, format: "id"
expect(response).to be_success
user_expectation(json, @user)
end
it "returns user data for a numeric steamid query" do
m = @user.steamid.match(/\A0:([01]):(\d{1,10})\Z/)
steamid = (m[2].to_i << 1) + m[1].to_i
get :show, id: steamid, format: "steamid"
expect(response).to be_success
user_expectation(json, @user)
end
it "returns user data for a string steamid query" do
get :show, id: @user.steamid, format: "steamidstr"
expect(response).to be_success
user_expectation(json, @user)
end
it "returns nulled steam data for users who had invalid steam ids" do it "returns nulled steam data for users who had invalid steam ids" do
@user.steamid = nil @user.steamid = nil
@user.save! @user.save!

3
spec/features/users/stream_spec.rb Normal file → Executable file
View file

@ -7,7 +7,7 @@ feature "User Stream Information" do
feature "stream administration" do feature "stream administration" do
scenario "user updates their stream" do scenario "user updates their stream" do
visit user_path(user) visit user_path(user)
expect(page).to have_content("No Stream Provided") expect(page.html).to_not include("<dt>Stream</dt>")
fill_login_form(user, password) fill_login_form(user, password)
click_button submit(:user, :login) click_button submit(:user, :login)
visit edit_user_path(user) visit edit_user_path(user)
@ -17,6 +17,7 @@ feature "User Stream Information" do
click_button "Update Profile" click_button "Update Profile"
expect(page).to have_content(I18n.t(:users_update)) expect(page).to have_content(I18n.t(:users_update))
visit user_path(user) visit user_path(user)
expect(page.html).to include("<dt>Stream</dt>")
expect(page).to have_content(stream_url) expect(page).to have_content(stream_url)
end end
end end