Skip to content

Commit 257ea01

Browse files
committed
test: Correct Rails 7 integration test to work with jruby-rack 1.2.x
1 parent 42e82be commit 257ea01

11 files changed

Lines changed: 45 additions & 56 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ integration/**/*.iml
1616
build.log
1717
.ruby-version
1818
.rspec_status
19-
/integration/rails7_test/src/main/ruby/db/*.sqlite3*
19+
*.sqlite3-*

integration/pom.xml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -149,33 +149,26 @@
149149
<pluginManagement>
150150
<plugins>
151151
<plugin>
152-
<groupId>org.mortbay.jetty</groupId>
152+
<groupId>org.eclipse.jetty</groupId>
153153
<artifactId>jetty-maven-plugin</artifactId>
154154
<version>${jetty.version}</version>
155155
<configuration>
156156
<webAppConfig>
157157
<contextPath>/</contextPath>
158-
<configurationClasses>
159-
<configurationClass>org.eclipse.jetty.webapp.WebXmlConfiguration</configurationClass>
160-
<configurationClass>org.eclipse.jetty.webapp.WebInfConfiguration</configurationClass>
161-
<configurationClass>org.eclipse.jetty.webapp.TagLibConfiguration</configurationClass>
162-
<configurationClass>org.eclipse.jetty.webapp.MetaInfConfiguration</configurationClass>
163-
<configurationClass>org.eclipse.jetty.webapp.FragmentConfiguration</configurationClass>
164-
<configurationClass>org.eclipse.jetty.webapp.JettyWebXmlConfiguration</configurationClass>
165-
<!-- intentionally no AnnotationConfiguration -->
166-
</configurationClasses>
167158
</webAppConfig>
168159
<stopPort>9966</stopPort>
169160
<stopKey>warbler_stop</stopKey>
170161
<scanIntervalSeconds>0</scanIntervalSeconds>
171162
<daemon>true</daemon>
163+
<supportedPackagings>jar</supportedPackagings>
172164
</configuration>
173165
<executions>
174166
<execution>
175167
<id>start-jetty</id>
176168
<phase>pre-integration-test</phase>
177169
<goals>
178-
<goal>run-war</goal>
170+
<!-- Change to run-war to interactively play with the server without running tests -->
171+
<goal>deploy-war</goal>
179172
</goals>
180173
</execution>
181174
<execution>

integration/rails7_test/pom.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
</parent>
1010

1111
<artifactId>rails7_test</artifactId>
12-
<packaging>pom</packaging>
13-
1412
<name>rails7_test</name>
1513

1614
<build>
@@ -30,7 +28,7 @@
3028
</executions>
3129
</plugin>
3230
<plugin>
33-
<groupId>org.mortbay.jetty</groupId>
31+
<groupId>org.eclipse.jetty</groupId>
3432
<artifactId>jetty-maven-plugin</artifactId>
3533
<executions>
3634
<execution>
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
source 'https://rubygems.org'
22

3-
gem 'rails', '7.1.5.1'
4-
5-
gem 'puma'
3+
gem 'rails', '~> 7.1.0'
4+
gem 'rack', '~> 2.2.19'
65

76
gem 'activerecord-jdbcsqlite3-adapter', '~> 71.0'
8-
9-
gem 'jbuilder'

integration/rails7_test/src/main/ruby/config/environments/development.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
# Enable server timing
1818
config.server_timing = true
1919

20+
# Workaround https://github.com/jruby/jruby-rack/issues/329
21+
config.logger = ActiveSupport::Logger.new(STDOUT)
22+
2023
# Enable/disable caching. By default caching is disabled.
2124
# Run rails dev:cache to toggle caching.
2225
if Rails.root.join("tmp/caching-dev.txt").exist?
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
Warbler::Config.new do |config|
22
config.autodeploy_dir = "../../../target"
33
config.jar_name = "rails7_test-1.0"
4+
5+
config.webxml.rails.env = 'development'
46
end
28 KB
Binary file not shown.

integration/rails7_test/src/main/ruby/db/migrate/20130502003552_create_posts.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class CreatePosts < ActiveRecord::Migration
1+
class CreatePosts < ActiveRecord::Migration[7.1]
22
def change
33
create_table :posts do |t|
44
t.string :name
Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
# encoding: UTF-8
21
# This file is auto-generated from the current state of the database. Instead
32
# of editing this file, please use the migrations feature of Active Record to
43
# incrementally modify your database, and then regenerate this schema definition.
54
#
6-
# Note that this schema.rb definition is the authoritative source for your
7-
# database schema. If you need to create the application database on another
8-
# system, you should be using db:schema:load, not running all the migrations
9-
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
10-
# you'll amass, the slower it'll run and the greater likelihood for issues).
5+
# This file is the source Rails uses to define your schema when running `bin/rails
6+
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7+
# be faster and is potentially less error prone than running all of your
8+
# migrations from scratch. Old migrations may fail to apply correctly if those
9+
# migrations use external dependencies or application code.
1110
#
1211
# It's strongly recommended that you check this file into your version control system.
1312

14-
ActiveRecord::Schema.define(version: 20130502003552) do
15-
16-
create_table "posts", force: true do |t|
17-
t.string "name"
18-
t.string "title"
19-
t.text "content"
20-
t.datetime "created_at"
21-
t.datetime "updated_at"
13+
ActiveRecord::Schema[7.1].define(version: 2013_05_02_003552) do
14+
create_table "posts", force: :cascade do |t|
15+
t.string "name"
16+
t.string "title"
17+
t.text "content"
18+
t.datetime "created_at", null: false
19+
t.datetime "updated_at", null: false
2220
end
2321

2422
end

integration/rails7_test/src/test/java/org/jruby/warbler/Rails7AppTestIT.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,34 @@
22

33
import java.net.*;
44
import java.io.*;
5-
import org.junit.Assert;
5+
66
import org.junit.Test;
7-
import org.hamcrest.Matcher;
8-
import org.hamcrest.Matchers;
7+
8+
import static org.hamcrest.CoreMatchers.containsString;
9+
import static org.hamcrest.MatcherAssert.assertThat;
910

1011
/**
1112
* Unit test for simple App.
1213
*/
13-
public class Rails7AppTestIT
14-
{
15-
private static String appName = "rails7_test-1.0";
16-
14+
public class Rails7AppTestIT {
1715
/**
1816
* Hit the web app and test the response
1917
*/
2018
@Test
21-
public void testApp() throws Exception
22-
{
23-
URL route = new URL("http://localhost:8080/" + appName + "/posts");
24-
URLConnection routeConn = route.openConnection();
25-
BufferedReader in = new BufferedReader( new InputStreamReader( routeConn.getInputStream()));
26-
27-
String inputLine;
28-
String content = "";
29-
30-
while ((inputLine = in.readLine()) != null)
31-
content += inputLine;
32-
in.close();
19+
public void testApp() throws Exception {
20+
String content = contentFrom("http://localhost:8080/posts/");
21+
assertThat(content, containsString("Rails7App"));
22+
assertThat(content, containsString("Listing posts"));
23+
}
3324

34-
Assert.assertThat(content, Matchers.containsString("Rails7App"));
35-
Assert.assertThat(content, Matchers.containsString("Listing posts"));
25+
private static String contentFrom(String url) throws IOException {
26+
URL route = new URL(url);
27+
StringBuilder content = new StringBuilder();
28+
try (BufferedReader in = new BufferedReader(new InputStreamReader(route.openStream()))) {
29+
while (in.ready()) {
30+
content.append(in.readLine());
31+
}
32+
}
33+
return content.toString();
3634
}
3735
}

0 commit comments

Comments
 (0)