forked from oracle/truffleruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
175 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#!/usr/bin/env bash | ||
|
||
# get the absolute path of the executable and resolve symlinks | ||
SELF_PATH=$(cd "$(dirname "$0")" && pwd -P)/$(basename "$0") | ||
while [ -h "$SELF_PATH" ]; do | ||
# 1) cd to directory of the symlink | ||
# 2) cd to the directory of where the symlink points | ||
# 3) get the pwd | ||
# 4) append the basename | ||
DIR=$(dirname "$SELF_PATH") | ||
SYM=$(readlink "$SELF_PATH") | ||
SELF_PATH=$(cd "$DIR" && cd "$(dirname "$SYM")" && pwd)/$(basename "$SYM") | ||
done | ||
|
||
ecosystem=$(dirname "$SELF_PATH") | ||
truffle=$(dirname "$ecosystem") | ||
test=$(dirname "$truffle") | ||
home=$(dirname "$test") | ||
|
||
function jt { | ||
ruby "${home}/tool/jt.rb" "$@" | ||
} | ||
|
||
function truffleruby { | ||
jt ruby -S "$@" | ||
} | ||
|
||
set -xe | ||
|
||
jt gem-test-pack | ||
truffleruby gem install truffleruby-gem-test-pack/gem-cache/bundler-1.16.5.gem --local | ||
|
||
# backup bin/rake, which gets overwritten | ||
cp bin/rake bin/rake-original | ||
|
||
cd test/truffle/ecosystem/blog | ||
|
||
truffleruby bundle config --local cache_path ../../../../truffleruby-gem-test-pack/gem-cache | ||
truffleruby bundle config --local without postgresql mysql | ||
truffleruby bundle config --local build.nokogiri --use-system-libraries | ||
|
||
truffleruby bundle install --local --no-cache | ||
|
||
truffleruby bin/rails db:setup | ||
truffleruby bin/rails log:clear tmp:clear | ||
|
||
truffleruby bin/rails test | ||
|
||
if [ -f tmp/pids/server.pid ] | ||
then | ||
kill "$(cat tmp/pids/server.pid)" || true | ||
rm tmp/pids/server.pid | ||
fi | ||
|
||
port=57085 | ||
truffleruby bundle exec bin/rails server --port="$port" & | ||
|
||
function kill_server { | ||
kill %1 | ||
kill "$(cat tmp/pids/server.pid)" | ||
} | ||
|
||
set +x | ||
url="http://localhost:$port/posts.json" | ||
while ! curl -s "$url"; | ||
do | ||
echo -n . | ||
sleep 1 | ||
done | ||
set -x | ||
|
||
test "$(curl -s "$url")" = '[]' | ||
|
||
kill_server | ||
|
||
# put back the original | ||
cd "$home" | ||
mv -f bin/rake-original bin/rake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
54 changes: 54 additions & 0 deletions
54
test/truffle/ecosystem/blog/test/controllers/posts_controller_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require 'test_helper' | ||
|
||
class PostsControllerTest < ActionDispatch::IntegrationTest | ||
test "should get index" do | ||
get '/posts' | ||
assert_response :success | ||
|
||
assert_match /Post 1/, @response.body | ||
assert_match /Post 2/, @response.body | ||
end | ||
|
||
test "should get show" do | ||
get post_path id: 1 | ||
assert_response :success | ||
assert_match /Post 1/, @response.body | ||
end | ||
|
||
test "should get new" do | ||
get new_post_path | ||
assert_response :success | ||
end | ||
|
||
test "should post create" do | ||
new_body = "= Title\nauthor\n\nBody" | ||
post '/posts', params: { body: new_body } | ||
assert_equal 3, Post.count | ||
assert_redirected_to '/posts/3' | ||
end | ||
|
||
test "should delete destroy" do | ||
delete post_path id: 1 | ||
assert_redirected_to action: :index | ||
assert_equal Post.all, [Post.find(2)] | ||
end | ||
|
||
test "should get edit" do | ||
get post_path id: 1 | ||
assert_response :success | ||
end | ||
|
||
test "should put update" do | ||
new_body = "= Title\nauthor\n\nBody" | ||
put post_path id: 1, body: new_body | ||
assert_redirected_to post_path(1) | ||
assert_equal Post.find(1).body, new_body | ||
end | ||
|
||
test "should delete destroy_all" do | ||
delete destroy_all_posts_path | ||
assert_redirected_to action: :index | ||
assert_predicate Post.all, :empty? | ||
end | ||
|
||
end |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
|
||
post1: | ||
id: 1 | ||
body: | | ||
= Post 1 | ||
An author | ||
Body of the post 1. | ||
post2: | ||
id: 2 | ||
body: | | ||
= Post 2 | ||
An author | ||
Body of the post 2. | ||
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'test_helper' | ||
|
||
class PostTest < ActiveSupport::TestCase | ||
test "title is parsed" do | ||
assert_equal Post.find(1).title, "Post 1" | ||
end | ||
|
||
test "author is parsed" do | ||
assert_equal Post.find(1).author, "An author" | ||
end | ||
|
||
test "title and author are required" do | ||
post = Post.new(body: "") | ||
assert_not post.valid? | ||
assert_equal post.errors.details, | ||
:title => [{ :error => :blank }], | ||
:author => [{ :error => :blank }] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters