Skip to content

Commit 3595cf8

Browse files
committed
#948 Make AppContext available in views
(cherry picked from commit f48dfe0)
1 parent 5b2af55 commit 3595cf8

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

activeweb-testing/src/test/java/app/controllers/ActiveWebParamsController.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,7 @@
2222
* @author Igor Polevoy
2323
*/
2424
public class ActiveWebParamsController extends AppController {
25-
public void index(){}
25+
public void index(){
26+
appContext().set("name", "javalight");
27+
}
2628
}

activeweb-testing/src/test/java/app/controllers/ActiveWebParamsControllerSpec.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,17 @@ public void before(){
3333
}
3434

3535
@Test
36-
public void shouldAssignAWMapToView(){
36+
public void shouldDisplayBuiltInValues(){
3737

3838
request().get("index");
3939
String response = responseContent();
4040

41-
a(response.contains("restful = false")).shouldBeTrue();
42-
a(response.contains("action = index")).shouldBeTrue();
43-
a(response.contains("controller = /active_web_params")).shouldBeTrue();
44-
a(response.contains("environment = " + AppConfig.activeEnv())).shouldBeTrue();
41+
the(response).shouldContain("restful = false");
42+
the(response).shouldContain("action = index");
43+
the(response).shouldContain("controller = /active_web_params");
44+
the(response).shouldContain("environment = " + AppConfig.activeEnv());
45+
the(response).shouldContain("Context path: /test_context");
46+
the(response).shouldContain("AppContext: org.javalite.activeweb.AppContext");
47+
the(response).shouldContain("AppContext Value: javalight");
4548
}
4649
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<#list activeweb?keys as key>
22
${key} = ${activeweb[key]?string}
33
</#list>
4+
Context path: ${context_path}
5+
AppContext: ${app_context}
6+
AppContext Value: ${app_context.name}
47

activeweb/src/main/java/org/javalite/activeweb/ParamCopy.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ private static void insertActiveWebParamsInto(Map assigns) {
5252
params.put("action", RequestContext.getRoute().getActionName());
5353
params.put("restful", RequestContext.getRoute().getController().restful());
5454
}
55+
56+
assigns.put("app_context", RequestContext.getAppContext());
57+
5558
assigns.put("activeweb", params);
5659
}
5760

0 commit comments

Comments
 (0)