Can ergodicity be checked by restricting attention to continuous maps? The following is well-known:

Theorem. Let $(X, \mathcal F, \mu)$ be a probability space and $T:X\to X$ be a measure preserving map. Then the following are equivalent:
$\bullet$ $T$ is $\mu$-ergodic.
$\bullet$ If $f\in L^2(X, \mu)$ satisfies $f\circ T=f$ $\mu$-a.e., then $f$ is constant $\mu$-a.e.
$\bullet$ If $f\in L^\infty(X, \mu)$ satisfies $f\circ T=f$ $\mu$-a.e., then $f$ is constant $\mu$-a.e.  

I am wondering if we can say more if $X$ has extra structure. In particular, is the following true:
Let $X$ be a compact metric space and $\mathcal B$ be its Borel $\sigma$-algebra.
Let $\mu$ be a Borel probability measure on $X$ and $T:X\to X$ be measure preserving.
Then are the following two statements equivalent:
1) $T$ is $\mu$-ergodic.
2) If a continuous map $f:X\to \mathbb R$ satisfies that $f\circ T=f$ $\mu$-a.e., then $f$ is constant $\mu$-a.e.
Perhaps one may need to assume that $T$ is continuous and that $\mu(U)>0$ for each open set $U\subseteq X$.
 A: The following answer has a slight flaw, but it gets the point across. I'll mention and correct the flaw after the answer (editing the answer to make it correct will distract from the main idea).
Consider $X = [-1,1] \subseteq \mathbb{R}$ and $\mu = \frac{1}{2}\cdot\text{Lebesgue}$. Let $T(x) = 1-x$ for $0 \le x \le 1$ and $Tx = -1-x$ for $-1 \le x \le 0$. Clearly $T$ is not ergodic. However, there is no continuous $f$ with $f \circ T = f$ $\mu$-a.e. but with $f$ not constant $\mu$-a.e.. Suppose otherwise.
Since $T|_{[-1,0]}$ and $T|_{[0,1]}$ are  ergodic and $f|_{[-1,0]}, f|_{[0,1]}$ are $T$-invariant and in $L^1$, $f|_{[-1,0]}$ and $f|_{[0,1]}$ must be $\mu$-a.e. constant, which, by continuity, means they are (everywhere) constant. Since $f$ is continuous, these constants must match, which means $f$ is everywhere constant, a contradiction.

The flaw is that $T$ is not well-defined, since $0$ gets mapped to two distinct points. To fix this, have $X = [-1,1] \cup \{-30\}$ and have $T$ be $T(x) = 1-x$ for $0 \le x \le 1$, $T(x) = -1-x$ for $-1 < x < 0$, $T(-30) = -1, T(-1) = -30$. Then proceed basically the same as before.
